From 8bba0df054614a7d76f693e21e088aa210d15f55 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 14:21:12 +0300 Subject: [PATCH] Added option --no-huge-pages. --- src/App.cpp | 2 +- src/Mem.h | 2 +- src/Mem_unix.cpp | 7 ++++++- src/Mem_win.cpp | 7 ++++++- src/Options.cpp | 13 ++++++++++++- src/Options.h | 2 ++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 83ead3af..c172c045 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -113,7 +113,7 @@ int App::exec() return 1; } - Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash()); + Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash(), m_options->hugePages()); Summary::print(); Workers::start(m_options->affinity(), m_options->priority()); diff --git a/src/Mem.h b/src/Mem.h index 050fd8e8..58dba848 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -44,7 +44,7 @@ public: Lock = 4 }; - static bool allocate(int algo, int threads, bool doubleHash); + static bool allocate(int algo, int threads, bool doubleHash, bool enabled); static cryptonight_ctx *create(int threadId); static void *calloc(size_t num, size_t size); static void release(); diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index 6de2bd40..7c41fd16 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -33,7 +33,7 @@ #include "Options.h" -bool Mem::allocate(int algo, int threads, bool doubleHash) +bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) { m_algo = algo; m_threads = threads; @@ -42,6 +42,11 @@ bool Mem::allocate(int algo, int threads, bool doubleHash) const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; const size_t size = MEMORY * (threads * ratio + 1); + if (!enabled) { + m_memory = static_cast(_mm_malloc(size, 16)); + return true; + } + m_flags |= HugepagesAvailable; # if defined(__APPLE__) diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index cfdb501b..3d0e2ee0 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -144,7 +144,7 @@ static BOOL TrySetLockPagesPrivilege() { } -bool Mem::allocate(int algo, int threads, bool doubleHash) +bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) { m_algo = algo; m_threads = threads; @@ -153,6 +153,11 @@ bool Mem::allocate(int algo, int threads, bool doubleHash) const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; const size_t size = MEMORY * (threads * ratio + 1); + if (!enabled) { + m_memory = static_cast(_mm_malloc(size, 16)); + return true; + } + if (TrySetLockPagesPrivilege()) { m_flags |= HugepagesAvailable; } diff --git a/src/Options.cpp b/src/Options.cpp index 95d099d5..15493e25 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -65,6 +65,7 @@ Options:\n\ -R, --retry-pause=N time to pause between retries (default: 5)\n\ --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\ --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ + --no-huge-pages disable huge pages support\n\ --no-color disable colored output\n\ --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ --user-agent set custom user-agent string for pool\n\ @@ -102,6 +103,7 @@ static struct option const options[] = { { "max-cpu-usage", 1, nullptr, 1004 }, { "nicehash", 0, nullptr, 1006 }, { "no-color", 0, nullptr, 1002 }, + { "no-huge-pages", 0, nullptr, 1009 }, { "pass", 1, nullptr, 'p' }, { "print-time", 1, nullptr, 1007 }, { "retries", 1, nullptr, 'r' }, @@ -126,6 +128,7 @@ static struct option const config_options[] = { { "cpu-affinity", 1, nullptr, 1020 }, { "cpu-priority", 1, nullptr, 1021 }, { "donate-level", 1, nullptr, 1003 }, + { "huge-pages", 0, nullptr, 1009 }, { "log-file", 1, nullptr, 'l' }, { "max-cpu-usage", 1, nullptr, 1004 }, { "print-time", 1, nullptr, 1007 }, @@ -181,6 +184,7 @@ Options::Options(int argc, char **argv) : m_background(false), m_colors(true), m_doubleHash(false), + m_hugePages(true), m_ready(false), m_safe(false), m_syslog(false), @@ -311,11 +315,14 @@ bool Options::parseArg(int key, const char *arg) case 'B': /* --background */ case 'k': /* --keepalive */ case 'S': /* --syslog */ - case 1002: /* --no-color */ case 1005: /* --safe */ case 1006: /* --nicehash */ return parseBoolean(key, true); + case 1002: /* --no-color */ + case 1009: /* --no-huge-pages */ + return parseBoolean(key, false); + case 'V': /* --version */ showVersion(); return false; @@ -462,6 +469,10 @@ bool Options::parseBoolean(int key, bool enable) m_pools.back()->setNicehash(enable); break; + case 1009: /* --no-huge-pages */ + m_hugePages = enable; + break; + case 2000: /* colors */ m_colors = enable; break; diff --git a/src/Options.h b/src/Options.h index ae2a2928..e85441d9 100644 --- a/src/Options.h +++ b/src/Options.h @@ -57,6 +57,7 @@ public: inline bool background() const { return m_background; } inline bool colors() const { return m_colors; } inline bool doubleHash() const { return m_doubleHash; } + inline bool hugePages() const { return m_hugePages; } inline bool syslog() const { return m_syslog; } inline const char *logFile() const { return m_logFile; } inline const char *userAgent() const { return m_userAgent; } @@ -102,6 +103,7 @@ private: bool m_background; bool m_colors; bool m_doubleHash; + bool m_hugePages; bool m_ready; bool m_safe; bool m_syslog;