Skip to content

Commit

Permalink
Adjust regions range dynamically based on memory limits (dotnet#71164)
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung authored Jun 30, 2022
1 parent 7cf661d commit bb36771
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/gc/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") \
Expand Down

0 comments on commit bb36771

Please sign in to comment.