From 270d290e65d1c4d6e65824d20ec7f0174047f7a6 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Fri, 1 Dec 2023 23:48:53 +0100 Subject: host_memory: allow missing MAP_NORESERVE on FreeBSD after 448d4815dece src/common/host_memory.cpp:408:47: error: use of undeclared identifier 'MAP_NORESERVE' MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); ^ --- src/common/host_memory.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 3a9ea6eb4..179f6ab11 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -25,6 +25,10 @@ #include #include "common/scope_exit.h" +#ifndef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif + #endif // ^^^ Linux ^^^ #include -- cgit v1.2.3 From 01d3e250ab41622742ccb5bf93819ae364a65310 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Sat, 2 Dec 2023 00:21:20 +0100 Subject: host_memory: move MAP_ALIGNED_SUPER attempt after 448d4815dece src/common/host_memory.cpp:410:14: error: unused function 'ChooseVirtualBase' [-Werror,-Wunused-function] 410 | static void* ChooseVirtualBase(size_t virtual_size) { | ^~~~~~~~~~~~~~~~~ --- src/common/host_memory.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 179f6ab11..4bfc64f2d 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -408,6 +408,16 @@ static void* ChooseVirtualBase(size_t virtual_size) { #else static void* ChooseVirtualBase(size_t virtual_size) { +#if defined(__FreeBSD__) + void* virtual_base = + mmap(nullptr, virtual_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_ALIGNED_SUPER, -1, 0); + + if (virtual_base != MAP_FAILED) { + return virtual_base; + } +#endif + return mmap(nullptr, virtual_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); } @@ -463,24 +473,12 @@ public: } // Virtual memory initialization -#if defined(__FreeBSD__) - virtual_base = - static_cast(mmap(nullptr, virtual_size, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER, -1, 0)); - if (virtual_base == MAP_FAILED) { - virtual_base = static_cast( - mmap(nullptr, virtual_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); - if (virtual_base == MAP_FAILED) { - LOG_CRITICAL(HW_Memory, "mmap failed: {}", strerror(errno)); - throw std::bad_alloc{}; - } - } -#else virtual_base = virtual_map_base = static_cast(ChooseVirtualBase(virtual_size)); if (virtual_base == MAP_FAILED) { LOG_CRITICAL(HW_Memory, "mmap failed: {}", strerror(errno)); throw std::bad_alloc{}; } +#if defined(__linux__) madvise(virtual_base, virtual_size, MADV_HUGEPAGE); #endif -- cgit v1.2.3