Remove unneeded loop through size_pools

This function loops twice through the array of size pools. Once to set
up the pages list, and then again later on in the function to set the
allocatable_pages count.

We don't do anything with the size pools in between the invocation of
these loops that will affect the size pools, so this commit removes the
second loop and moves the allocatable_pages count update into the first
loop.
This commit is contained in:
Matt Valentine-House 2024-06-11 14:06:51 +01:00
Родитель 6b6fd16219
Коммит 1db19a2dbd
1 изменённых файлов: 9 добавлений и 14 удалений

23
gc.c
Просмотреть файл

@ -3527,6 +3527,11 @@ rb_gc_impl_objspace_alloc(void)
rb_bug("Could not preregister postponed job for GC");
}
// TODO: debug why on Windows Ruby crashes on boot when GC is on.
#ifdef _WIN32
dont_gc_on();
#endif
for (int i = 0; i < SIZE_POOL_COUNT; i++) {
rb_size_pool_t *size_pool = &size_pools[i];
@ -3534,15 +3539,14 @@ rb_gc_impl_objspace_alloc(void)
ccan_list_head_init(&SIZE_POOL_EDEN_HEAP(size_pool)->pages);
ccan_list_head_init(&SIZE_POOL_TOMB_HEAP(size_pool)->pages);
gc_params.size_pool_init_slots[i] = GC_HEAP_INIT_SLOTS;
size_pool->allocatable_pages = minimum_pages_for_size_pool(objspace, size_pool);
}
rb_darray_make(&objspace->weak_references, 0);
// TODO: debug why on Windows Ruby crashes on boot when GC is on.
#ifdef _WIN32
dont_gc_on();
#endif
#if defined(INIT_HEAP_PAGE_ALLOC_USE_MMAP)
/* Need to determine if we can use mmap at runtime. */
heap_page_alloc_use_mmap = INIT_HEAP_PAGE_ALLOC_USE_MMAP;
@ -3556,15 +3560,6 @@ rb_gc_impl_objspace_alloc(void)
objspace->rgengc.oldmalloc_increase_limit = gc_params.oldmalloc_limit_min;
#endif
/* Set size pools allocatable pages. */
for (int i = 0; i < SIZE_POOL_COUNT; i++) {
rb_size_pool_t *size_pool = &size_pools[i];
/* Set the default value of size_pool_init_slots. */
gc_params.size_pool_init_slots[i] = GC_HEAP_INIT_SLOTS;
size_pool->allocatable_pages = minimum_pages_for_size_pool(objspace, size_pool);
}
heap_pages_expand_sorted(objspace);
init_mark_stack(&objspace->mark_stack);