diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-03-31 15:41:01 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-04-03 11:06:07 -0400 |
commit | fe358a4fd67fc48188eb062ae026001ff74082e9 (patch) | |
tree | 9d21950a36f870c44e15667b5000bc10e8ea2d62 /src/mongo/util/processinfo_windows.cpp | |
parent | 8c2598812fe6c553783edbba4bc5d16a44a1b4d9 (diff) | |
download | mongo-fe358a4fd67fc48188eb062ae026001ff74082e9.tar.gz |
SERVER-17745: Improve dirty page estimation in mmapv1 on Windows
Diffstat (limited to 'src/mongo/util/processinfo_windows.cpp')
-rw-r--r-- | src/mongo/util/processinfo_windows.cpp | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/src/mongo/util/processinfo_windows.cpp b/src/mongo/util/processinfo_windows.cpp index 1747b980225..e370076fec9 100644 --- a/src/mongo/util/processinfo_windows.cpp +++ b/src/mongo/util/processinfo_windows.cpp @@ -85,18 +85,69 @@ namespace mongo { int ProcessInfo::getVirtualMemorySize() { MEMORYSTATUSEX mse; mse.dwLength = sizeof(mse); - verify( GlobalMemoryStatusEx( &mse ) ); - DWORDLONG x = (mse.ullTotalVirtual - mse.ullAvailVirtual) / (1024 * 1024) ; - verify( x <= 0x7fffffff ); + BOOL status = GlobalMemoryStatusEx(&mse); + if (!status) { + DWORD gle = GetLastError(); + error() << "GlobalMemoryStatusEx failed with " << errnoWithDescription(gle); + fassert(28621, status); + } + + DWORDLONG x = (mse.ullTotalVirtual - mse.ullAvailVirtual) / (1024 * 1024); + invariant( x <= 0x7fffffff ); return (int) x; } int ProcessInfo::getResidentSize() { PROCESS_MEMORY_COUNTERS pmc; - verify( GetProcessMemoryInfo( GetCurrentProcess() , &pmc, sizeof(pmc) ) ); + BOOL status = GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)); + if (!status) { + DWORD gle = GetLastError(); + error() << "GetProcessMemoryInfo failed with " << errnoWithDescription(gle); + fassert(28622, status); + } + return _wconvertmtos( pmc.WorkingSetSize ); } + double ProcessInfo::getSystemMemoryPressurePercentage() { + MEMORYSTATUSEX mse; + mse.dwLength = sizeof(mse); + BOOL status = GlobalMemoryStatusEx( &mse ); + if (!status) { + DWORD gle = GetLastError(); + error() << "GlobalMemoryStatusEx failed with " << errnoWithDescription(gle); + fassert(28623, status); + } + + DWORDLONG totalPageFile = mse.ullTotalPageFile; + if (totalPageFile == 0) { + return false; + } + + // If the page file is >= 50%, say we are low on system memory + // If the page file is >= 75%, we are running very low on system memory + // + DWORDLONG highWatermark = totalPageFile / 2; + DWORDLONG veryHighWatermark = 3 * (totalPageFile / 4); + + DWORDLONG usedPageFile = mse.ullTotalPageFile - mse.ullAvailPageFile; + + // Below the watermark, we are fine + // Also check we will not do a divide by zero below + if (usedPageFile < highWatermark || + veryHighWatermark <= highWatermark) { + return 0.0; + } + + // Above the high watermark, we tell MMapV1 how much to remap + // < 1.0, we have some pressure, but not much so do not be very aggressive + // 1.0 = we are at very high watermark, remap everything + // > 1.0, the user may run out of memory, remap everything + // i.e., Example (N - 50) / (75 - 50) + return static_cast<double>(usedPageFile - highWatermark) / + (veryHighWatermark - highWatermark); + } + void ProcessInfo::getExtraInfo(BSONObjBuilder& info) { MEMORYSTATUSEX mse; mse.dwLength = sizeof(mse); |