From fabc460880fbabd18369a7ef8715538c83ebffc9 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 14 Apr 2018 06:18:49 +0900 Subject: Invoke full GC when too many objects allocated during GC; fix #3998 When object allocation rate during incremental GC is too high, the `gc->majorgc_old_threshold` becomes too big. This means major GC start slower and old objects stay longer (and consume too much memory). --- src/gc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index 6f3aef8a7..631f7b910 100644 --- a/src/gc.c +++ b/src/gc.c @@ -345,6 +345,7 @@ add_heap(mrb_state *mrb, mrb_gc *gc) #define DEFAULT_GC_INTERVAL_RATIO 200 #define DEFAULT_GC_STEP_RATIO 200 #define MAJOR_GC_INC_RATIO 120 +#define MAJOR_GC_TOOMANY 10000 #define is_generational(gc) ((gc)->generational) #define is_major_gc(gc) (is_generational(gc) && (gc)->full) #define is_minor_gc(gc) (is_generational(gc) && !(gc)->full) @@ -1209,7 +1210,13 @@ mrb_incremental_gc(mrb_state *mrb) } if (is_major_gc(gc)) { - gc->majorgc_old_threshold = gc->live_after_mark/100 * MAJOR_GC_INC_RATIO; + size_t threshold = gc->live_after_mark/100 * MAJOR_GC_INC_RATIO; + + if (threshold > MAJOR_GC_TOOMANY) { + mrb_full_gc(mrb); + threshold = gc->live_after_mark/100 * MAJOR_GC_INC_RATIO; + } + gc->majorgc_old_threshold = threshold; gc->full = FALSE; } else if (is_minor_gc(gc)) { -- cgit v1.2.3