Граф коммитов

1869 Коммитов

Автор SHA1 Сообщение Дата
Koichi Sasada 02d9524cda separate rb_ractor_pub from rb_ractor_t
separate some fields from rb_ractor_t to rb_ractor_pub and put it
at the beggining of rb_ractor_t and declare it in vm_core.h so
vm_core.h can access rb_ractor_pub fields.

Now rb_ec_ractor_hooks() is a complete inline function and no
MJIT related issue.
2020-12-22 00:03:00 +09:00
Koichi Sasada 74ab2c3b46 finalizing should be checked before VM lock 2020-12-18 17:59:26 +09:00
Nobuyoshi Nakada 7d32bf7853
Removed a moved local variable 2020-12-18 17:56:08 +09:00
Koichi Sasada 61236770e6 need to sync gc_finalize_deferred
gc_finalize_deferred() runs finalizers and it accesses objspace,
so it need to sync.
2020-12-18 17:50:01 +09:00
Nobuyoshi Nakada 75416b8628 Removed old GC.stat keys deprecated since 2.2 2020-12-18 16:27:43 +09:00
Nobuyoshi Nakada 763d5f9c6b Removed old GC tuning environment variables deprecated since 2.1 2020-12-18 16:27:43 +09:00
Koichi Sasada cfa124ef05 acquire VM lock on gc_verify_internal_consistency()
There is a case to call this function without VM lock acquiring.
2020-12-18 14:16:06 +09:00
Koichi Sasada 29e42b8bfd add explicit check
To debug this issue:
https://rubyci.org/logs/rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/log/20201217T220004Z.fail.html.gz
2020-12-18 08:26:25 +09:00
Koichi Sasada 6538c89f1c gc_verify_internal_consistency() needs barrier
gc_verify_internal_consistency() accesses all slots (objects) so
all ractors should stop before starting this function.
2020-12-18 01:20:02 +09:00
Koichi Sasada da3438a504 sync obj_to_id_tbl
objspace->obj_to_id_tbl is a shared table so we need to synchronize
it to access.
2020-12-17 18:13:40 +09:00
Koichi Sasada 7f11c8086a reduce barrier counts for GC events
mark needs barrier (stop other ractors), but other GC events don't need
barriers (maybe...).
2020-12-17 18:13:26 +09:00
Koichi Sasada 99b9145380 relax synchronization on WB
Current synchronization is too much on write barriers.
2020-12-17 17:37:52 +09:00
Koichi Sasada c42948d784 add debug counters for gc start events 2020-12-17 17:03:05 +09:00
Koichi Sasada 93ba3ac036 RGENGC_PROFILE=0
Enabled this flag, maybe accidentally.
2020-12-17 03:46:44 +09:00
Nobuyoshi Nakada 289d42c932
Removed unneeded cast and use the real name 2020-12-15 23:43:08 +09:00
Koichi Sasada 974e89ae07 revert da3bca513f
It seems introduce critical problems. Now I could not find
out the issue.

