From 9035562af932fc7802f4ee195bef7a5893e7aeb5 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 24 Jun 2019 17:43:05 -0700 Subject: [PATCH 1/6] Add property HardLimitBytes to GCMemoryInfo This adds a new property HardLimitBytes. Unlike TotalAvailableMemoryBytes, this will reflect an explicitly set COMPLUS_GCHeapHardLimit. It will also reflect the fraction of a container's size that we use, where TotalAvailableMemoryBytes is the total container size. Normally, though, it is equal to TotalAvailableMemoryBytes. Fix #38821 --- .../shared/System/GCMemoryInfo.cs | 14 +++++++++++++- src/System.Private.CoreLib/src/System/GC.cs | 4 ++++ src/gc/gc.cpp | 2 ++ src/gc/gcimpl.h | 1 + src/gc/gcinterface.h | 1 + src/vm/comutilnative.cpp | 4 ++-- src/vm/comutilnative.h | 2 +- 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs index 72c2aca14da2..0bb677ba0242 100644 --- a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs +++ b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs @@ -17,10 +17,20 @@ public readonly struct GCMemoryInfo public long MemoryLoadBytes { get; } /// - /// Total available memory for the GC to use when the last GC ocurred. By default this is the physical memory on the machine, but it may be customized by specifying a HardLimit. + /// Total available memory for the GC to use when the last GC ocurred. + /// This is the physical memory on the machine, or in a container, it is the total size of the container. + /// Unlike HardLimitBytes, this is not affected by COMPlus_GCHeapHardLimit or "Server.GC.HeapHardLimit". /// public long TotalAvailableMemoryBytes { get; } + /// + /// Hard limit on heap size. + /// This is equal to TotalAvailableMemoryBytes normally. + /// In a container, this will be an implementation-defined fraction of the container's size. + /// If the environment variable COMPlus_GCHeapHardLimit is set, or "Server.GC.HeapHardLimit" is specified in runtimeconfig.json, this will come from that. + /// + public long HardLimitBytes { get; } + /// /// The total heap size when the last GC ocurred /// @@ -43,12 +53,14 @@ public readonly struct GCMemoryInfo internal GCMemoryInfo(long highMemoryLoadThresholdBytes, long memoryLoadBytes, long totalAvailableMemoryBytes, + long hardLimitBytes, long heapSizeBytes, long fragmentedBytes) { HighMemoryLoadThresholdBytes = highMemoryLoadThresholdBytes; MemoryLoadBytes = memoryLoadBytes; TotalAvailableMemoryBytes = totalAvailableMemoryBytes; + HardLimitBytes = hardLimitBytes; HeapSizeBytes = heapSizeBytes; FragmentedBytes = fragmentedBytes; } diff --git a/src/System.Private.CoreLib/src/System/GC.cs b/src/System.Private.CoreLib/src/System/GC.cs index 26bc6c7c035d..23abebf47031 100644 --- a/src/System.Private.CoreLib/src/System/GC.cs +++ b/src/System.Private.CoreLib/src/System/GC.cs @@ -56,6 +56,7 @@ public static class GC [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void GetMemoryInfo(out uint highMemLoadThreshold, out ulong totalPhysicalMem, + out ulong hardLimit, out uint lastRecordedMemLoad, // The next two are size_t out UIntPtr lastRecordedHeapSize, @@ -65,6 +66,7 @@ public static GCMemoryInfo GetGCMemoryInfo() { GetMemoryInfo(out uint highMemLoadThreshold, out ulong totalPhysicalMem, + out ulong hardLimit, out uint lastRecordedMemLoad, out UIntPtr lastRecordedHeapSize, out UIntPtr lastRecordedFragmentation); @@ -72,6 +74,7 @@ public static GCMemoryInfo GetGCMemoryInfo() return new GCMemoryInfo((long)((double)highMemLoadThreshold / 100 * totalPhysicalMem), (long)((double)lastRecordedMemLoad / 100 * totalPhysicalMem), (long)totalPhysicalMem, + (long)hardLimit, (long)(ulong)lastRecordedHeapSize, (long)(ulong)lastRecordedFragmentation); } @@ -542,6 +545,7 @@ public MemoryLoadChangeNotification(float lowMemoryPercent, float highMemoryPerc private static float GetMemoryLoad() { GetMemoryInfo(out uint _, + out ulong _, out ulong _, out uint lastRecordedMemLoad, out UIntPtr _, diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index 820e66db676c..1947807e2163 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -36152,12 +36152,14 @@ unsigned int GCHeap::GetCondemnedGeneration() void GCHeap::GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, + uint64_t* hardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) { *highMemLoadThreshold = gc_heap::high_memory_load_th; *totalPhysicalMem = gc_heap::total_physical_mem; + *hardLimit = gc_heap::heap_hard_limit != 0 ? gc_heap::heap_hard_limit : gc_heap::total_physical_mem; *lastRecordedMemLoad = gc_heap::last_gc_memory_load; *lastRecordedHeapSize = gc_heap::last_gc_heap_size; *lastRecordedFragmentation = gc_heap::last_gc_fragmentation; diff --git a/src/gc/gcimpl.h b/src/gc/gcimpl.h index b1d4e07981d5..d2b0651a1344 100644 --- a/src/gc/gcimpl.h +++ b/src/gc/gcimpl.h @@ -173,6 +173,7 @@ class GCHeap : public IGCHeapInternal void GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, + uint64_t* hardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); diff --git a/src/gc/gcinterface.h b/src/gc/gcinterface.h index 6d09a62824e5..b109339fe052 100644 --- a/src/gc/gcinterface.h +++ b/src/gc/gcinterface.h @@ -607,6 +607,7 @@ class IGCHeap { // lastRecordedFragmentation - total fragmentation in the managed heap recorded in the last GC virtual void GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, + uint64_t* hardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) = 0; diff --git a/src/vm/comutilnative.cpp b/src/vm/comutilnative.cpp index 27d85f6af6cf..9df21cd32a76 100644 --- a/src/vm/comutilnative.cpp +++ b/src/vm/comutilnative.cpp @@ -886,13 +886,13 @@ UINT64 GCInterface::m_remPressure[NEW_PRESSURE_COUNT] = {0, 0, 0, 0}; // his // (m_iteration % NEW_PRESSURE_COUNT) is used as an index into m_addPressure and m_remPressure UINT GCInterface::m_iteration = 0; -FCIMPL5(void, GCInterface::GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) +FCIMPL6(void, GCInterface::GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT64* hardLimit, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) { FCALL_CONTRACT; FC_GC_POLL_NOT_NEEDED(); - return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalPhysicalMem, + return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalPhysicalMem, hardLimit, lastRecordedMemLoad, lastRecordedHeapSize, lastRecordedFragmentation); } diff --git a/src/vm/comutilnative.h b/src/vm/comutilnative.h index 6afbc5a45e3d..89e9a8ecba36 100644 --- a/src/vm/comutilnative.h +++ b/src/vm/comutilnative.h @@ -110,7 +110,7 @@ class GCInterface { static FORCEINLINE UINT64 InterlockedAdd(UINT64 *pAugend, UINT64 addend); static FORCEINLINE UINT64 InterlockedSub(UINT64 *pMinuend, UINT64 subtrahend); - static FCDECL5(void, GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); + static FCDECL6(void, GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT64* hardLimit, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); static FCDECL0(int, GetGcLatencyMode); static FCDECL1(int, SetGcLatencyMode, int newLatencyMode); static FCDECL0(int, GetLOHCompactionMode); From b095f245d1bb17d223b1a5f5fe6544caf6bdc804 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 27 Jun 2019 18:04:29 -0700 Subject: [PATCH 2/6] Remove HardLimitBytes; have TotalAvailableMemoryBytes take on its behavior --- .../shared/System/GCMemoryInfo.cs | 17 ++++------------- src/System.Private.CoreLib/src/System/GC.cs | 4 ---- src/gc/gc.cpp | 4 +--- src/gc/gcimpl.h | 1 - src/gc/gcinterface.h | 1 - src/vm/comutilnative.cpp | 4 ++-- src/vm/comutilnative.h | 2 +- 7 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs index 0bb677ba0242..b5daac199dec 100644 --- a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs +++ b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs @@ -17,20 +17,13 @@ public readonly struct GCMemoryInfo public long MemoryLoadBytes { get; } /// - /// Total available memory for the GC to use when the last GC ocurred. - /// This is the physical memory on the machine, or in a container, it is the total size of the container. - /// Unlike HardLimitBytes, this is not affected by COMPlus_GCHeapHardLimit or "Server.GC.HeapHardLimit". + /// If the environment variable COMPLUS_GCHeapHardLimit is set, + /// or "Server.GC.HeapHardLimti" is in runtimeconfig.json, this will come from that. + /// If the program is run in a container, this will be an implementation-defined fraction of the container's size. + /// Else, this is the physical memory on the machine that was available for the GC to use when the last GC occurred. /// public long TotalAvailableMemoryBytes { get; } - /// - /// Hard limit on heap size. - /// This is equal to TotalAvailableMemoryBytes normally. - /// In a container, this will be an implementation-defined fraction of the container's size. - /// If the environment variable COMPlus_GCHeapHardLimit is set, or "Server.GC.HeapHardLimit" is specified in runtimeconfig.json, this will come from that. - /// - public long HardLimitBytes { get; } - /// /// The total heap size when the last GC ocurred /// @@ -53,14 +46,12 @@ public readonly struct GCMemoryInfo internal GCMemoryInfo(long highMemoryLoadThresholdBytes, long memoryLoadBytes, long totalAvailableMemoryBytes, - long hardLimitBytes, long heapSizeBytes, long fragmentedBytes) { HighMemoryLoadThresholdBytes = highMemoryLoadThresholdBytes; MemoryLoadBytes = memoryLoadBytes; TotalAvailableMemoryBytes = totalAvailableMemoryBytes; - HardLimitBytes = hardLimitBytes; HeapSizeBytes = heapSizeBytes; FragmentedBytes = fragmentedBytes; } diff --git a/src/System.Private.CoreLib/src/System/GC.cs b/src/System.Private.CoreLib/src/System/GC.cs index 23abebf47031..26bc6c7c035d 100644 --- a/src/System.Private.CoreLib/src/System/GC.cs +++ b/src/System.Private.CoreLib/src/System/GC.cs @@ -56,7 +56,6 @@ public static class GC [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void GetMemoryInfo(out uint highMemLoadThreshold, out ulong totalPhysicalMem, - out ulong hardLimit, out uint lastRecordedMemLoad, // The next two are size_t out UIntPtr lastRecordedHeapSize, @@ -66,7 +65,6 @@ public static GCMemoryInfo GetGCMemoryInfo() { GetMemoryInfo(out uint highMemLoadThreshold, out ulong totalPhysicalMem, - out ulong hardLimit, out uint lastRecordedMemLoad, out UIntPtr lastRecordedHeapSize, out UIntPtr lastRecordedFragmentation); @@ -74,7 +72,6 @@ public static GCMemoryInfo GetGCMemoryInfo() return new GCMemoryInfo((long)((double)highMemLoadThreshold / 100 * totalPhysicalMem), (long)((double)lastRecordedMemLoad / 100 * totalPhysicalMem), (long)totalPhysicalMem, - (long)hardLimit, (long)(ulong)lastRecordedHeapSize, (long)(ulong)lastRecordedFragmentation); } @@ -545,7 +542,6 @@ public MemoryLoadChangeNotification(float lowMemoryPercent, float highMemoryPerc private static float GetMemoryLoad() { GetMemoryInfo(out uint _, - out ulong _, out ulong _, out uint lastRecordedMemLoad, out UIntPtr _, diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index 1947807e2163..7e83cc93286c 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -36152,14 +36152,12 @@ unsigned int GCHeap::GetCondemnedGeneration() void GCHeap::GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, - uint64_t* hardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) { *highMemLoadThreshold = gc_heap::high_memory_load_th; - *totalPhysicalMem = gc_heap::total_physical_mem; - *hardLimit = gc_heap::heap_hard_limit != 0 ? gc_heap::heap_hard_limit : gc_heap::total_physical_mem; + *totalPhysicalMem = gc_heap::heap_hard_limit != 0 ? gc_heap::heap_hard_limit : gc_heap::total_physical_mem; *lastRecordedMemLoad = gc_heap::last_gc_memory_load; *lastRecordedHeapSize = gc_heap::last_gc_heap_size; *lastRecordedFragmentation = gc_heap::last_gc_fragmentation; diff --git a/src/gc/gcimpl.h b/src/gc/gcimpl.h index d2b0651a1344..b1d4e07981d5 100644 --- a/src/gc/gcimpl.h +++ b/src/gc/gcimpl.h @@ -173,7 +173,6 @@ class GCHeap : public IGCHeapInternal void GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, - uint64_t* hardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); diff --git a/src/gc/gcinterface.h b/src/gc/gcinterface.h index b109339fe052..6d09a62824e5 100644 --- a/src/gc/gcinterface.h +++ b/src/gc/gcinterface.h @@ -607,7 +607,6 @@ class IGCHeap { // lastRecordedFragmentation - total fragmentation in the managed heap recorded in the last GC virtual void GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, - uint64_t* hardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) = 0; diff --git a/src/vm/comutilnative.cpp b/src/vm/comutilnative.cpp index 9df21cd32a76..7aa49f171f73 100644 --- a/src/vm/comutilnative.cpp +++ b/src/vm/comutilnative.cpp @@ -886,13 +886,13 @@ UINT64 GCInterface::m_remPressure[NEW_PRESSURE_COUNT] = {0, 0, 0, 0}; // his // (m_iteration % NEW_PRESSURE_COUNT) is used as an index into m_addPressure and m_remPressure UINT GCInterface::m_iteration = 0; -FCIMPL6(void, GCInterface::GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT64* hardLimit, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) +FCIMPL5(void, GCInterface::GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) { FCALL_CONTRACT; FC_GC_POLL_NOT_NEEDED(); - return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalPhysicalMem, hardLimit, + return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalPhysicalMem, lastRecordedMemLoad, lastRecordedHeapSize, lastRecordedFragmentation); } diff --git a/src/vm/comutilnative.h b/src/vm/comutilnative.h index 89e9a8ecba36..6afbc5a45e3d 100644 --- a/src/vm/comutilnative.h +++ b/src/vm/comutilnative.h @@ -110,7 +110,7 @@ class GCInterface { static FORCEINLINE UINT64 InterlockedAdd(UINT64 *pAugend, UINT64 addend); static FORCEINLINE UINT64 InterlockedSub(UINT64 *pMinuend, UINT64 subtrahend); - static FCDECL6(void, GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT64* hardLimit, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); + static FCDECL5(void, GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); static FCDECL0(int, GetGcLatencyMode); static FCDECL1(int, SetGcLatencyMode, int newLatencyMode); static FCDECL0(int, GetLOHCompactionMode); From a9c48aede70a8faf4c99558c93d12e6234f4599a Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 27 Jun 2019 18:29:05 -0700 Subject: [PATCH 3/6] Fix typos --- src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs index b5daac199dec..2a2956f7bc63 100644 --- a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs +++ b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs @@ -17,8 +17,8 @@ public readonly struct GCMemoryInfo public long MemoryLoadBytes { get; } /// - /// If the environment variable COMPLUS_GCHeapHardLimit is set, - /// or "Server.GC.HeapHardLimti" is in runtimeconfig.json, this will come from that. + /// If the environment variable COMPlus_GCHeapHardLimit is set, + /// or "Server.GC.HeapHardLimit" is in runtimeconfig.json, this will come from that. /// If the program is run in a container, this will be an implementation-defined fraction of the container's size. /// Else, this is the physical memory on the machine that was available for the GC to use when the last GC occurred. /// From 6447db87e57532f38cf4028a66b54c27e62073c3 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 1 Jul 2019 20:16:22 -0700 Subject: [PATCH 4/6] Separate total_physical_mem and heap_hard_limit so we can compute highMemoryLoadThresholdBytes and memoryLoadBytes --- .../shared/System/GCMemoryInfo.cs | 2 ++ src/System.Private.CoreLib/src/System/GC.cs | 13 ++++++++----- src/gc/gc.cpp | 4 +++- src/gc/gcimpl.h | 1 + src/gc/gcinterface.h | 1 + src/vm/comutilnative.cpp | 4 ++-- src/vm/comutilnative.h | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs index 2a2956f7bc63..850f1256eb12 100644 --- a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs +++ b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs @@ -17,6 +17,8 @@ public readonly struct GCMemoryInfo public long MemoryLoadBytes { get; } /// + /// Total available memory for the GC to use when the last GC ocurred. + /// /// If the environment variable COMPlus_GCHeapHardLimit is set, /// or "Server.GC.HeapHardLimit" is in runtimeconfig.json, this will come from that. /// If the program is run in a container, this will be an implementation-defined fraction of the container's size. diff --git a/src/System.Private.CoreLib/src/System/GC.cs b/src/System.Private.CoreLib/src/System/GC.cs index 26bc6c7c035d..ecb1a659d1cb 100644 --- a/src/System.Private.CoreLib/src/System/GC.cs +++ b/src/System.Private.CoreLib/src/System/GC.cs @@ -56,6 +56,7 @@ public static class GC [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void GetMemoryInfo(out uint highMemLoadThreshold, out ulong totalPhysicalMem, + out ulong heapHardLimit, out uint lastRecordedMemLoad, // The next two are size_t out UIntPtr lastRecordedHeapSize, @@ -65,15 +66,16 @@ public static GCMemoryInfo GetGCMemoryInfo() { GetMemoryInfo(out uint highMemLoadThreshold, out ulong totalPhysicalMem, + out ulong heapHardLimit, out uint lastRecordedMemLoad, out UIntPtr lastRecordedHeapSize, out UIntPtr lastRecordedFragmentation); - return new GCMemoryInfo((long)((double)highMemLoadThreshold / 100 * totalPhysicalMem), - (long)((double)lastRecordedMemLoad / 100 * totalPhysicalMem), - (long)totalPhysicalMem, - (long)(ulong)lastRecordedHeapSize, - (long)(ulong)lastRecordedFragmentation); + return new GCMemoryInfo(highMemoryLoadThresholdBytes: (long)((double)highMemLoadThreshold / 100 * totalPhysicalMem), + memoryLoadBytes: (long)((double)lastRecordedMemLoad / 100 * totalPhysicalMem), + totalAvailableMemoryBytes: (long)(heapHardLimit != 0 ? heapHardLimit : totalPhysicalMem), + heapSizeBytes: (long)(ulong)lastRecordedHeapSize, + fragmentedBytes: (long)(ulong)lastRecordedFragmentation); } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] @@ -542,6 +544,7 @@ public MemoryLoadChangeNotification(float lowMemoryPercent, float highMemoryPerc private static float GetMemoryLoad() { GetMemoryInfo(out uint _, + out ulong _, out ulong _, out uint lastRecordedMemLoad, out UIntPtr _, diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index 7e83cc93286c..c0c88779e150 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -36152,12 +36152,14 @@ unsigned int GCHeap::GetCondemnedGeneration() void GCHeap::GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, + uint64_t* heapHardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) { *highMemLoadThreshold = gc_heap::high_memory_load_th; - *totalPhysicalMem = gc_heap::heap_hard_limit != 0 ? gc_heap::heap_hard_limit : gc_heap::total_physical_mem; + *totalPhysicalMem = gc_heap::total_physical_mem; + *heapHardLimit = gc_heap::heap_hard_limit; *lastRecordedMemLoad = gc_heap::last_gc_memory_load; *lastRecordedHeapSize = gc_heap::last_gc_heap_size; *lastRecordedFragmentation = gc_heap::last_gc_fragmentation; diff --git a/src/gc/gcimpl.h b/src/gc/gcimpl.h index b1d4e07981d5..f0af851d2ee7 100644 --- a/src/gc/gcimpl.h +++ b/src/gc/gcimpl.h @@ -173,6 +173,7 @@ class GCHeap : public IGCHeapInternal void GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, + uint64_t* heapHardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); diff --git a/src/gc/gcinterface.h b/src/gc/gcinterface.h index 6d09a62824e5..84ea95582a46 100644 --- a/src/gc/gcinterface.h +++ b/src/gc/gcinterface.h @@ -607,6 +607,7 @@ class IGCHeap { // lastRecordedFragmentation - total fragmentation in the managed heap recorded in the last GC virtual void GetMemoryInfo(uint32_t* highMemLoadThreshold, uint64_t* totalPhysicalMem, + uint64_t* heapHardLimit, uint32_t* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) = 0; diff --git a/src/vm/comutilnative.cpp b/src/vm/comutilnative.cpp index 7aa49f171f73..beeac9d2ff64 100644 --- a/src/vm/comutilnative.cpp +++ b/src/vm/comutilnative.cpp @@ -886,13 +886,13 @@ UINT64 GCInterface::m_remPressure[NEW_PRESSURE_COUNT] = {0, 0, 0, 0}; // his // (m_iteration % NEW_PRESSURE_COUNT) is used as an index into m_addPressure and m_remPressure UINT GCInterface::m_iteration = 0; -FCIMPL5(void, GCInterface::GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) +FCIMPL6(void, GCInterface::GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT64* heapHardLimit, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) { FCALL_CONTRACT; FC_GC_POLL_NOT_NEEDED(); - return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalPhysicalMem, + return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalPhysicalMem, heapHardLimit, lastRecordedMemLoad, lastRecordedHeapSize, lastRecordedFragmentation); } diff --git a/src/vm/comutilnative.h b/src/vm/comutilnative.h index 6afbc5a45e3d..9f01b1b43113 100644 --- a/src/vm/comutilnative.h +++ b/src/vm/comutilnative.h @@ -110,7 +110,7 @@ class GCInterface { static FORCEINLINE UINT64 InterlockedAdd(UINT64 *pAugend, UINT64 addend); static FORCEINLINE UINT64 InterlockedSub(UINT64 *pMinuend, UINT64 subtrahend); - static FCDECL5(void, GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); + static FCDECL6(void, GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT64* heapHardLimit, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); static FCDECL0(int, GetGcLatencyMode); static FCDECL1(int, SetGcLatencyMode, int newLatencyMode); static FCDECL0(int, GetLOHCompactionMode); From c48503896b7e1af54ce089e8f4d531ff939f91ab Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 1 Jul 2019 21:52:46 -0700 Subject: [PATCH 5/6] Do more work in gc.cpp instead of Gc.cs --- src/System.Private.CoreLib/src/System/GC.cs | 28 ++++++++++----------- src/gc/gc.cpp | 16 ++++++------ src/gc/gcimpl.h | 8 +++--- src/gc/gcinterface.h | 8 +++--- src/vm/comutilnative.cpp | 6 ++--- src/vm/comutilnative.h | 2 +- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/GC.cs b/src/System.Private.CoreLib/src/System/GC.cs index ecb1a659d1cb..24094a814798 100644 --- a/src/System.Private.CoreLib/src/System/GC.cs +++ b/src/System.Private.CoreLib/src/System/GC.cs @@ -54,26 +54,26 @@ public enum GCNotificationStatus public static class GC { [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern void GetMemoryInfo(out uint highMemLoadThreshold, - out ulong totalPhysicalMem, - out ulong heapHardLimit, - out uint lastRecordedMemLoad, + internal static extern void GetMemoryInfo(out ulong highMemLoadThresholdBytes, + out ulong totalAvailableMemoryBytes, + out ulong lastRecordedMemLoadBytes, + out uint lastRecordedMemLoadPct, // The next two are size_t out UIntPtr lastRecordedHeapSize, out UIntPtr lastRecordedFragmentation); public static GCMemoryInfo GetGCMemoryInfo() { - GetMemoryInfo(out uint highMemLoadThreshold, - out ulong totalPhysicalMem, - out ulong heapHardLimit, - out uint lastRecordedMemLoad, + GetMemoryInfo(out ulong highMemLoadThresholdBytes, + out ulong totalAvailableMemoryBytes, + out ulong lastRecordedMemLoadBytes, + out uint _, out UIntPtr lastRecordedHeapSize, out UIntPtr lastRecordedFragmentation); - return new GCMemoryInfo(highMemoryLoadThresholdBytes: (long)((double)highMemLoadThreshold / 100 * totalPhysicalMem), - memoryLoadBytes: (long)((double)lastRecordedMemLoad / 100 * totalPhysicalMem), - totalAvailableMemoryBytes: (long)(heapHardLimit != 0 ? heapHardLimit : totalPhysicalMem), + return new GCMemoryInfo(highMemoryLoadThresholdBytes: (long)highMemLoadThresholdBytes, + memoryLoadBytes: (long)lastRecordedMemLoadBytes, + totalAvailableMemoryBytes: (long)totalAvailableMemoryBytes, heapSizeBytes: (long)(ulong)lastRecordedHeapSize, fragmentedBytes: (long)(ulong)lastRecordedFragmentation); } @@ -543,14 +543,14 @@ public MemoryLoadChangeNotification(float lowMemoryPercent, float highMemoryPerc private static float GetMemoryLoad() { - GetMemoryInfo(out uint _, + GetMemoryInfo(out ulong _, out ulong _, out ulong _, - out uint lastRecordedMemLoad, + out uint lastRecordedMemLoadPct, out UIntPtr _, out UIntPtr _); - return (float)lastRecordedMemLoad / 100; + return (float)lastRecordedMemLoadPct; } private static bool InvokeMemoryLoadChangeNotifications() diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index c0c88779e150..ae38a0905617 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -36150,17 +36150,17 @@ unsigned int GCHeap::GetCondemnedGeneration() return gc_heap::settings.condemned_generation; } -void GCHeap::GetMemoryInfo(uint32_t* highMemLoadThreshold, - uint64_t* totalPhysicalMem, - uint64_t* heapHardLimit, - uint32_t* lastRecordedMemLoad, +void GCHeap::GetMemoryInfo(uint64_t* highMemLoadThresholdBytes, + uint64_t* totalAvailableMemoryBytes, + uint64_t* lastRecordedMemLoadBytes, + uint32_t* lastRecordedMemLoadPct, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) { - *highMemLoadThreshold = gc_heap::high_memory_load_th; - *totalPhysicalMem = gc_heap::total_physical_mem; - *heapHardLimit = gc_heap::heap_hard_limit; - *lastRecordedMemLoad = gc_heap::last_gc_memory_load; + *highMemLoadThresholdBytes = (uint64_t) (((double)gc_heap::high_memory_load_th) / 100 * gc_heap::total_physical_mem); + *totalAvailableMemoryBytes = gc_heap::heap_hard_limit != 0 ? gc_heap::heap_hard_limit : gc_heap::total_physical_mem; + *lastRecordedMemLoadBytes = (uint64_t) (((double)gc_heap::last_gc_memory_load) / 100 * gc_heap::total_physical_mem); + *lastRecordedMemLoadPct = gc_heap::last_gc_memory_load; *lastRecordedHeapSize = gc_heap::last_gc_heap_size; *lastRecordedFragmentation = gc_heap::last_gc_fragmentation; } diff --git a/src/gc/gcimpl.h b/src/gc/gcimpl.h index f0af851d2ee7..91508c783ee4 100644 --- a/src/gc/gcimpl.h +++ b/src/gc/gcimpl.h @@ -171,10 +171,10 @@ class GCHeap : public IGCHeapInternal unsigned GetCondemnedGeneration(); - void GetMemoryInfo(uint32_t* highMemLoadThreshold, - uint64_t* totalPhysicalMem, - uint64_t* heapHardLimit, - uint32_t* lastRecordedMemLoad, + void GetMemoryInfo(uint64_t* highMemLoadThresholdBytes, + uint64_t* totalAvailableMemoryBytes, + uint64_t* lastRecordedMemLoadBytes, + uint32_t* lastRecordedMemLoadPct, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); diff --git a/src/gc/gcinterface.h b/src/gc/gcinterface.h index 84ea95582a46..af2ff506a79a 100644 --- a/src/gc/gcinterface.h +++ b/src/gc/gcinterface.h @@ -605,10 +605,10 @@ class IGCHeap { // lastRecordedMemLoad - physical memory load in percentage recorded in the last GC // lastRecordedHeapSize - total managed heap size recorded in the last GC // lastRecordedFragmentation - total fragmentation in the managed heap recorded in the last GC - virtual void GetMemoryInfo(uint32_t* highMemLoadThreshold, - uint64_t* totalPhysicalMem, - uint64_t* heapHardLimit, - uint32_t* lastRecordedMemLoad, + virtual void GetMemoryInfo(uint64_t* highMemLoadThresholdBytes, + uint64_t* totalPhysicalMemoryBytes, + uint64_t* lastRecordedMemLoadBytes, + uint32_t* lastRecordedMemLoadPct, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) = 0; diff --git a/src/vm/comutilnative.cpp b/src/vm/comutilnative.cpp index beeac9d2ff64..e2531ff259cc 100644 --- a/src/vm/comutilnative.cpp +++ b/src/vm/comutilnative.cpp @@ -886,14 +886,14 @@ UINT64 GCInterface::m_remPressure[NEW_PRESSURE_COUNT] = {0, 0, 0, 0}; // his // (m_iteration % NEW_PRESSURE_COUNT) is used as an index into m_addPressure and m_remPressure UINT GCInterface::m_iteration = 0; -FCIMPL6(void, GCInterface::GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT64* heapHardLimit, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) +FCIMPL6(void, GCInterface::GetMemoryInfo, UINT64* highMemLoadThreshold, UINT64* totalAvailableMemoryBytes, UINT64* lastRecordedMemLoadBytes, UINT32* lastRecordedMemLoadPct, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) { FCALL_CONTRACT; FC_GC_POLL_NOT_NEEDED(); - return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalPhysicalMem, heapHardLimit, - lastRecordedMemLoad, + return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalAvailableMemoryBytes, + lastRecordedMemLoadBytes, lastRecordedMemLoadPct, lastRecordedHeapSize, lastRecordedFragmentation); } FCIMPLEND diff --git a/src/vm/comutilnative.h b/src/vm/comutilnative.h index 9f01b1b43113..a51dd25d2a9c 100644 --- a/src/vm/comutilnative.h +++ b/src/vm/comutilnative.h @@ -110,7 +110,7 @@ class GCInterface { static FORCEINLINE UINT64 InterlockedAdd(UINT64 *pAugend, UINT64 addend); static FORCEINLINE UINT64 InterlockedSub(UINT64 *pMinuend, UINT64 subtrahend); - static FCDECL6(void, GetMemoryInfo, UINT32* highMemLoadThreshold, UINT64* totalPhysicalMem, UINT64* heapHardLimit, UINT32* lastRecordedMemLoad, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); + static FCDECL6(void, GetMemoryInfo, UINT64* highMemLoadThresholdBytes, UINT64* totalAvailableMemoryBytes, UINT64* lastRecordedMemLoadBytes, UINT32* lastRecordedMemLoadPct, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); static FCDECL0(int, GetGcLatencyMode); static FCDECL1(int, SetGcLatencyMode, int newLatencyMode); static FCDECL0(int, GetLOHCompactionMode); From cb8f824bc1bc407579906cb8866d3970fe8cc82a Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 2 Jul 2019 13:45:38 -0700 Subject: [PATCH 6/6] Consistently end names in "Bytes" --- src/System.Private.CoreLib/src/System/GC.cs | 12 ++++++------ src/gc/gc.cpp | 8 ++++---- src/gc/gcimpl.h | 4 ++-- src/gc/gcinterface.h | 4 ++-- src/vm/comutilnative.cpp | 4 ++-- src/vm/comutilnative.h | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/GC.cs b/src/System.Private.CoreLib/src/System/GC.cs index 24094a814798..03eed93cd060 100644 --- a/src/System.Private.CoreLib/src/System/GC.cs +++ b/src/System.Private.CoreLib/src/System/GC.cs @@ -59,8 +59,8 @@ internal static extern void GetMemoryInfo(out ulong highMemLoadThresholdBytes, out ulong lastRecordedMemLoadBytes, out uint lastRecordedMemLoadPct, // The next two are size_t - out UIntPtr lastRecordedHeapSize, - out UIntPtr lastRecordedFragmentation); + out UIntPtr lastRecordedHeapSizeBytes, + out UIntPtr lastRecordedFragmentationBytes); public static GCMemoryInfo GetGCMemoryInfo() { @@ -68,14 +68,14 @@ public static GCMemoryInfo GetGCMemoryInfo() out ulong totalAvailableMemoryBytes, out ulong lastRecordedMemLoadBytes, out uint _, - out UIntPtr lastRecordedHeapSize, - out UIntPtr lastRecordedFragmentation); + out UIntPtr lastRecordedHeapSizeBytes, + out UIntPtr lastRecordedFragmentationBytes); return new GCMemoryInfo(highMemoryLoadThresholdBytes: (long)highMemLoadThresholdBytes, memoryLoadBytes: (long)lastRecordedMemLoadBytes, totalAvailableMemoryBytes: (long)totalAvailableMemoryBytes, - heapSizeBytes: (long)(ulong)lastRecordedHeapSize, - fragmentedBytes: (long)(ulong)lastRecordedFragmentation); + heapSizeBytes: (long)(ulong)lastRecordedHeapSizeBytes, + fragmentedBytes: (long)(ulong)lastRecordedFragmentationBytes); } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index ae38a0905617..6a8d4f8e7453 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -36154,15 +36154,15 @@ void GCHeap::GetMemoryInfo(uint64_t* highMemLoadThresholdBytes, uint64_t* totalAvailableMemoryBytes, uint64_t* lastRecordedMemLoadBytes, uint32_t* lastRecordedMemLoadPct, - size_t* lastRecordedHeapSize, - size_t* lastRecordedFragmentation) + size_t* lastRecordedHeapSizeBytes, + size_t* lastRecordedFragmentationBytes) { *highMemLoadThresholdBytes = (uint64_t) (((double)gc_heap::high_memory_load_th) / 100 * gc_heap::total_physical_mem); *totalAvailableMemoryBytes = gc_heap::heap_hard_limit != 0 ? gc_heap::heap_hard_limit : gc_heap::total_physical_mem; *lastRecordedMemLoadBytes = (uint64_t) (((double)gc_heap::last_gc_memory_load) / 100 * gc_heap::total_physical_mem); *lastRecordedMemLoadPct = gc_heap::last_gc_memory_load; - *lastRecordedHeapSize = gc_heap::last_gc_heap_size; - *lastRecordedFragmentation = gc_heap::last_gc_fragmentation; + *lastRecordedHeapSizeBytes = gc_heap::last_gc_heap_size; + *lastRecordedFragmentationBytes = gc_heap::last_gc_fragmentation; } int GCHeap::GetGcLatencyMode() diff --git a/src/gc/gcimpl.h b/src/gc/gcimpl.h index 91508c783ee4..965bfa698770 100644 --- a/src/gc/gcimpl.h +++ b/src/gc/gcimpl.h @@ -175,8 +175,8 @@ class GCHeap : public IGCHeapInternal uint64_t* totalAvailableMemoryBytes, uint64_t* lastRecordedMemLoadBytes, uint32_t* lastRecordedMemLoadPct, - size_t* lastRecordedHeapSize, - size_t* lastRecordedFragmentation); + size_t* lastRecordedHeapSizeBytes, + size_t* lastRecordedFragmentationBytes); int GetGcLatencyMode(); int SetGcLatencyMode(int newLatencyMode); diff --git a/src/gc/gcinterface.h b/src/gc/gcinterface.h index af2ff506a79a..062743ff37b2 100644 --- a/src/gc/gcinterface.h +++ b/src/gc/gcinterface.h @@ -609,8 +609,8 @@ class IGCHeap { uint64_t* totalPhysicalMemoryBytes, uint64_t* lastRecordedMemLoadBytes, uint32_t* lastRecordedMemLoadPct, - size_t* lastRecordedHeapSize, - size_t* lastRecordedFragmentation) = 0; + size_t* lastRecordedHeapSizeBytes, + size_t* lastRecordedFragmentationBytes) = 0; // Gets the current GC latency mode. virtual int GetGcLatencyMode() = 0; diff --git a/src/vm/comutilnative.cpp b/src/vm/comutilnative.cpp index e2531ff259cc..ccb9ea219477 100644 --- a/src/vm/comutilnative.cpp +++ b/src/vm/comutilnative.cpp @@ -886,7 +886,7 @@ UINT64 GCInterface::m_remPressure[NEW_PRESSURE_COUNT] = {0, 0, 0, 0}; // his // (m_iteration % NEW_PRESSURE_COUNT) is used as an index into m_addPressure and m_remPressure UINT GCInterface::m_iteration = 0; -FCIMPL6(void, GCInterface::GetMemoryInfo, UINT64* highMemLoadThreshold, UINT64* totalAvailableMemoryBytes, UINT64* lastRecordedMemLoadBytes, UINT32* lastRecordedMemLoadPct, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation) +FCIMPL6(void, GCInterface::GetMemoryInfo, UINT64* highMemLoadThreshold, UINT64* totalAvailableMemoryBytes, UINT64* lastRecordedMemLoadBytes, UINT32* lastRecordedMemLoadPct, size_t* lastRecordedHeapSizeBytes, size_t* lastRecordedFragmentationBytes) { FCALL_CONTRACT; @@ -894,7 +894,7 @@ FCIMPL6(void, GCInterface::GetMemoryInfo, UINT64* highMemLoadThreshold, UINT64* return GCHeapUtilities::GetGCHeap()->GetMemoryInfo(highMemLoadThreshold, totalAvailableMemoryBytes, lastRecordedMemLoadBytes, lastRecordedMemLoadPct, - lastRecordedHeapSize, lastRecordedFragmentation); + lastRecordedHeapSizeBytes, lastRecordedFragmentationBytes); } FCIMPLEND diff --git a/src/vm/comutilnative.h b/src/vm/comutilnative.h index a51dd25d2a9c..5267d6ef732b 100644 --- a/src/vm/comutilnative.h +++ b/src/vm/comutilnative.h @@ -110,7 +110,7 @@ class GCInterface { static FORCEINLINE UINT64 InterlockedAdd(UINT64 *pAugend, UINT64 addend); static FORCEINLINE UINT64 InterlockedSub(UINT64 *pMinuend, UINT64 subtrahend); - static FCDECL6(void, GetMemoryInfo, UINT64* highMemLoadThresholdBytes, UINT64* totalAvailableMemoryBytes, UINT64* lastRecordedMemLoadBytes, UINT32* lastRecordedMemLoadPct, size_t* lastRecordedHeapSize, size_t* lastRecordedFragmentation); + static FCDECL6(void, GetMemoryInfo, UINT64* highMemLoadThresholdBytes, UINT64* totalAvailableMemoryBytes, UINT64* lastRecordedMemLoadBytes, UINT32* lastRecordedMemLoadPct, size_t* lastRecordedHeapSizBytes, size_t* lastRecordedFragmentationBytes); static FCDECL0(int, GetGcLatencyMode); static FCDECL1(int, SetGcLatencyMode, int newLatencyMode); static FCDECL0(int, GetLOHCompactionMode);