ruby-changes:63784
From: Takashi <ko1@a...>
Date: Sat, 28 Nov 2020 16:27:27 +0900 (JST)
Subject: [ruby-changes:63784] 096f54428d (master): Throttle JIT compaction
https://git.ruby-lang.org/ruby.git/commit/?id=096f54428d From 096f54428d8000cccce430022784cb0e7cd31cb4 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Fri, 27 Nov 2020 23:25:31 -0800 Subject: 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. diff --git a/mjit_worker.c b/mjit_worker.c index 6432785..b8c5886 100644 --- a/mjit_worker.c +++ b/mjit_worker.c @@ -227,6 +227,8 @@ static int in_gc = 0; https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L227 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) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1321 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) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1337 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) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1365 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) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1405 // 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/