From b57ee3cb543100ef90a3affb9972eb101696b38d Mon Sep 17 00:00:00 2001 From: Peter Sollich Date: Fri, 28 Oct 2022 10:11:48 +0200 Subject: [PATCH 1/2] Fix issue with spurious unproductive full GC which led to OOM. (#77478) Problem was that a BGC was in progress when the full GC was requested by setting the last_gc_before_oom flag, and at the end of the BGC we turned off the last_gc_before_oom flag. Fix is simply not to turn off the flag in the case of BGC. --- src/coreclr/gc/gc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 5d0af20f569e69..d9276b613c2328 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -21711,7 +21711,10 @@ void gc_heap::gc1() #endif //BACKGROUND_GC #endif //MULTIPLE_HEAPS #ifdef USE_REGIONS - last_gc_before_oom = FALSE; + if (!(settings.concurrent)) + { + last_gc_before_oom = FALSE; + } #endif //USE_REGIONS } From 51608e360889c293ac6ab6780065840fce2f11bb Mon Sep 17 00:00:00 2001 From: Peter Sollich Date: Wed, 30 Nov 2022 16:21:21 +0100 Subject: [PATCH 2/2] Fix issue with last_gc_before_oom flag being reset by intervening gen 1 GC. (#78973) This is a refinement suggested by Maoni for earlier PR#77478 - the last_gc_before_oom flag should also not be reset by an intervening gen 1 GC. This was noticed by Maoni due to a customer issue with spurious OOM exceptions with .NET Core 7. --- src/coreclr/gc/gc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index d9276b613c2328..41731d28dcb568 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -21711,7 +21711,7 @@ void gc_heap::gc1() #endif //BACKGROUND_GC #endif //MULTIPLE_HEAPS #ifdef USE_REGIONS - if (!(settings.concurrent)) + if (!(settings.concurrent) && (settings.condemned_generation == max_generation)) { last_gc_before_oom = FALSE; }