summaryrefslogtreecommitdiff
path: root/internal/gc.h
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2021-06-29 14:32:50 -0400
committerPeter Zhu <peter@peterzhu.ca>2021-07-15 11:48:52 -0400
commit4a627dbdfd1165022fa9e716ba845e937b03773d (patch)
tree2dd5c738728ffb2e64816f8a4ffefc82acdc38aa /internal/gc.h
parent119697f61e2b2b157816a8aa33aada5863959900 (diff)
downloadruby-4a627dbdfd1165022fa9e716ba845e937b03773d.tar.gz
[Bug #18014] Fix memory leak in GC when using Ractors
When a Ractor is removed, the freelist in the Ractor cache is not returned to the GC, leaving the freelist permanently lost. This commit recycles the freelist when the Ractor is destroyed, preventing a memory leak from occurring.
Diffstat (limited to 'internal/gc.h')
-rw-r--r--internal/gc.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/internal/gc.h b/internal/gc.h
index 86a2512c85..ba2882af13 100644
--- a/internal/gc.h
+++ b/internal/gc.h
@@ -73,6 +73,11 @@ struct rb_objspace; /* in vm_core.h */
#define RVARGC_PAYLOAD_INIT(obj, size) (void *)rb_rvargc_payload_init((VALUE)obj, (size_t)size)
+typedef struct ractor_newobj_cache {
+ struct RVALUE *freelist;
+ struct heap_page *using_page;
+} rb_ractor_newobj_cache_t;
+
/* gc.c */
extern VALUE *ruby_initial_gc_stress_ptr;
extern int ruby_disable_gc;
@@ -115,6 +120,7 @@ void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR
void *ruby_sized_xrealloc2(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2, 3));
void ruby_sized_xfree(void *x, size_t size);
int rb_slot_size(void);
+void rb_gc_ractor_newobj_cache_clear(rb_ractor_newobj_cache_t *newobj_cache);
RUBY_SYMBOL_EXPORT_END
MJIT_SYMBOL_EXPORT_BEGIN