Skip to content

Commit a8009c9

Browse files
Allow flex in heap growth threshold
Add a 7/8 multiplier to the min_free_slots checks in gc_sweep_finish_heap and gc_marks_finish, allowing heaps to be up to ~12.5% below the free slots target without triggering a major GC or forced growth. With 12 heaps instead of 5, each heap independently hitting the exact threshold would cause excessive memory growth. The slack prevents cascading growth decisions while still ensuring heaps stay close to their target occupancy.
1 parent 5c968c5 commit a8009c9

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

gc/default/default.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,7 +3870,8 @@ gc_sweep_finish_heap(rb_objspace_t *objspace, rb_heap_t *heap)
38703870
heap_allocatable_bytes_expand(objspace, heap, swept_slots, heap->total_slots, heap->slot_size);
38713871
}
38723872
}
3873-
else if (objspace->heap_pages.allocatable_bytes < (min_free_slots - swept_slots) * heap->slot_size) {
3873+
else if (swept_slots < min_free_slots * 7 / 8 &&
3874+
objspace->heap_pages.allocatable_bytes < (min_free_slots * 7 / 8 - swept_slots) * heap->slot_size) {
38743875
gc_needs_major_flags |= GPR_FLAG_MAJOR_BY_NOFREE;
38753876
heap->force_major_gc_count++;
38763877
}
@@ -5500,7 +5501,7 @@ gc_marks_finish(rb_objspace_t *objspace)
55005501
}
55015502

55025503
if (objspace->heap_pages.allocatable_bytes == 0 && sweep_slots < min_free_slots) {
5503-
if (!full_marking) {
5504+
if (!full_marking && sweep_slots < min_free_slots * 7 / 8) {
55045505
if (objspace->profile.count - objspace->rgengc.last_major_gc < RVALUE_OLD_AGE) {
55055506
full_marking = TRUE;
55065507
}

0 commit comments

Comments
 (0)