From bb3677126e3cc11cec206e08ebe2eeb9d191d862 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Thu, 30 Jun 2022 13:11:56 -0700 Subject: [PATCH] Adjust regions range dynamically based on memory limits (#71164) --- src/coreclr/gc/gc.cpp | 22 +++++++++++++++++----- src/coreclr/gc/gcconfig.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 1021d669b2dc3..57e0864bf9a59 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -43855,11 +43855,6 @@ HRESULT GCHeap::Initialize() { gc_heap::total_physical_mem = GCToOSInterface::GetPhysicalMemoryLimit (&gc_heap::is_restricted_physical_mem); } - -#ifdef USE_REGIONS - gc_heap::regions_range = (size_t)GCConfig::GetGCRegionRange(); -#endif //USE_REGIONS - #ifdef HOST_64BIT gc_heap::heap_hard_limit = (size_t)GCConfig::GetGCHeapHardLimit(); gc_heap::heap_hard_limit_oh[soh] = (size_t)GCConfig::GetGCHeapHardLimitSOH(); @@ -43948,6 +43943,23 @@ HRESULT GCHeap::Initialize() return CLR_E_GC_LARGE_PAGE_MISSING_HARD_LIMIT; } +#ifdef USE_REGIONS + gc_heap::regions_range = (size_t)GCConfig::GetGCRegionRange(); + if (gc_heap::regions_range == 0) + { + if (gc_heap::heap_hard_limit) + { + gc_heap::regions_range = 2 * gc_heap::heap_hard_limit; + } + else + { + gc_heap::regions_range = max(((size_t)256 * 1024 * 1024 * 1024), (size_t)(2 * gc_heap::total_physical_mem)); + } + gc_heap::regions_range = align_on_page(gc_heap::regions_range); + } + // TODO: Set config after config API is merged. +#endif //USE_REGIONS + #endif //HOST_64BIT uint32_t nhp = 1; diff --git a/src/coreclr/gc/gcconfig.h b/src/coreclr/gc/gcconfig.h index 28e0581d00c09..f8410a15a0c87 100644 --- a/src/coreclr/gc/gcconfig.h +++ b/src/coreclr/gc/gcconfig.h @@ -103,7 +103,7 @@ class GCConfigStringHolder INT_CONFIG (GCHeapHardLimit, "GCHeapHardLimit", "System.GC.HeapHardLimit", 0, "Specifies a hard limit for the GC heap") \ INT_CONFIG (GCHeapHardLimitPercent, "GCHeapHardLimitPercent", "System.GC.HeapHardLimitPercent", 0, "Specifies the GC heap usage as a percentage of the total memory") \ INT_CONFIG (GCTotalPhysicalMemory, "GCTotalPhysicalMemory", NULL, 0, "Specifies what the GC should consider to be total physical memory") \ - INT_CONFIG (GCRegionRange, "GCRegionRange", NULL, 274877906944L, "Specifies the range for the GC heap") \ + INT_CONFIG (GCRegionRange, "GCRegionRange", NULL, 0, "Specifies the range for the GC heap") \ INT_CONFIG (GCRegionSize, "GCRegionSize", NULL, 4194304, "Specifies the size for a basic GC region") \ STRING_CONFIG(LogFile, "GCLogFile", NULL, "Specifies the name of the GC log file") \ STRING_CONFIG(ConfigLogFile, "GCConfigLogFile", NULL, "Specifies the name of the GC config log file") \