Skip to content

Commit

Permalink
Force page creation, if major GC doesn't free.
Browse files Browse the repository at this point in the history
[Bug #20762]

Prior to 51bd816 this conditional would
call `heap_increment` which would always create a new page if one was
unavailable to be resurrected.

This new code uses heap_page_allocate_and_initialize which does nothing
if there are no allocatable slots left in the heap.

The reason we've hit this bug is because we've tried to allocate, run a
major GC, and been unable to free or resurrect a page. In this instance
we should instead use heap_page_allocate_and_initialize_force to force
creation of another page.
  • Loading branch information
eightbitraptor committed Sep 27, 2024
1 parent 7f83bd3 commit 9bcf039
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions gc/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -2164,9 +2164,11 @@ heap_prepare(rb_objspace_t *objspace, rb_size_pool_t *size_pool, rb_heap_t *heap
/* Do steps of incremental marking or lazy sweeping. */
gc_continue(objspace, size_pool, heap);

if (heap->free_pages == NULL &&
!heap_page_allocate_and_initialize(objspace, size_pool, heap)) {
rb_bug("cannot create a new page after major GC");
if (heap->free_pages == NULL) {
heap_page_allocate_and_initialize_force(objspace, size_pool, heap);
if (heap->free_pages == NULL) {
rb_bug("cannot create a new page after major GC");
}
}
}
}
Expand Down

0 comments on commit 9bcf039

Please sign in to comment.