Skip to content

Commit

Permalink
Rename size_pool -> heap
Browse files Browse the repository at this point in the history
Now that we've inlined the eden_heap into the size_pool, we should
rename the size_pool to heap. So that Ruby contains multiple heaps, with
different sized objects.

The term heap as a collection of memory pages is more in memory
management nomenclature, whereas size_pool was a name chosen out of
necessity during the development of the Variable Width Allocation
features of Ruby.

The concept of size pools was introduced in order to facilitate
different sized objects (other than the default 40 bytes). They wrapped
the eden heap and the tomb heap, and some related state, and provided a
reasonably simple way of duplicating all related concerns, to provide
multiple pools that all shared the same structure but held different
objects.

Since then various changes have happend in Ruby's memory layout:

* The concept of tomb heaps has been replaced by a global free pages list,
  with each page having it's slot size reconfigured at the point when it
  is resurrected
* the eden heap has been inlined into the size pool itself, so that now
  the size pool directly controls the free_pages list, the sweeping
  page, the compaction cursor and the other state that was previously
  being managed by the eden heap.

Now that there is no need for a heap wrapper, we should refer to the
collection of pages containing Ruby objects as a heap again rather than
a size pool
  • Loading branch information
eightbitraptor committed Oct 3, 2024
1 parent ad1dfd6 commit 5c8d8d2
Show file tree
Hide file tree
Showing 16 changed files with 442 additions and 442 deletions.
4 changes: 2 additions & 2 deletions benchmark/string_concat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ benchmark:
"#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \
"#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}" \
"#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}#{CHUNK}"
interpolation_same_size_pool: |
interpolation_same_heap: |
buffer = "#{SHORT}#{SHORT}"
interpolation_switching_size_pools: |
interpolation_switching_heaps: |
buffer = "#{SHORT}#{LONG}"
24 changes: 12 additions & 12 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ rb_gc_set_shape(VALUE obj, uint32_t shape_id)
}

uint32_t
rb_gc_rebuild_shape(VALUE obj, size_t size_pool_id)
rb_gc_rebuild_shape(VALUE obj, size_t heap_id)
{
rb_shape_t *orig_shape = rb_shape_get_shape(obj);

if (rb_shape_obj_too_complex(obj)) return (uint32_t)OBJ_TOO_COMPLEX_SHAPE_ID;

rb_shape_t *initial_shape = rb_shape_get_shape_by_id((shape_id_t)(size_pool_id + FIRST_T_OBJECT_SHAPE_ID));
rb_shape_t *initial_shape = rb_shape_get_shape_by_id((shape_id_t)(heap_id + FIRST_T_OBJECT_SHAPE_ID));
rb_shape_t *new_shape = rb_shape_traverse_from_new_root(initial_shape, orig_shape);

if (!new_shape) return 0;
Expand Down Expand Up @@ -577,7 +577,7 @@ typedef struct gc_function_map {
void (*ractor_cache_free)(void *objspace_ptr, void *cache);
void (*set_params)(void *objspace_ptr);
void (*init)(void);
size_t *(*size_pool_sizes)(void *objspace_ptr);
size_t *(*heap_sizes)(void *objspace_ptr);
// Shutdown
void (*shutdown_free_objects)(void *objspace_ptr);
// GC
Expand All @@ -594,7 +594,7 @@ typedef struct gc_function_map {
// Object allocation
VALUE (*new_obj)(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, bool wb_protected, size_t alloc_size);
size_t (*obj_slot_size)(VALUE obj);
size_t (*size_pool_id_for_size)(void *objspace_ptr, size_t size);
size_t (*heap_id_for_size)(void *objspace_ptr, size_t size);
bool (*size_allocatable_p)(size_t size);
// Malloc
void *(*malloc)(void *objspace_ptr, size_t size);
Expand Down Expand Up @@ -708,7 +708,7 @@ ruby_external_gc_init(void)
load_external_gc_func(ractor_cache_free);
load_external_gc_func(set_params);
load_external_gc_func(init);
load_external_gc_func(size_pool_sizes);
load_external_gc_func(heap_sizes);
// Shutdown
load_external_gc_func(shutdown_free_objects);
// GC
Expand All @@ -725,7 +725,7 @@ ruby_external_gc_init(void)
// Object allocation
load_external_gc_func(new_obj);
load_external_gc_func(obj_slot_size);
load_external_gc_func(size_pool_id_for_size);
load_external_gc_func(heap_id_for_size);
load_external_gc_func(size_allocatable_p);
// Malloc
load_external_gc_func(malloc);
Expand Down Expand Up @@ -787,7 +787,7 @@ ruby_external_gc_init(void)
# define rb_gc_impl_ractor_cache_free rb_gc_functions.ractor_cache_free
# define rb_gc_impl_set_params rb_gc_functions.set_params
# define rb_gc_impl_init rb_gc_functions.init
# define rb_gc_impl_size_pool_sizes rb_gc_functions.size_pool_sizes
# define rb_gc_impl_heap_sizes rb_gc_functions.heap_sizes
// Shutdown
# define rb_gc_impl_shutdown_free_objects rb_gc_functions.shutdown_free_objects
// GC
Expand All @@ -804,7 +804,7 @@ ruby_external_gc_init(void)
// Object allocation
# define rb_gc_impl_new_obj rb_gc_functions.new_obj
# define rb_gc_impl_obj_slot_size rb_gc_functions.obj_slot_size
# define rb_gc_impl_size_pool_id_for_size rb_gc_functions.size_pool_id_for_size
# define rb_gc_impl_heap_id_for_size rb_gc_functions.heap_id_for_size
# define rb_gc_impl_size_allocatable_p rb_gc_functions.size_allocatable_p
// Malloc
# define rb_gc_impl_malloc rb_gc_functions.malloc
Expand Down Expand Up @@ -3000,9 +3000,9 @@ rb_gc_prepare_heap(void)
}

size_t
rb_gc_size_pool_id_for_size(size_t size)
rb_gc_heap_id_for_size(size_t size)
{
return rb_gc_impl_size_pool_id_for_size(rb_gc_get_objspace(), size);
return rb_gc_impl_heap_id_for_size(rb_gc_get_objspace(), size);
}

bool
Expand Down Expand Up @@ -3452,9 +3452,9 @@ rb_gc_initial_stress_set(VALUE flag)
}

size_t *
rb_gc_size_pool_sizes(void)
rb_gc_heap_sizes(void)
{
return rb_gc_impl_size_pool_sizes(rb_gc_get_objspace());
return rb_gc_impl_heap_sizes(rb_gc_get_objspace());
}

VALUE
Expand Down
Loading

0 comments on commit 5c8d8d2

Please sign in to comment.