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.
This commit is contained in:
parent
4de049a3f9
commit
30ef0f180b
Notes:
git
2025-05-09 07:55:26 +00:00
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user