diff options
author | John Hawthorn <[email protected]> | 2025-05-08 22:35:59 -0700 |
---|---|---|
committer | John Hawthorn <[email protected]> | 2025-05-09 00:55:14 -0700 |
commit | 30ef0f180b396314521d1309e7732ce921cd2fab (patch) | |
tree | 3c4e3f8078a051477917260876cdc7270d9441f0 /gc/default/default.c | |
parent | 4de049a3f9709ab8b0b192c40e83b910b80d6de3 (diff) |
Fix allocation count when forking with Ractors
After fork we reset to single ractor mode (which IMO we shouldn't do,
but it requires more work to fix) and so we need to add the pending
object counts back to the main heap.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13286
Diffstat (limited to 'gc/default/default.c')
-rw-r--r-- | gc/default/default.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/gc/default/default.c b/gc/default/default.c index 157873bc1c..b3887a5c28 100644 --- a/gc/default/default.c +++ b/gc/default/default.c @@ -3659,13 +3659,19 @@ static int compare_pinned_slots(const void *left, const void *right, void *d); static void gc_ractor_newobj_cache_clear(void *c, void *data) { + rb_objspace_t *objspace = rb_gc_get_objspace(); rb_ractor_newobj_cache_t *newobj_cache = c; newobj_cache->incremental_mark_step_allocated_slots = 0; for (size_t heap_idx = 0; heap_idx < HEAP_COUNT; heap_idx++) { + rb_ractor_newobj_heap_cache_t *cache = &newobj_cache->heap_caches[heap_idx]; + rb_heap_t *heap = &heaps[heap_idx]; + RUBY_ATOMIC_SIZE_ADD(heap->total_allocated_objects, cache->allocated_objects_count); + cache->allocated_objects_count = 0; + struct heap_page *page = cache->using_page; struct free_slot *freelist = cache->freelist; RUBY_DEBUG_LOG("ractor using_page:%p freelist:%p", (void *)page, (void *)freelist); @@ -6161,8 +6167,6 @@ rb_gc_impl_ractor_cache_free(void *objspace_ptr, void *cache) for (size_t heap_idx = 0; heap_idx < HEAP_COUNT; heap_idx++) { rb_heap_t *heap = &heaps[heap_idx]; rb_ractor_newobj_heap_cache_t *heap_cache = &newobj_cache->heap_caches[heap_idx]; - RUBY_ATOMIC_SIZE_ADD(heap->total_allocated_objects, heap_cache->allocated_objects_count); - heap_cache->allocated_objects_count = 0; } gc_ractor_newobj_cache_clear(cache, NULL); @@ -9220,7 +9224,9 @@ gc_malloc_allocations(VALUE self) #endif void rb_gc_impl_before_fork(void *objspace_ptr) { /* no-op */ } -void rb_gc_impl_after_fork(void *objspace_ptr, rb_pid_t pid) { /* no-op */ } +void rb_gc_impl_after_fork(void *objspace_ptr, rb_pid_t pid) { + rb_gc_ractor_newobj_cache_foreach(gc_ractor_newobj_cache_clear, NULL); +} VALUE rb_ident_hash_new_with_size(st_index_t size); |