http://ci.rvm.jp/results/trunk-test@ruby-sky1/3286048
2020-12-11 09:54:34 +09:00
Koichi Sasada 72f1c43584 ObjectSpace._id2ref should not support unshareable
ObjectSpace._id2ref(id) can return any objects even if they are
unshareable, so this patch raises RangeError if it runs on multi-ractor
mode and the found object is unshareable.
2020-12-10 18:27:44 +09:00
Nobuyoshi Nakada 142f154a0a
Unpoison freelist to chain 2020-12-10 18:16:22 +09:00
Koichi Sasada da3bca513f cache free pages per ractor
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.
2020-12-10 13:05:43 +09:00
Koichi Sasada 554c094977 set min/maximum free slots relative to ractor cnt
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).
2020-12-10 13:05:43 +09:00
Koichi Sasada eafe000af3 lazy sweep tries to collect 2048 slots
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.
2020-12-10 13:05:43 +09:00
Koichi Sasada 45b29754cf need the lock for debug checking.
Checking code (RGENGC_CHECK_MODE > 0) need a VM lock because it
refers objspace.
2020-12-09 15:15:46 +09:00
Koichi Sasada 1ba05f5b2d need more lock in finalize_list()
Some data should be accessed in parallel so they should be protected
by the lock.
2020-12-07 13:32:50 +09:00
Koichi Sasada 0ebf6bd0a2 RB_VM_LOCK_ENTER_NO_BARRIER
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-07 11:27:25 +09:00
Koichi Sasada 8dd03e5cf0 skip assertion on multi-ractor
This assertion is not considerred on multi-ractor mdoe.
2020-12-07 11:10:18 +09:00
Koichi Sasada 59ddb88da6 RB_EC_NEWOBJ_OF
NEWOBJ with current ec.
2020-12-07 08:28:36 +09:00
Koichi Sasada 91d99025e4 per-ractor object allocation
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).
2020-12-07 08:28:36 +09:00
Aaron Patterson a9d773a288
Revert "Skip repeated scan of object during compaction"
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 88bb1a672c.
2020-12-03 17:19:15 -08:00
Peter Zhu 88bb1a672c Skip repeated scan of object during compaction 2020-12-03 11:58:05 -08:00
Aaron Patterson 51268be7fe When allocating new pages, add them to the end of the linked list
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
2020-12-02 10:47:10 -08:00
Aaron Patterson 0bebea985d Incremental sweeping should not require page allocation
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>
2020-12-02 08:23:31 -08:00
Koichi Sasada d2cfb5228a show with sharing info 2020-12-01 11:10:19 +09:00
Koichi Sasada 67693d8d80 ractor local storage C-API
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.
2020-12-01 09:39:30 +09:00
Koichi Sasada 77936ad679 support SIGSEGV/BUS while read_barrier_handler()
read_barrier_handler() can cause SIGSEGV/BUS so it should show
the errors.
2020-11-30 05:10:48 +09:00
Takashi Kokubun 69e77e81dc
Run rb_print_backtrace first on ruby_on_ci
Unfortunately we couldn't see a C backtrace with the previous commit
http://ci.rvm.jp/results/trunk-random2@phosphorus-docker/3272697.
2020-11-26 20:37:47 -08:00
Takashi Kokubun 4dbf6f1e51
Call rb_bug_without_die on CI
when GC.compact's SEGV handler is installed
2020-11-26 20:09:57 -08:00
Aaron Patterson c32218de1b
Disable auto compaction on platforms that can't support it
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-25 11:29:14 -08:00
Aaron Patterson fed67fe6b2
Revert "Disable auto compaction on platforms that can't support it"
This reverts commit 63ad55cd88.

Revert "Disable read barrier on explicit compaction request"

This reverts commit 490b57783d.
2020-11-24 21:30:13 -08:00
Aaron Patterson 63ad55cd88
Disable auto compaction on platforms that can't support it
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-24 14:48:19 -08:00
Aaron Patterson 87d21ee996
add HEAP_PAGE_SIZE to internal constants 2020-11-24 13:30:26 -08:00
Aaron Patterson 490b57783d Disable read barrier on explicit compaction request
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"
2020-11-24 12:38:05 -08:00
Koichi Sasada 5e3259ea74 fix public interface
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)
2020-11-18 03:52:41 +09:00
Aaron Patterson 6d17c9fa5d
gc_rest can change the total pages, so we need to do that first 2020-11-05 12:28:50 -08:00
Aaron Patterson d8da5c1983
add asserts to find crash 2020-11-05 12:27:09 -08:00
Aaron Patterson ab5f2fa4fb
Refactor verification method
Combine everything in to one C function
2020-11-05 11:13:04 -08:00
Aaron Patterson 68a3a2d90f
take VM lock when mutating the heap 2020-11-05 08:51:40 -08:00
Aaron Patterson a8581ce673 ensure T_OBJECT objects have internals initialized 2020-11-04 14:40:50 -08:00
Aaron Patterson 67b2c21c32
Add `GC.auto_compact= true/false` and `GC.auto_compact`
* `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-02 14:42:48 -08:00
Koichi Sasada db7a3b63ba suppport Ractor.send(move: true) for more deta
This patch allows to move more data types.
2020-11-02 01:37:28 +09:00
Aaron Patterson d8b0f1f7a8
Objects are born embedded, so we don't need to check ivpr
It's not necessary to check ivpt because objects are allocated as
"embedded" by default
2020-10-28 16:11:30 -07:00