From f32dc65cc78140a2e488b066099abe810ae11e17 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Tue, 18 May 2021 17:42:38 -0600 Subject: [PATCH] Add AUTO_HUGEPAGE feature to disable writing to nr_hugepages --- CMakeLists.txt | 5 +++++ src/crypto/common/LinuxMemory.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a44e672be4..6dd9fc0e33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ option(WITH_VAES "Enable VAES instructions for Cryptonight" ON) option(WITH_BENCHMARK "Enable builtin RandomX benchmark and stress test" ON) option(WITH_SECURE_JIT "Enable secure access to JIT memory" OFF) option(WITH_DMI "Enable DMI/SMBIOS reader" ON) +option(WITH_AUTO_HUGEPAGE "Enable Automatic setting of nr_hugepages (Linux Only)" ON) option(BUILD_STATIC "Build static binary" OFF) option(ARM_TARGET "Force use specific ARM target 8 or 7" 0) @@ -180,6 +181,10 @@ else() if (XMRIG_OS_ANDROID) set(EXTRA_LIBS pthread rt dl log) elseif (XMRIG_OS_LINUX) + if (WITH_AUTO_HUGEPAGE) + add_definitions(/DXMRIG_FEATURE_AUTO_HUGEPAGE) + endif() + list(APPEND SOURCES_OS src/crypto/common/LinuxMemory.h src/crypto/common/LinuxMemory.cpp diff --git a/src/crypto/common/LinuxMemory.cpp b/src/crypto/common/LinuxMemory.cpp index 8a00e1c360..9fd5f0c2bc 100644 --- a/src/crypto/common/LinuxMemory.cpp +++ b/src/crypto/common/LinuxMemory.cpp @@ -60,7 +60,11 @@ bool xmrig::LinuxMemory::reserve(size_t size, uint32_t node, size_t hugePageSize return false; } +# ifdef XMRIG_FEATURE_AUTO_HUGEPAGE return write_nr_hugepages(node, hugePageSize, std::max(nr_hugepages(node, hugePageSize), 0) + (required - available)); +# else + return false; +# endif }