summaryrefslogtreecommitdiff
path: root/gc.c
AgeCommit message (Collapse)Author
2020-12-10cache free pages per ractorKoichi Sasada
Per ractor method cache (GH-#3842) only cached 1 page and this patch caches several pages to keep at least 512 free slots if available. If you increase the number of cached free slots, all cached slots will be collected when the GC is invoked. Notes: Merged: https://github.com/ruby/ruby/pull/3875
2020-12-10set min/maximum free slots relative to ractor cntKoichi Sasada
A program with multiple ractors can consume more objects per unit time, so this patch set minimum/maximum free_slots to relative to ractors count (upto 8). Notes: Merged: https://github.com/ruby/ruby/pull/3875
2020-12-10lazy sweep tries to collect 2048 slotsKoichi Sasada
Lazy sweep tries to collect free (unused) slots incrementally, and it only collect a few pages. This patch makes lazy sweep collects more objects (at least 2048 objects) and GC overhead of multi-ractor execution will be reduced. Notes: Merged: https://github.com/ruby/ruby/pull/3875
2020-12-09need the lock for debug checking.Koichi Sasada
Checking code (RGENGC_CHECK_MODE > 0) need a VM lock because it refers objspace.
2020-12-07need more lock in finalize_list()Koichi Sasada
Some data should be accessed in parallel so they should be protected by the lock.
2020-12-07RB_VM_LOCK_ENTER_NO_BARRIERKoichi Sasada
Write barrier requires VM lock because it accesses VM global bitmap but RB_VM_LOCK_ENTER() can invoke GC because another ractor can wait to invoke GC and RB_VM_LOCK_ENTER() is barrier point. This means that before protecting by a write barrier, GC can invoke. To prevent such situation, RB_VM_LOCK_ENTER_NO_BARRIER() is introduced. This lock primitive does not become GC barrier points.
2020-12-07skip assertion on multi-ractorKoichi Sasada
This assertion is not considerred on multi-ractor mdoe.
2020-12-07RB_EC_NEWOBJ_OFKoichi Sasada
NEWOBJ with current ec. Notes: Merged: https://github.com/ruby/ruby/pull/3842
2020-12-07per-ractor object allocationKoichi Sasada
Now object allocation requires VM global lock to synchronize objspace. However, of course, it introduces huge overhead. This patch caches some slots (in a page) by each ractor and use cached slots for object allocation. If there is no cached slots, acquire the global lock and get new cached slots, or start GC (marking or lazy sweeping). Notes: Merged: https://github.com/ruby/ruby/pull/3842
2020-12-03Revert "Skip repeated scan of object during compaction"Aaron Patterson
This seems to be breaking the build for some reason. This command can reproduce it: `make yes-test-all TESTS=--repeat-count=20` This reverts commit 88bb1a672c49746972f4b15410fa92e9d237c43d.
2020-12-03Skip repeated scan of object during compactionPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/3843
2020-12-02When allocating new pages, add them to the end of the linked listAaron Patterson
When we allocate new pages, allocate them on the end of the linked list. Then when we compact we can move things to the head of the list Notes: Merged: https://github.com/ruby/ruby/pull/3814
2020-12-02Incremental sweeping should not require page allocationAaron Patterson
Incremental sweeping should sweep until we find a slot for objects to use. `heap_increment` was adding a page to the heap even though we would sweep immediately after. Co-authored-by: John Hawthorn <john@hawthorn.email> Notes: Merged: https://github.com/ruby/ruby/pull/3837
2020-12-01show with sharing infoKoichi Sasada
2020-12-01ractor local storage C-APIKoichi Sasada
To manage ractor-local data for C extension, the following APIs are defined. * rb_ractor_local_storage_value_newkey * rb_ractor_local_storage_value * rb_ractor_local_storage_value_set * rb_ractor_local_storage_ptr_newkey * rb_ractor_local_storage_ptr * rb_ractor_local_storage_ptr_set At first, you need to create a key of storage by rb_ractor_local_(value|ptr)_newkey(). For ptr storage, it accepts the type of storage, how to mark and how to free with ractor's lifetime. rb_ractor_local_storage_value/set are used to access a VALUE and rb_ractor_local_storage_ptr/set are used to access a pointer. random.c uses this API. Notes: Merged: https://github.com/ruby/ruby/pull/3822
2020-11-30support SIGSEGV/BUS while read_barrier_handler()Koichi Sasada
read_barrier_handler() can cause SIGSEGV/BUS so it should show the errors.
2020-11-26Run rb_print_backtrace first on ruby_on_ciTakashi Kokubun
Unfortunately we couldn't see a C backtrace with the previous commit http://ci.rvm.jp/results/trunk-random2@phosphorus-docker/3272697.
2020-11-26Call rb_bug_without_die on CITakashi Kokubun
when GC.compact's SEGV handler is installed
2020-11-25Disable auto compaction on platforms that can't support itAaron Patterson
Both explicit compaction routines (gc_compact and the verify references form) need to clear the heap before executing compaction. Otherwise some objects may not be alive, and we'll need the read barrier. The heap must only contain *live* objects if we want to disable the read barrier during explicit compaction. The previous commit was missing the "clear the heap" phase from the "verify references" explicit compaction function. Fixes [Bug #17306]
2020-11-24Revert "Disable auto compaction on platforms that can't support it"Aaron Patterson
This reverts commit 63ad55cd882e4010fe313d271af006a430b5ffa8. Revert "Disable read barrier on explicit compaction request" This reverts commit 490b57783d80f0c5f7882c66d9fb6aa02713c9a5.
2020-11-24Disable auto compaction on platforms that can't support itAaron Patterson
Auto Compaction uses mprotect to implement a read barrier. mprotect can only work on regions of memory that are a multiple of the OS page size. Ruby's pages are a multiple of 4kb, but some platforms (like ppc64le) don't have 4kb page sizes. This commit disables the features on those platforms. Fixes [Bug #17306]
2020-11-24add HEAP_PAGE_SIZE to internal constantsAaron Patterson
2020-11-24Disable read barrier on explicit compaction requestAaron Patterson
We don't need a read barrier when the user calls `GC.compact` because we don't allow allocations during GC, and all references should be "live" Notes: Merged: https://github.com/ruby/ruby/pull/3809
2020-11-18fix public interfaceKoichi Sasada
To make some kind of Ractor related extensions, some functions should be exposed. * include/ruby/thread_native.h * rb_native_mutex_* * rb_native_cond_* * include/ruby/ractor.h * RB_OBJ_SHAREABLE_P(obj) * rb_ractor_shareable_p(obj) * rb_ractor_std*() * rb_cRactor and rm ractor_pub.h and rename srcdir/ractor.h to srcdir/ractor_core.h (to avoid conflict with include/ruby/ractor.h) Notes: Merged: https://github.com/ruby/ruby/pull/3775
2020-11-05gc_rest can change the total pages, so we need to do that firstAaron Patterson
2020-11-05add asserts to find crashAaron Patterson
2020-11-05Refactor verification methodAaron Patterson
Combine everything in to one C function
2020-11-05take VM lock when mutating the heapAaron Patterson
2020-11-04ensure T_OBJECT objects have internals initializedAaron Patterson
Notes: Merged: https://github.com/ruby/ruby/pull/3734
2020-11-02Add `GC.auto_compact= true/false` and `GC.auto_compact`Aaron Patterson
* `GC.auto_compact=`, `GC.auto_compact` can be used to control when compaction runs. Setting `auto_compact=` to true will cause compaction to occurr duing major collections. At the moment, compaction adds significant overhead to major collections, so please test first! [Feature #17176]
2020-11-02suppport Ractor.send(move: true) for more detaKoichi Sasada
This patch allows to move more data types. Notes: Merged: https://github.com/ruby/ruby/pull/3727
2020-10-28Objects are born embedded, so we don't need to check ivprAaron Patterson
It's not necessary to check ivpt because objects are allocated as "embedded" by default
2020-10-28Remove another unnecessary testAaron Patterson
Same as 5be42c1ef4f7ed0a8004cad750a9ce61869bd768
2020-10-28Remove unnecessary conditionalAaron Patterson
As of 0b81a484f3453082d28a48968a063fd907daa5b5, `ROBJECT_IVPTR` will always return a value, so we don't need to test whether or not we got one. T_OBJECTs always come to life as embedded objects, so they will return an ivptr, and when they become "unembedded" they will have an ivptr at that point too
2020-10-28If an object isn't embedded it will have an ivptrAaron Patterson
We don't need to check the existence if an ivptr because non-embedded objects will always have one
2020-10-22Use a lock level for a less granular lock.Aaron Patterson
We are seeing an error where code that is generated with MJIT contains references to objects that have been moved. I believe this is due to a race condition in the compaction function. `gc_compact` has two steps: 1. Run a full GC to pin objects 2. Compact / update references Step one is executed with `garbage_collect`. `garbage_collect` calls `gc_enter` / `gc_exit`, these functions acquire a JIT lock and release a JIT lock. So a lock is held for the duration of step 1. Step two is executed by `gc_compact_after_gc`. It also holds a JIT lock. I believe the problem is that the JIT is free to execute between step 1 and step 2. It copies call cache values, but doesn't pin them when it copies them. So the compactor thinks it's OK to move the call cache even though it is not safe. We need to hold a lock for the duration of `garbage_collect` *and* `gc_compact_after_gc`. This patch introduces a lock level which increments and decrements. The compaction function can increment and decrement the lock level and prevent MJIT from executing during both steps. Notes: Merged: https://github.com/ruby/ruby/pull/3683
2020-10-21Ractor-safe rb_objspace_reachable_objects_fromKoichi Sasada
rb_objspace_reachable_objects_from(obj) is used to traverse all reachable objects from obj. This function modify objspace but it is not ractor-safe (thread-safe). This patch fix the problem. Strategy: (1) call GC mark process during_gc (2) call Ractor-local custom mark func when !during_gc Notes: Merged: https://github.com/ruby/ruby/pull/3680
2020-10-20ObjectSpace.each_object with RactorsKoichi Sasada
Unshareable objects should not be touched from multiple ractors so ObjectSpace.each_object should be restricted. On multi-ractor mode, ObjectSpace.each_object only iterates shareable objects. [Feature #17270] Notes: Merged: https://github.com/ruby/ruby/pull/3672
2020-10-17sync RClass::ext::iv_index_tblKoichi Sasada
iv_index_tbl manages instance variable indexes (ID -> index). This data structure should be synchronized with other ractors so introduce some VM locks. This patch also introduced atomic ivar cache used by set/getinlinecache instructions. To make updating ivar cache (IVC), we changed iv_index_tbl data structure to manage (ID -> entry) and an entry points serial and index. IVC points to this entry so that cache update becomes atomically. Notes: Merged: https://github.com/ruby/ruby/pull/3662
2020-10-03add NULL check.Koichi Sasada
DATA_PTR(ractor) can be NULL just after creation.
2020-09-28Fix ASAN and don't check SPECIAL_CONST_PAaron Patterson
Heap allocated objects are never special constants. Since we're walking the heap, we know none of these objects can be special. Also, adding the object to the freelist will poison the object, so we can't check that the type is T_NONE after poison.
2020-09-28Fix ASAN errors when updating call cacheAaron Patterson
Invalidating call cache walks the heap, so we need to take care to un-poison objects when examining them
2020-09-24sync rb_gc_register_mark_object()Koichi Sasada
rb_vm_t::mark_object_ary is global resource so we need to synchronize to access it.
2020-09-22Add a comment about why we're checking the finalizer tableAaron Patterson
2020-09-22Revert "Pin values in the finalizer table"Aaron Patterson
If an object has a finalizer flag set on it, prevent it from moving. This partially reverts commit 1a9dd31910699c7cd69f2a84c94af20eacd5875c.
2020-09-20Update heap_pages_himem after freeing pagesPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/3461
2020-09-19strip trailing spaces [ci skip]Nobuyoshi Nakada
2020-09-18Pin values in the finalizer tableAaron Patterson
When finalizers run (in `rb_objspace_call_finalizer`) the table is copied to a linked list that is not managed by the GC. If compaction runs, the references in the linked list can go bad. Finalizer table shouldn't be used frequently, so lets pin references in the table so that the linked list in `rb_objspace_call_finalizer` is safe. Notes: Merged: https://github.com/ruby/ruby/pull/3556
2020-09-18rb_obj_info() shows more info for T_SYMBOLKoichi Sasada
Notes: Merged: https://github.com/ruby/ruby/pull/3548
2020-09-16Warn on a finalizer that captures the object to be finalizedChris Seaton
Also improve specs and documentation for finalizers and more clearly recommend a safe code pattern to use them. Notes: Merged: https://github.com/ruby/ruby/pull/3444