diff options
author | Jan Kotas <jkotas@microsoft.com> | 2016-05-18 00:31:02 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-05-18 02:26:03 +0300 |
commit | fb4461712ec8e0906bf799ca8704375b9e1cff1a (patch) | |
tree | df333b7d4113aed1d44f0dc6906c52b0e627ba47 /src/Native/Runtime/windows | |
parent | 95cf48ec140a129eb97bb8d7d267ee6caba9c2b9 (diff) |
Fixes for GC update
Diffstat (limited to 'src/Native/Runtime/windows')
-rw-r--r-- | src/Native/Runtime/windows/PalRedhawkMinWin.cpp | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/src/Native/Runtime/windows/PalRedhawkMinWin.cpp b/src/Native/Runtime/windows/PalRedhawkMinWin.cpp index 792feacc4..a27e423b8 100644 --- a/src/Native/Runtime/windows/PalRedhawkMinWin.cpp +++ b/src/Native/Runtime/windows/PalRedhawkMinWin.cpp @@ -1385,7 +1385,7 @@ bool GCToOSInterface::SetCurrentThreadIdealAffinity(GCThreadAffinity* affinity) { proc.Number = (BYTE)affinity->Processor; success = !!SetThreadIdealProcessorEx(GetCurrentThread(), &proc, NULL); - } + } } return success; @@ -1615,25 +1615,64 @@ uint32_t GCToOSInterface::GetCurrentProcessCpuCount() return count; } +// Return the size of the user-mode portion of the virtual address space of this process. +// Return: +// non zero if it has succeeded, 0 if it has failed +size_t GCToOSInterface::GetVirtualMemoryLimit() +{ + MEMORYSTATUSEX memStatus; + + memStatus.dwLength = sizeof(MEMORYSTATUSEX); + + BOOL fRet; + fRet = GlobalMemoryStatusEx(&memStatus); + _ASSERTE(fRet); + + return (size_t)memStatus.ullTotalVirtual; +} + +// Get the physical memory that this process can use. +// Return: +// non zero if it has succeeded, 0 if it has failed +uint64_t GCToOSInterface::GetPhysicalMemoryLimit() +{ + MEMORYSTATUSEX memStatus; + + memStatus.dwLength = sizeof(MEMORYSTATUSEX); + + BOOL fRet; + fRet = GlobalMemoryStatusEx(&memStatus); + _ASSERTE(fRet); + + return memStatus.ullTotalPhys; +} + // Get global memory status // Parameters: // ms - pointer to the structure that will be filled in with the memory status -void GCToOSInterface::GetMemoryStatus(GCMemoryStatus* ms) +void GCToOSInterface::GetMemoryStatus(uint32_t* memory_load, uint64_t* available_physical, uint64_t* available_page_file) { MEMORYSTATUSEX memStatus; + memStatus.dwLength = sizeof(MEMORYSTATUSEX); - // TODO: fail fast if the function call fails? - GlobalMemoryStatusEx(&memStatus); - - // Convert Windows struct to abstract struct - ms->dwMemoryLoad = memStatus.dwMemoryLoad; - ms->ullTotalPhys = memStatus.ullTotalPhys; - ms->ullAvailPhys = memStatus.ullAvailPhys; - ms->ullTotalPageFile = memStatus.ullTotalPageFile; - ms->ullAvailPageFile = memStatus.ullAvailPageFile; - ms->ullTotalVirtual = memStatus.ullTotalVirtual; - ms->ullAvailVirtual = memStatus.ullAvailVirtual; + BOOL fRet; + fRet = GlobalMemoryStatusEx(&memStatus); + _ASSERTE(fRet); + + // If the machine has more RAM than virtual address limit, let us cap it. + // The GC can never use more than virtual address limit. + if (memStatus.ullAvailPhys > memStatus.ullTotalVirtual) + { + memStatus.ullAvailPhys = memStatus.ullAvailVirtual; + } + + if (memory_load != NULL) + *memory_load = memStatus.dwMemoryLoad; + if (available_physical != NULL) + *available_physical = memStatus.ullAvailPhys; + if (available_page_file != NULL) + *available_page_file = memStatus.ullAvailPageFile; } // Get a high precision performance counter |