diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2023-02-22 14:49:49 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-03-20 17:44:22 +0000 |
commit | e41dfbe8bf58bc8489defe42dfb72a0512f5c2fe (patch) | |
tree | 7f3b1d0f19fc5ed0ea823735a095d8c8c538f7f7 | |
parent | c7d6bc29c9ce2254e587f85c2fedc1ba2c8f7ce5 (diff) | |
download | mongo-e41dfbe8bf58bc8489defe42dfb72a0512f5c2fe.tar.gz |
SERVER-74038 Grow dwMaximumWorkingSetSize with current working set size
(cherry picked from commit db5ca2947f37d6706c01fe24d6294af75b6418c9)
-rw-r--r-- | src/mongo/base/secure_allocator.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/mongo/base/secure_allocator.cpp b/src/mongo/base/secure_allocator.cpp index fca3e4ab82c..0a1ce485cc1 100644 --- a/src/mongo/base/secure_allocator.cpp +++ b/src/mongo/base/secure_allocator.cpp @@ -36,6 +36,7 @@ #include <memory> #ifdef _WIN32 +#include <psapi.h> #include <windows.h> #else #include <sys/mman.h> @@ -138,7 +139,19 @@ void growWorkingSize(std::size_t bytes) { // Since allocation request is aligned to page size, we can just add it to the current working // set size. - maxWorkingSetSize = std::max(minWorkingSetSize + bytes + minGap, maxWorkingSetSize); + // Note: The default dwMaximumWorkingSetSize for a process is 345 pages on a system with 4k + // pages (i.e x64). This is not the same as the current working set of the process. It usually + // far lower. The min value is ignored by Windows until the machine is starved for memory or + // MongoDB wants to lock pages. The max value is treated as a target working set goal for a + // process that Windows should meet. This means that if MongoDB sets the number too low, Windows + // will flush the process out to the page file which will cause the process to freeze while this + // occurs. MongoDB will set the dwMaximumWorkingSetSize to 90% of physical RAM. On high memory + // systems (> 128GB0), this may be too conservative so use 5GB as a threshold. + uint64_t physicalRamSize = ProcessInfo::getMemSizeMB() * 1024ULL * 1024ULL; + + maxWorkingSetSize = physicalRamSize - + std::min(0.10 * physicalRamSize, + static_cast<double>(5ULL * 1024ULL * 1024ULL * 1024ULL) /* 5 GB */); // Increase the working set size minimum to the new lower bound. if (!SetProcessWorkingSetSizeEx(GetCurrentProcess(), |