summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib
diff options
context:
space:
mode:
authorAndy Hanson <anhans@microsoft.com>2019-07-08 16:12:06 -0700
committerJan Kotas <jkotas@microsoft.com>2019-07-08 16:12:06 -0700
commit11137fbe46f524dfd6c2f7bb2a77035aa225524c (patch)
tree116160fa9d0ed8c8cb2fa1cb6ac407e476ab96cf /src/System.Private.CoreLib
parent8749c016e520bcaa23c56a862fe5f57eba1b879b (diff)
downloadcoreclr-11137fbe46f524dfd6c2f7bb2a77035aa225524c.tar.gz
coreclr-11137fbe46f524dfd6c2f7bb2a77035aa225524c.tar.bz2
coreclr-11137fbe46f524dfd6c2f7bb2a77035aa225524c.zip
Return HardLimitBytes from GCMemoryInfo.TotalAvailableMemoryBytes (#25437)
* 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 * Remove HardLimitBytes; have TotalAvailableMemoryBytes take on its behavior * Fix typos * Separate total_physical_mem and heap_hard_limit so we can compute highMemoryLoadThresholdBytes and memoryLoadBytes * Do more work in gc.cpp instead of Gc.cs * Consistently end names in "Bytes"
Diffstat (limited to 'src/System.Private.CoreLib')
-rw-r--r--src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs7
-rw-r--r--src/System.Private.CoreLib/src/System/GC.cs39
2 files changed, 27 insertions, 19 deletions
diff --git a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs
index 72c2aca14d..850f1256eb 100644
--- a/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs
+++ b/src/System.Private.CoreLib/shared/System/GCMemoryInfo.cs
@@ -17,7 +17,12 @@ namespace System
public long MemoryLoadBytes { get; }
/// <summary>
- /// 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.
+ ///
+ /// 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.
/// </summary>
public long TotalAvailableMemoryBytes { get; }
diff --git a/src/System.Private.CoreLib/src/System/GC.cs b/src/System.Private.CoreLib/src/System/GC.cs
index 89c277e544..e67c043e62 100644
--- a/src/System.Private.CoreLib/src/System/GC.cs
+++ b/src/System.Private.CoreLib/src/System/GC.cs
@@ -54,26 +54,28 @@ namespace System
public static class GC
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern void GetMemoryInfo(out uint highMemLoadThreshold,
- out ulong totalPhysicalMem,
- 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);
+ out UIntPtr lastRecordedHeapSizeBytes,
+ out UIntPtr lastRecordedFragmentationBytes);
public static GCMemoryInfo GetGCMemoryInfo()
{
- GetMemoryInfo(out uint highMemLoadThreshold,
- out ulong totalPhysicalMem,
- out uint lastRecordedMemLoad,
- out UIntPtr lastRecordedHeapSize,
- out UIntPtr lastRecordedFragmentation);
+ GetMemoryInfo(out ulong highMemLoadThresholdBytes,
+ out ulong totalAvailableMemoryBytes,
+ out ulong lastRecordedMemLoadBytes,
+ out uint _,
+ out UIntPtr lastRecordedHeapSizeBytes,
+ out UIntPtr lastRecordedFragmentationBytes);
- 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)highMemLoadThresholdBytes,
+ memoryLoadBytes: (long)lastRecordedMemLoadBytes,
+ totalAvailableMemoryBytes: (long)totalAvailableMemoryBytes,
+ heapSizeBytes: (long)(ulong)lastRecordedHeapSizeBytes,
+ fragmentedBytes: (long)(ulong)lastRecordedFragmentationBytes);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
@@ -541,13 +543,14 @@ namespace System
private static float GetMemoryLoad()
{
- GetMemoryInfo(out uint _,
+ GetMemoryInfo(out ulong _,
out ulong _,
- out uint lastRecordedMemLoad,
+ out ulong _,
+ out uint lastRecordedMemLoadPct,
out UIntPtr _,
out UIntPtr _);
- return (float)lastRecordedMemLoad / 100;
+ return (float)lastRecordedMemLoadPct;
}
private static bool InvokeMemoryLoadChangeNotifications()