aboutsummaryrefslogtreecommitdiffstats
path: root/mjit_worker.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2020-11-27 23:25:31 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2020-11-27 23:25:32 -0800
commit096f54428d8000cccce430022784cb0e7cd31cb4 (patch)
tree0f3497c1ec536f90b41ea4cd2cbd1da03754b133 /mjit_worker.c
parent2a7e85861751fff05010099a985902f997cbf3a0 (diff)
downloadruby-096f54428d8000cccce430022784cb0e7cd31cb4.tar.gz
Throttle JIT compaction
The compilation for JIT compaction is very heavy. Triggering a second compaction to include one more new method is probably not worth it. So this triggers JIT compaction for ten more new methods after each compaction.
Diffstat (limited to 'mjit_worker.c')
-rw-r--r--mjit_worker.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/mjit_worker.c b/mjit_worker.c
index 6432785c74..b8c5886299 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -227,6 +227,8 @@ static int in_gc = 0;
static bool in_jit = false;
// The times when unload_units is requested. unload_units is called after some requests.
static int unload_requests = 0;
+// The total number of unloaded units.
+static int total_unloads = 0;
// Set to true to stop worker.
static bool stop_worker_p;
// Set to true if worker is stopped.
@@ -1319,6 +1321,7 @@ unload_units(void)
if (units_num > active_units.length) {
verbose(1, "Too many JIT code -- %d units unloaded", units_num - active_units.length);
+ total_unloads += units_num - active_units.length;
}
}
@@ -1334,8 +1337,8 @@ mjit_worker(void)
if (max_compact_size < 10) max_compact_size = 10;
// Run unload_units after it's requested `max_cache_size / 10` (default: 10) times.
- // This throttles the call to mitigate locking in unload_units.
- int unload_threshold = mjit_opts.max_cache_size / 10;
+ // This throttles the call to mitigate locking in unload_units. It also throttles JIT compaction.
+ int throttle_threshold = mjit_opts.max_cache_size / 10;
#ifndef _MSC_VER
if (pch_status == PCH_NOT_READY) {
@@ -1362,7 +1365,7 @@ mjit_worker(void)
rb_native_cond_wait(&mjit_worker_wakeup, &mjit_engine_mutex);
verbose(3, "Getting wakeup from client");
- if (unload_requests >= unload_threshold) {
+ if (unload_requests >= throttle_threshold) {
RB_DEBUG_COUNTER_INC(mjit_unload_units);
unload_units();
unload_requests = 0;
@@ -1402,7 +1405,7 @@ mjit_worker(void)
// Combine .o files to one .so and reload all jit_func to improve memory locality.
if (compact_units.length < max_compact_size
&& ((!mjit_opts.wait && unit_queue.length == 0 && active_units.length > 1)
- || active_units.length == mjit_opts.max_cache_size)) {
+ || (active_units.length == mjit_opts.max_cache_size && compact_units.length * throttle_threshold <= total_unloads))) { // throttle compaction by total_unloads
compact_all_jit_code();
}
#endif