mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
YJIT: Set code mem permissions in bulk
Some GC modules, notably MMTk, support parallel GC, i.e. multiple GC threads work in parallel during a GC. Currently, when two GC threads scan two iseq objects simultaneously when YJIT is enabled, both threads will attempt to borrow `CodeBlock::mem_block`, which will result in panic. This commit makes one part of the change. We now set the YJIT code memory to writable in bulk before the reference-updating phase, and reset it to executable in bulk after the reference-updating phase. Previously, YJIT lazily sets memory pages writable while updating object references embedded in JIT-compiled machine code, and sets the memory back to executable by calling `mark_all_executable`. This approach is inherently unfriendly to parallel GC because (1) it borrows `CodeBlock::mem_block`, and (2) it sets the whole `CodeBlock` as executable which races with other GC threads that are updating other iseq objects. It also has performance overhead due to the frequent invocation of system calls. We now set the permission of all the code memory in bulk before and after the reference updating phase. Multiple GC threads can now perform raw memory writes in parallel. We should also see performance improvement during moving GC because of the reduced number of `mprotect` system calls.
This commit is contained in:
parent
e288a86692
commit
51a3ea5ade
7 changed files with 84 additions and 7 deletions
|
@ -7068,6 +7068,8 @@ gc_update_references(rb_objspace_t *objspace)
|
|||
{
|
||||
objspace->flags.during_reference_updating = true;
|
||||
|
||||
rb_gc_before_updating_jit_code();
|
||||
|
||||
struct heap_page *page = NULL;
|
||||
|
||||
for (int i = 0; i < HEAP_COUNT; i++) {
|
||||
|
@ -7102,6 +7104,8 @@ gc_update_references(rb_objspace_t *objspace)
|
|||
);
|
||||
}
|
||||
|
||||
rb_gc_after_updating_jit_code();
|
||||
|
||||
objspace->flags.during_reference_updating = false;
|
||||
}
|
||||
|
||||
|
|
2
gc/gc.h
2
gc/gc.h
|
@ -94,6 +94,8 @@ MODULAR_GC_FN uint32_t rb_gc_rebuild_shape(VALUE obj, size_t heap_id);
|
|||
MODULAR_GC_FN void rb_gc_prepare_heap_process_object(VALUE obj);
|
||||
MODULAR_GC_FN bool rb_memerror_reentered(void);
|
||||
MODULAR_GC_FN bool rb_obj_id_p(VALUE);
|
||||
MODULAR_GC_FN void rb_gc_before_updating_jit_code(void);
|
||||
MODULAR_GC_FN void rb_gc_after_updating_jit_code(void);
|
||||
|
||||
#if USE_MODULAR_GC
|
||||
MODULAR_GC_FN bool rb_gc_event_hook_required_p(rb_event_flag_t event);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue