summaryrefslogtreecommitdiff
path: root/test/ruby/test_gc.rb
AgeCommit message (Collapse)Author
2024-02-01Backport #20157 to Ruby 3.3 (#9428)KJ Tsanaktsidis
* Fix GC.measure_total_time regression Commit 93ac7405b80cc61930d73da04441fa09af1851e1 introduced a regression where measurements would still be taken after setting GC.measure_total_time = false. Fixes [Bug #20157] * Add test case for GC.measure_total_time --------- Co-authored-by: Rian McGuire <rian@rian.id.au>
2023-12-19restore the stack pointer on finalizerKoichi Sasada
When error on finalizer, the exception will be ignored. To restart the code, we need to restore the stack pointer. fix [Bug #20042]
2023-12-18Fix flaky test test_stat_heapPeter Zhu
The test sometimes fails with: 1) Failure: TestGc#test_stat_heap [/tmp/ruby/src/trunk-repeat50/test/ruby/test_gc.rb:169]: Expected 33434403 to be <= 33434354.
2023-12-12Skip a GC test for RJITTakashi Kokubun
It randomly fails like this: https://github.com/ruby/ruby/actions/runs/7191443542/job/19586164973
2023-12-07Fix SEGV caused by `GC::Profiler.raw_data` (#9122)Soutaro Matsumoto
2023-10-18Loosen assertion for flaky weak references testPeter Zhu
2023-09-08Fix weak_references count testMatt Valentine-House
This test creates a lot of Objects held in an array, and a set of weak references to them using WeakMap. It then clears the array and frees it and asserts that all the weak references to it are also gone. This test is failing because one of the dummy objects in our weakmap is ending up on the stack, and so is being marked, even though we thought that we'd removed the only reference to it. This behaviour has changed since this commit: https://github.com/ruby/ruby/commit/5b5ae3d9e064e17e2a7d8d21d739fcc62ae1075c which rewrites `Integer#times` from C into Ruby. This change is somehow causing the last object we append to our array to consistently end up on the stack during GC. This commit fixes the specific weakmap test by using an enumerator and each, instead of `Integer#times`, and thus avoids having our last object created end up on the stack. Notes: Merged: https://github.com/ruby/ruby/pull/8402
2023-08-31Correctly calculate initial pagesPeter Zhu
The old algorithm could calculate an undercount for the initial pages due to two issues: 1. It did not take into account that some heap pages will have one less slot due to alignment. It assumed that every heap page would be able to be fully filled with slots. Pages that are unaligned with the slot size will lose one slot. The new algorithm assumes that every page will be unaligned. 2. It performed integer division, which truncates down. This means that the number of pages might not actually satisfy the number of slots. This can cause the heap to grow in `gc_sweep_finish_size_pool` after allocating all of the allocatable pages because the total number of slots would be less than the initial configured number of slots. Notes: Merged: https://github.com/ruby/ruby/pull/8333
2023-08-30Change heap init environment variable namesPeter Zhu
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`). Notes: Merged: https://github.com/ruby/ruby/pull/8335
2023-08-28Fix growth in minor GC when we have initial slotsPeter Zhu
If initial slots is set, then during a minor GC, if we have allocatable pages but the heap is mostly full, then we will set `grow_heap` to true since `total_slots` does not count allocatable pages so it will be less than `init_slots`. This can cause `allocatable_pages` to grow to much higher than desired since it will appear that the heap is mostly full. Notes: Merged: https://github.com/ruby/ruby/pull/8310
2023-08-28Remove --disable-gems in assert_in_out_errPeter Zhu
assert_in_out_err adds --disable=gems so we don't need to add --disable-gems in the args list. Notes: Merged: https://github.com/ruby/ruby/pull/8303
2023-08-25[Feature #19785] Deprecate RUBY_GC_HEAP_INIT_SLOTSPeter Zhu
This environment variable is replaced by `RUBY_GC_HEAP_INIT_SIZE_%d_SLOTS`, so it doesn't make sense to keep it. Notes: Merged: https://github.com/ruby/ruby/pull/8147
2023-08-25Expose stats about weak referencesPeter Zhu
[Feature #19783] This commit adds stats about weak references to `GC.latest_gc_info`. It adds the following two keys: - `weak_references_count`: number of weak references registered during the last GC. - `retained_weak_references_count`: number of weak references that survived the last GC. Notes: Merged: https://github.com/ruby/ruby/pull/8113
2023-08-17Move total_freed_objects to size poolPeter Zhu
This commit moves the `total_freed_objects` statistic to the size pool which allows for `total_freed_objects` key in `GC.stat_heap`. Notes: Merged: https://github.com/ruby/ruby/pull/8231
2023-08-17Move total_allocated_objects to size poolPeter Zhu
This commit moves the `total_allocated_objects` statistic to the size pool which allows for `total_allocated_objects` key in `GC.stat_heap`. Notes: Merged: https://github.com/ruby/ruby/pull/8231
2023-08-15Add stat force_incremental_marking_finish_countPeter Zhu
This commit adds key force_incremental_marking_finish_count to GC.stat_heap. This statistic returns the number of times the size pool has forced incremental marking to finish due to running out of slots.
2023-08-03Remove --disable-gems for assert_separatelyPeter Zhu
assert_separately adds --disable=gems so we don't need to add --disable-gems when calling assert_separately. Notes: Merged: https://github.com/ruby/ruby/pull/8162
2023-07-31Fix default value of global_init_slotsPeter Zhu
Not setting a value to global_init_slots causes get_envparam_size to output a broken default value.
2023-07-31Fix test_gc_parameter_init_slotsPeter Zhu
If the stack is not cleared (e.g. compiling with -O0), then `ary` could remain on the stack, which would be marked. Clear the array first to make sure all the objects can be GC'd.
2023-07-31Store initial slots per size poolPeter Zhu
This commit stores the initial slots per size pool, configured with the environment variables `RUBY_GC_HEAP_INIT_SIZE_%d_SLOTS`. This ensures that the configured initial slots remains a low bound for the number of slots in the heap, which can prevent heaps from thrashing in size. Notes: Merged: https://github.com/ruby/ruby/pull/8116
2023-07-12Add comment to testPeter Zhu
Add comment for 7299c8c0f165247853fac2fe337e7c2678e653c9.
2023-07-11Try to fix flaky GC testPeter Zhu
assert_not_nil could allocate objects which may trigger the major GC, so don't run the assertions until the major GC has been ran. Notes: Merged: https://github.com/ruby/ruby/pull/8055
2023-06-17Remove no longer used variableNobuyoshi Nakada
2023-06-02Stabilize test_latest_gc_info_need_major_byJean Boussier
Fix: ``` 1) Failure: TestGc#test_latest_gc_info_need_major_by [/home/runner/work/ruby/ruby/src/test/ruby/test_gc.rb:266]: <nil> expected to not be nil. ``` `GC.stat(:major_gc_count)` can be bumped while `GC.latest_gc_info(:need_major_by)` is still nil. Notes: Merged: https://github.com/ruby/ruby/pull/7895
2023-05-25Don't immediately promote children of old objectsPeter Zhu
[Feature #19678] References from an old object to a write barrier protected young object will not immediately promote the young object. Instead, the young object will age just like any other object, meaning that it has to survive three collections before being promoted to the old generation. References from an old object to a write barrier unprotected object will place the parent object in the remember set for marking during minor collections. This allows the child object to be reclaimed in minor collections at the cost of increased time for minor collections. On one of [Shopify's highest traffic Ruby apps, Storefront Renderer](https://shopify.engineering/how-shopify-reduced-storefront-response-times-rewrite), we saw significant improvements after deploying this feature in production. We compare the GC time and response time of web workers that have the original behaviour (non-experimental group) and this new behaviour (experimental group). We see that with this feature we spend significantly less time in the GC, 0.81x on average, 0.88x on p99, and 0.45x on p99.9. This translates to improvements in average response time (0.96x) and p99 response time (0.92x). Notes: Merged: https://github.com/ruby/ruby/pull/7821
2023-05-24Add REMEMBERED_WB_UNPROTECTED_OBJECTS_LIMIT_RATIOPeter Zhu
[Feature #19571] This commit adds the environment variable `RUBY_GC_HEAP_REMEMBERED_WB_UNPROTECTED_OBJECTS_LIMIT_RATIO` which is used to calculate the `remembered_wb_unprotected_objects_limit` using a ratio of `old_objects`. This should improve performance by reducing major GC because, in a major GC, we mark all of the old objects, so we should have more uncollectible WB unprotected objects before starting a major GC. The default has been set to 0.01 (1% of old objects). On one of [Shopify's highest traffic Ruby apps, Storefront Renderer](https://shopify.engineering/how-shopify-reduced-storefront-response-times-rewrite), we saw significant improvements after deploying this patch in production. In the graphs below, we have the `tuned` group which uses `RUBY_GC_HEAP_REMEMBERED_WB_UNPROTECTED_OBJECTS_LIMIT_RATIO=0.01` (the default value), and an `untuned` group, which turns this feature off with `RUBY_GC_HEAP_REMEMBERED_WB_UNPROTECTED_OBJECTS_LIMIT_RATIO=0`. We see that the tuned group spends significantly less time in GC, on average 0.67x of the time compared to the untuned group and 0.49x for p99. We see this improvement in GC time translate to improvements in response times. The average response time is now 0.96x of the time compared to the untuned group and 0.86x for p99. https://user-images.githubusercontent.com/15860699/229559078-e23e8ce4-5f1f-4a2f-b5ef-5769f92b8c70.png Notes: Merged: https://github.com/ruby/ruby/pull/7577
2023-02-21Add marking and sweeping time to GC.statPeter Zhu
There is a `time` key in GC.stat that gives us the total time spent in GC. However, we don't know what proportion of the time is spent between marking and sweeping. This makes it difficult to tune the GC as we're not sure where to focus our efforts on. This PR adds keys `marking_time` and `sweeping_time` to GC.stat for the time spent marking and sweeping, in milliseconds. [Feature #19437] Notes: Merged: https://github.com/ruby/ruby/pull/7304
2023-02-08Add RUBY_GC_HEAP_INIT_SIZE_%d_SLOTS to pre-init pools granularlyJean Boussier
The old RUBY_GC_HEAP_INIT_SLOTS isn't really usable anymore as it initalize all the pools by the same factor, but it's unlikely that pools will need similar sizes. In production our 40B pool is 5 to 6 times bigger than our 80B pool. Notes: Merged: https://github.com/ruby/ruby/pull/7235
2023-02-07Use more agressive RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR for GC testsJean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/7263
2022-12-30Fix test when Ruby is verbosePeter Zhu
The test added in 90a80eb0 fails if Ruby is verbose, it outputs the following line to stderr: RUBY_GC_HEAP_INIT_SLOTS=100 (default value: 10000)
2022-12-30Fix integer underflow when using HEAP_INIT_SLOTSPeter Zhu
There is an integer underflow when the environment variable RUBY_GC_HEAP_INIT_SLOTS is less than the number of slots currently in the Ruby heap. [Bug #19284] Notes: Merged: https://github.com/ruby/ruby/pull/7044
2022-12-10Expose need_major_gc via GC.latest_gc_info (#6791)Mirek Klimos
Notes: Merged-By: peterzhu2118 <peter@peterzhu.ca>
2022-11-21Add RVALUE_OVERHEAD and move ractor_belonging_idPeter Zhu
This commit adds RVALUE_OVERHEAD for storing metadata at the end of the slot. This commit moves the ractor_belonging_id in debug builds from the flags to RVALUE_OVERHEAD which frees the 16 bits in the headers for object shapes. Notes: Merged: https://github.com/ruby/ruby/pull/6763
2022-10-08Fix flaky test test_thrashing_for_young_objectsPeter Zhu
The test could be flaky when a heap has below GC_HEAP_INIT_SLOTS number of free slots because it would trigger a major GC and allocate more pages.
2022-10-07Add more debugging output to test_thrashing_for_young_objectsPeter Zhu
2022-10-06Add debug output to test_thrashing_for_young_objectsPeter Zhu
The test is failing only on trunk-repeat50@phosphorus-docker. This commit adds some debugging output to debug the failure.
2022-08-17Fix flaky test for GC thrashingPeter Zhu
GC could be in an intermediate state after creating the objects, so we should finish GC by running a minor GC. Notes: Merged: https://github.com/ruby/ruby/pull/6245
2022-08-15Add test for GC thrashing of young object creationPeter Zhu
This test will prevent performance regressions like [Bug #18929]. Notes: Merged: https://github.com/ruby/ruby/pull/6243
2022-06-08Add key force_major_gc_count to GC.stat_heapPeter Zhu
force_major_gc_count is the number of times the size pool forced major GC to run.
2022-02-03Move total_freed_pages to size poolPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/5523
2022-02-03Move total_allocated_pages to size poolPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/5523
2022-02-02Decouple GC slot sizes from RVALUEPeter Zhu
Add a new macro BASE_SLOT_SIZE that determines the slot size. For Variable Width Allocation (compiled with USE_RVARGC=1), all slot sizes are powers-of-2 multiples of BASE_SLOT_SIZE. For USE_RVARGC=0, BASE_SLOT_SIZE is set to sizeof(RVALUE). Notes: Merged: https://github.com/ruby/ruby/pull/5517
2022-01-11Use omit instead of skip without the default gems testsHiroshi SHIBATA
2022-01-04[Feature #18364] Add GC.stat_heap to get stats for memory heapsPeter Zhu
GC.stat_heap will return stats for memory heaps. This is used for the Variable Width Allocation feature. Notes: Merged: https://github.com/ruby/ruby/pull/5177
2022-01-04Use omit instead of skip: test/ruby/**/*.rbHiroshi SHIBATA
2021-11-25Revert "Add GC.stat_size_pool to get stats for a size pool"Peter Zhu
This reverts commit 6157619bb68e4307cdf065cb73d5bfcec30d042d. We'll wait for comments in the open ticket: https://bugs.ruby-lang.org/issues/18364 Notes: Merged: https://github.com/ruby/ruby/pull/5176
2021-11-25Add GC.stat_size_pool to get stats for a size poolPeter Zhu
GC.stat_size_pool will return stats for a particular size pool. This is used for the Variable Width Allocation feature. Notes: Merged: https://github.com/ruby/ruby/pull/5169
2021-07-27Run in a separated process to run finalizers certainlyNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4685 Merged-By: nobu <nobu@ruby-lang.org>
2021-07-27Try GC more during suppressing the warningNobuyoshi Nakada
2021-07-27Make GCed during suppressing the warningNobuyoshi Nakada
Consume the VM stack more, to make the target object get GCed with more probability during suppressing the warning.