Skip to content

Commit 6bcec02

Browse files
peterzhu2118jhawthorn
authored andcommitted
Change heap init environment variable names
This commit changes RUBY_GC_HEAP_INIT_SIZE_{40,80,160,320,640}_SLOTS to RUBY_GC_HEAP_{0,1,2,3,4}_INIT_SLOTS. This is easier to use because the user does not need to determine the slot sizes (which can vary between 32 and 64 bit systems). They now just use the heap names (`GC.stat_heap.keys`).
1 parent b7043fb commit 6bcec02

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11773,8 +11773,8 @@ gc_set_initial_pages(rb_objspace_t *objspace)
1177311773

1177411774
for (int i = 0; i < SIZE_POOL_COUNT; i++) {
1177511775
rb_size_pool_t *size_pool = &size_pools[i];
11776-
char env_key[sizeof("RUBY_GC_HEAP_INIT_SIZE_" "_SLOTS") + DECIMAL_SIZE_OF_BITS(sizeof(size_pool->slot_size) * CHAR_BIT)];
11777-
snprintf(env_key, sizeof(env_key), "RUBY_GC_HEAP_INIT_SIZE_%d_SLOTS", size_pool->slot_size);
11776+
char env_key[sizeof("RUBY_GC_HEAP_" "_INIT_SLOTS") + DECIMAL_SIZE_OF_BITS(sizeof(int) * CHAR_BIT)];
11777+
snprintf(env_key, sizeof(env_key), "RUBY_GC_HEAP_%d_INIT_SLOTS", i);
1177811778

1177911779
size_t size_pool_init_slots = gc_params.size_pool_init_slots[i];
1178011780
if (get_envparam_size(env_key, &size_pool_init_slots, 0)) {

man/ruby.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,9 @@ the following 11 environment variables:
552552
.It Ev RUBY_GC_HEAP_INIT_SLOTS
553553
Initial allocation slots. Applies to all slot sizes. Introduced in Ruby 2.1, default: 10000.
554554
.Pp
555-
.It Ev RUBY_GC_HEAP_INIT_SIZE_%d_SLOTS
556-
Initial allocation of slots in a specific size pool.
557-
The available size pools can be found in `GC.stat_heap`.
555+
.It Ev RUBY_GC_HEAP_%d_INIT_SLOTS
556+
Initial allocation of slots in a specific heap.
557+
The available heaps can be found in the keys of `GC.stat_heap`.
558558
Introduced in Ruby 3.3.
559559
.Pp
560560
.It Ev RUBY_GC_HEAP_FREE_SLOTS

test/ruby/test_gc.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,17 @@ def test_gc_parameter
316316
assert_normal_exit("exit", "[ruby-core:39777]", :child_env => env)
317317

318318
env = {}
319-
GC.stat_heap.each do |_, s|
320-
env["RUBY_GC_HEAP_INIT_SIZE_#{s[:slot_size]}_SLOTS"] = "200000"
319+
GC.stat_heap.keys.each do |heap|
320+
env["RUBY_GC_HEAP_#{heap}_INIT_SLOTS"] = "200000"
321321
end
322322
assert_normal_exit("exit", "", :child_env => env)
323323

324324
env["RUBY_GC_HEAP_INIT_SLOTS"] = "100000"
325325
assert_normal_exit("exit", "", :child_env => env)
326326

327327
env = {}
328-
GC.stat_heap.each do |_, s|
329-
env["RUBY_GC_HEAP_INIT_SIZE_#{s[:slot_size]}_SLOTS"] = "0"
328+
GC.stat_heap.keys.each do |heap|
329+
env["RUBY_GC_HEAP_#{heap}_INIT_SLOTS"] = "0"
330330
end
331331
assert_normal_exit("exit", "", :child_env => env)
332332

@@ -398,8 +398,8 @@ def test_gc_parameter_init_slots
398398
env = {}
399399
# Make the heap big enough to ensure the heap never needs to grow.
400400
sizes = GC.stat_heap.keys.reverse.map { |i| (i + 1) * 100_000 }
401-
GC.stat_heap.each do |i, s|
402-
env["RUBY_GC_HEAP_INIT_SIZE_#{s[:slot_size]}_SLOTS"] = sizes[i].to_s
401+
GC.stat_heap.keys.each do |heap|
402+
env["RUBY_GC_HEAP_#{heap}_INIT_SLOTS"] = sizes[heap].to_s
403403
end
404404
assert_separately([env, "-W0", "--disable-gems"], __FILE__, __LINE__, <<~RUBY)
405405
SIZES = #{sizes}

0 commit comments

Comments
 (0)