From 1724b4c2180e7fbf6a2139422bdb7bb4db3c9edc Mon Sep 17 00:00:00 2001 From: Maoni0 Date: Fri, 5 Aug 2022 00:02:41 -0700 Subject: [PATCH 1/2] no default SIP --- src/coreclr/gc/gc.cpp | 15 ++++++++++++--- src/coreclr/gc/gcconfig.h | 1 + src/coreclr/gc/gcpriv.h | 19 +++++++++++-------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 67ff74640c7cb..5a8a9b0898d6c 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -2660,7 +2660,9 @@ bool gc_heap::use_large_pages_p = 0; #ifdef HEAP_BALANCE_INSTRUMENTATION size_t gc_heap::last_gc_end_time_us = 0; #endif //HEAP_BALANCE_INSTRUMENTATION -#ifndef USE_REGIONS +#ifdef USE_REGIONS +bool gc_heap::enable_special_regions_p = false; +#else //USE_REGIONS size_t gc_heap::min_segment_size = 0; size_t gc_heap::min_uoh_segment_size = 0; #endif //!USE_REGIONS @@ -5622,7 +5624,6 @@ gc_heap::soh_get_segment_to_expand() dprintf (GTC_LOG, ("(gen%d)creating new segment %Ix", settings.condemned_generation, result)); return result; } -#endif //!USE_REGIONS //returns 0 in case of allocation failure heap_segment* @@ -5768,6 +5769,7 @@ void gc_heap::release_segment (heap_segment* sg) FIRE_EVENT(GCFreeSegment_V1, heap_segment_mem(sg)); virtual_free (sg, (uint8_t*)heap_segment_reserved (sg)-(uint8_t*)sg, sg); } +#endif //!USE_REGIONS heap_segment* gc_heap::get_segment_for_uoh (int gen_number, size_t size #ifdef MULTIPLE_HEAPS @@ -8886,6 +8888,7 @@ void gc_heap::set_fgm_result (failure_get_memory f, size_t s, BOOL loh_p) #endif //MULTIPLE_HEAPS } +#ifndef USE_REGIONS //returns 0 for success, -1 otherwise // We are doing all the decommitting here because we want to make sure we have // enough memory to do so - if we do this during copy_brick_card_table and @@ -9195,6 +9198,7 @@ int gc_heap::grow_brick_card_tables (uint8_t* start, return 0; } +#endif //!USE_REGIONS //copy all of the arrays managed by the card table for a page aligned range void gc_heap::copy_brick_card_range (uint8_t* la, uint32_t* old_card_table, @@ -11146,7 +11150,6 @@ void gc_heap::clear_region_info (heap_segment* region) } // Note that returning a region to free does not decommit. -// REGIONS PERF TODO: should decommit if needed. void gc_heap::return_free_region (heap_segment* region) { gc_oh_num oh = heap_segment_oh (region); @@ -30797,6 +30800,11 @@ void gc_heap::update_start_tail_regions (generation* gen, inline bool gc_heap::should_sweep_in_plan (heap_segment* region) { + if (!enable_special_regions_p) + { + return false; + } + if (settings.reason == reason_induced_aggressive) { return false; @@ -44327,6 +44335,7 @@ HRESULT GCHeap::Initialize() GCConfig::SetHeapCount(static_cast(nhp)); #ifdef USE_REGIONS + gc_heap::enable_special_regions_p = (bool)GCConfig::GetGCEnableSpecialRegions(); size_t gc_region_size = (size_t)GCConfig::GetGCRegionSize(); if (!power_of_two_p(gc_region_size) || ((gc_region_size * nhp * 19) > gc_heap::regions_range)) { diff --git a/src/coreclr/gc/gcconfig.h b/src/coreclr/gc/gcconfig.h index e99a9ecded330..92fe5a49ac642 100644 --- a/src/coreclr/gc/gcconfig.h +++ b/src/coreclr/gc/gcconfig.h @@ -105,6 +105,7 @@ class GCConfigStringHolder INT_CONFIG (GCTotalPhysicalMemory, "GCTotalPhysicalMemory", NULL, 0, "Specifies what the GC should consider to be total physical memory") \ 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") \ + INT_CONFIG (GCEnableSpecialRegions, "GCEnableSpecialRegions", NULL, 0, "Specifies to enable special handling some regions like SIP") \ 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") \ INT_CONFIG (BGCFLTuningEnabled, "BGCFLTuningEnabled", NULL, 0, "Enables FL tuning") \ diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index 2c18c93681e02..2d46a4d0fbea0 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -52,7 +52,7 @@ inline void FATAL_GC_ERROR() // This means any empty regions can be freely used for any generation. For // Server GC we will balance regions between heaps. // For now disable regions for StandAlone GC, NativeAOT and MacOS builds -#if defined (HOST_64BIT) && !defined (BUILD_AS_STANDALONE) && !defined(__APPLE__) && !defined(FEATURE_NATIVEAOT) +#if defined (HOST_64BIT) && defined (BUILD_AS_STANDALONE) && !defined(__APPLE__) && !defined(FEATURE_NATIVEAOT) #define USE_REGIONS #endif //HOST_64BIT && BUILD_AS_STANDALONE @@ -1596,17 +1596,16 @@ class gc_heap static void get_card_table_element_sizes (uint8_t* start, uint8_t* end, size_t bookkeeping_sizes[total_bookkeeping_elements]); + static + void set_fgm_result (failure_get_memory f, size_t s, BOOL loh_p); + #ifdef USE_REGIONS static bool on_used_changed (uint8_t* left); static bool inplace_commit_card_table (uint8_t* from, uint8_t* to); -#endif //USE_REGIONS - - static - void set_fgm_result (failure_get_memory f, size_t s, BOOL loh_p); - +#else //USE_REGIONS static int grow_brick_card_tables (uint8_t* start, uint8_t* end, @@ -1614,6 +1613,7 @@ class gc_heap heap_segment* new_seg, gc_heap* hp, BOOL loh_p); +#endif //USE_REGIONS PER_HEAP_ISOLATED BOOL is_mark_set (uint8_t* o); @@ -2001,11 +2001,11 @@ class gc_heap #ifndef USE_REGIONS PER_HEAP heap_segment* soh_get_segment_to_expand(); -#endif //!USE_REGIONS PER_HEAP heap_segment* get_segment (size_t size, gc_oh_num oh); PER_HEAP_ISOLATED void release_segment (heap_segment* sg); +#endif //!USE_REGIONS PER_HEAP_ISOLATED void seg_mapping_table_add_segment (heap_segment* seg, gc_heap* hp); PER_HEAP_ISOLATED @@ -4040,7 +4040,10 @@ class gc_heap size_t last_gc_end_time_us; #endif //HEAP_BALANCE_INSTRUMENTATION -#ifndef USE_REGIONS +#ifdef USE_REGIONS + PER_HEAP_ISOLATED + bool enable_special_regions_p; +#else //USE_REGIONS PER_HEAP_ISOLATED size_t min_segment_size; From 2ec40f2266e174fbb53751b516d66a835744887c Mon Sep 17 00:00:00 2001 From: Maoni0 Date: Fri, 5 Aug 2022 11:08:01 -0700 Subject: [PATCH 2/2] correct my mistake of accidently inverting which dll has regions --- src/coreclr/gc/gcpriv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index 2d46a4d0fbea0..d834dcbcc4f29 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -52,7 +52,7 @@ inline void FATAL_GC_ERROR() // This means any empty regions can be freely used for any generation. For // Server GC we will balance regions between heaps. // For now disable regions for StandAlone GC, NativeAOT and MacOS builds -#if defined (HOST_64BIT) && defined (BUILD_AS_STANDALONE) && !defined(__APPLE__) && !defined(FEATURE_NATIVEAOT) +#if defined (HOST_64BIT) && !defined (BUILD_AS_STANDALONE) && !defined(__APPLE__) && !defined(FEATURE_NATIVEAOT) #define USE_REGIONS #endif //HOST_64BIT && BUILD_AS_STANDALONE