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).
parent 3b273243
......@@ -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)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment