diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2023-08-21 14:13:24 -0400 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2023-08-27 09:39:29 -0400 |
| commit | b7237e3bbd36e7c520c4cbaf1f866b6dcc265a99 (patch) | |
| tree | 45a80f00e101e5460f210d6c55c0a1a9b42a825c /test/ruby | |
| parent | 5c98ee02d2ac7f20ab978be7645801adf03e4302 (diff) | |
Free all empty heap pages in Process.warmup
This commit adds `free_empty_pages` which frees all empty heap pages and
moves the number of pages freed to the allocatable pages counter. This
is used in Process.warmup to improve performance because page
invalidation from copy-on-write is slower than allocating a new page.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8257
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_process.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 38dcb8054f..095ab27f5d 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2725,4 +2725,26 @@ EOS assert_include(ObjectSpace.dump(obj), '"coderange":"7bit"') end; end + + def test_warmup_frees_pages + assert_separately([{"RUBY_GC_HEAP_FREE_SLOTS_MAX_RATIO" => "1.0"}, "-W0"], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + TIMES = 10_000 + ary = Array.new(TIMES) + TIMES.times do |i| + ary[i] = Object.new + end + ary.clear + ary = nil + + total_pages_before = GC.stat(:heap_eden_pages) + GC.stat(:heap_allocatable_pages) + + Process.warmup + + # Number of pages freed should cause equal increase in number of allocatable pages. + assert_equal(total_pages_before, GC.stat(:heap_eden_pages) + GC.stat(:heap_allocatable_pages)) + assert_equal(0, GC.stat(:heap_tomb_pages)) + assert_operator(GC.stat(:total_freed_pages), :>, 0) + end; + end end |
