Skip to content

Commit

Permalink
[Bug #18929] Fix heap creation thrashing in GC
Browse files Browse the repository at this point in the history
Before this commit, if we don't have enough slots after sweeping but
had pages on the tomb heap, then the GC would frequently allocate and
deallocate pages. This is because after sweeping it would set
allocatable pages (since there were not enough slots) but free the
pages on the tomb heap.

This commit reuses pages on the tomb heap if there's not enough slots
after sweeping.
  • Loading branch information
peterzhu2118 committed Jul 21, 2022
1 parent 804b073 commit cdbb9b8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5810,6 +5810,19 @@ gc_sweep_finish_size_pool(rb_objspace_t *objspace, rb_size_pool_t *size_pool)
min_free_slots = gc_params.heap_init_slots;
}

/* If we don't have enough slots and we have pages on the tomb heap, move
* pages from the tomb heap to the eden heap. This may prevent page
* creation thrashing (frequently allocating and deallocting pages) and
* GC thrashing (running GC more frequently than required). */
struct heap_page *resurrected_page;
while (swept_slots < min_free_slots &&
(resurrected_page = heap_page_resurrect(objspace, size_pool))) {
swept_slots += resurrected_page->free_slots;

heap_add_page(objspace, size_pool, heap, resurrected_page);
heap_add_freepage(heap, resurrected_page);
}

if (swept_slots < min_free_slots) {
bool grow_heap = is_full_marking(objspace);

Expand Down

0 comments on commit cdbb9b8

Please sign in to comment.