[release/6.0] In reset_memory, check settings.entry_memory_load ... (#58543)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Thu, 2 Sep 2021 20:43:20 +0000 (13:43 -0700)
committerGitHub <noreply@github.com>
Thu, 2 Sep 2021 20:43:20 +0000 (13:43 -0700)
* In reset_memory, check settings.entry_memory_load in addition to g_low_memory_status - it looks like the latter won't be set on Linux.

* Factor out common logic for detecting high memory load.

* Make high_memory_load_p a member function of gc_heap and rename to dt_high_memory_load_p.

Co-authored-by: Peter Sollich <petersol@microsoft.com>
src/coreclr/gc/gc.cpp
src/coreclr/gc/gcpriv.h

index 26233d5..be40c4a 100644 (file)
@@ -3256,6 +3256,12 @@ gc_heap::dt_low_card_table_efficiency_p (gc_tuning_point tp)
 }
 
 inline BOOL
+gc_heap::dt_high_memory_load_p()
+{
+    return ((settings.entry_memory_load >= high_memory_load_th) || g_low_memory_status);
+}
+
+inline BOOL
 in_range_for_segment(uint8_t* add, heap_segment* seg)
 {
     return ((add >= heap_segment_mem (seg)) && (add < heap_segment_reserved (seg)));
@@ -10917,7 +10923,7 @@ void gc_heap::clear_region_info (heap_segment* region)
                         settings.gc_index, current_bgc_state,
                         seg_deleted);
 
-    if (settings.entry_memory_load >= high_memory_load_th || g_low_memory_status)
+    if (dt_high_memory_load_p())
     {
         decommit_mark_array_by_seg (region);
     }
@@ -11376,7 +11382,7 @@ size_t gc_heap::decommit_heap_segment_pages_worker (heap_segment* seg,
                                                     uint8_t* new_committed)
 {
 #ifdef USE_REGIONS
-    if (settings.entry_memory_load < high_memory_load_th && !g_low_memory_status)
+    if (!dt_high_memory_load_p())
     {
         return 0;
     }
@@ -11411,7 +11417,7 @@ size_t gc_heap::decommit_heap_segment_pages_worker (heap_segment* seg,
 void gc_heap::decommit_heap_segment (heap_segment* seg)
 {
 #ifdef USE_REGIONS
-    if (settings.entry_memory_load < high_memory_load_th && !g_low_memory_status)
+    if (!dt_high_memory_load_p())
     {
         return;
     }
@@ -39355,7 +39361,7 @@ void reset_memory (uint8_t* o, size_t sizeo)
         size_t size = align_lower_page ((size_t)o + sizeo - size_to_skip - plug_skew) - page_start;
         // Note we need to compensate for an OS bug here. This bug would cause the MEM_RESET to fail
         // on write watched memory.
-        if (reset_mm_p && gc_heap::g_low_memory_status)
+        if (reset_mm_p && gc_heap::dt_high_memory_load_p())
         {
 #ifdef MULTIPLE_HEAPS
             bool unlock_p = true;
index cda8e68..ce14ce6 100644 (file)
@@ -4962,6 +4962,9 @@ public:
     PER_HEAP_ISOLATED
     size_t exponential_smoothing (int gen, size_t collection_count, size_t desired_per_heap);
 
+    PER_HEAP_ISOLATED
+    BOOL dt_high_memory_load_p();
+
 protected:
     PER_HEAP
     void update_collection_counts ();