From 400ac4f08dfc0e430e6fc4a9ecc215d2b8faaa2b Mon Sep 17 00:00:00 2001 From: Mark Plesko Date: Thu, 22 Feb 2024 01:59:47 -0800 Subject: [PATCH 1/2] Reset inc_failure_count whenever below target, not just if decreasing the hc --- src/coreclr/gc/gc.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 4d281b16251a1e..b4ee811cc6d368 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -25650,6 +25650,12 @@ int gc_heap::calculate_new_heap_count () dynamic_heap_count_data.below_target_accumulation = 0; } + if (dynamic_heap_count_data.inc_failure_count) + { + dprintf (6666, ("[CHP1] shrink, reset inc failure count (was %d)", dynamic_heap_count_data.inc_failure_count)); + dynamic_heap_count_data.inc_failure_count = 0; + } + if (new_n_heaps < n_heaps) { dynamic_heap_count_data.last_changed_gc_index = current_gc_index; @@ -25657,12 +25663,6 @@ int gc_heap::calculate_new_heap_count () dynamic_heap_count_data.last_changed_stcp = smoothed_median_throughput_cost_percent; dprintf (6666, ("[CHP1] setting last changed gc index to %Id, count to %.3f, stcp to %.3f", dynamic_heap_count_data.last_changed_gc_index, dynamic_heap_count_data.last_changed_count, dynamic_heap_count_data.last_changed_stcp)); - - if (dynamic_heap_count_data.inc_failure_count) - { - dprintf (6666, ("[CHP1] shrink, reset inc failure count (was %d)", dynamic_heap_count_data.inc_failure_count)); - dynamic_heap_count_data.inc_failure_count = 0; - } } } } From 7961d6312449af387129d454aea403d5a4709cfa Mon Sep 17 00:00:00 2001 From: Mark Plesko Date: Thu, 22 Feb 2024 02:35:36 -0800 Subject: [PATCH 2/2] Limit inc_failure_count to 2 and ignore it after 40 GCs --- src/coreclr/gc/gc.cpp | 12 ++++++++---- src/coreclr/gc/gcpriv.h | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index b4ee811cc6d368..92d803351d3a6b 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -25492,10 +25492,14 @@ int gc_heap::calculate_new_heap_count () { if (((int)dynamic_heap_count_data.last_changed_count > 0) && (dynamic_heap_count_data.last_changed_gc_index > 0.0)) { - (dynamic_heap_count_data.inc_failure_count)++; - dprintf (6666, ("[CHP0-4] just grew %d GCs ago, grow more aggressively from %d -> %d more heaps", - (current_gc_index - dynamic_heap_count_data.last_changed_gc_index), step_up_int, (step_up_int * (dynamic_heap_count_data.inc_failure_count + 1)))); - step_up_int *= dynamic_heap_count_data.inc_failure_count + 1; + size_t gc_count_since_last_growth = (current_gc_index - dynamic_heap_count_data.last_changed_gc_index); + if (gc_count_since_last_growth <= dynamic_heap_count_data.inc_failure_gcs_threshold) + { + dynamic_heap_count_data.inc_failure_count = min(dynamic_heap_count_data.inc_failure_count + 1, dynamic_heap_count_data.inc_failure_limit); + dprintf (6666, ("[CHP0-4] just grew %d GCs ago, grow more aggressively from %d -> %d more heaps", + gc_count_since_last_growth, step_up_int, (step_up_int * (dynamic_heap_count_data.inc_failure_count + 1)))); + step_up_int *= dynamic_heap_count_data.inc_failure_count + 1; + } } } } diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index 788cbff9f5e507..bcba2d0ca9df5d 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -4339,8 +4339,11 @@ class gc_heap // For tuning above/below target tcp. // // If we just increased the heap count and immediately need to grow again, that counts as a failure. - // The higher the failure count, the more aggressive we should grow. + // The higher the failure count, the more aggressive we should grow, but only to a point. int inc_failure_count; + const int inc_failure_limit = 2; + // After enough GCs without growth, we should stop being aggressive due to the failure count. + const int inc_failure_gcs_threshold = 40; // If we are trending up and the tcp is already close enough to target, we need this many samples // before we adjust.