summaryrefslogtreecommitdiff
path: root/yjit/src/stats.rs
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2022-06-14 10:23:13 -0400
committerGitHub <noreply@github.com>2022-06-14 10:23:13 -0400
commit9f09397bfe6762bf19ef47b2f60988e49b80560d (patch)
tree2be526b0bc34af44937eab15f31f131c85df6b03 /yjit/src/stats.rs
parent9b9cc8ad34fdecdede439f14c027c5eefef5541e (diff)
YJIT: On-demand executable memory allocation; faster boot (#5944)
This commit makes YJIT allocate memory for generated code gradually as needed. Previously, YJIT allocates all the memory it needs on boot in one go, leading to higher than necessary resident set size (RSS) and time spent on boot initializing the memory with a large memset(). Users should no longer need to search for a magic number to pass to `--yjit-exec-mem` since physical memory consumption should now more accurately reflect the requirement of the workload. YJIT now reserves a range of addresses on boot. This region start out with no access permission at all so buggy attempts to jump to the region crashes like before this change. To get this hardening at finer granularity than the page size, we fill each page with trapping instructions when we first allocate physical memory for the page. Most of the time applications don't need 256 MiB of executable code, so allocating on-demand ends up doing less total work than before. Case in point, a simple `ruby --yjit-call-threshold=1 -eitself` takes about half as long after this change. In terms of memory consumption, here is a table to give a rough summary of the impact: | Peak RSS in MiB | -eitself example | railsbench once | | :-------------: | ---------------: | --------------: | | before | 265 | 377 | | after | 11 | 143 | | no YJIT | 10 | 101 | A new module is introduced to handle allocation bookkeeping. `CodePtr` is moved into the module since it has a close relationship with the new `VirtualMemory` struct. This new interface has a slightly smaller surface than before in that marking a region as writable is no longer a public operation.
Notes
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'yjit/src/stats.rs')
-rw-r--r--yjit/src/stats.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/yjit/src/stats.rs b/yjit/src/stats.rs
index e129cc2811..6bad8db7e7 100644
--- a/yjit/src/stats.rs
+++ b/yjit/src/stats.rs
@@ -141,7 +141,7 @@ macro_rules! incr_counter {
($counter_name:ident) => {
#[allow(unused_unsafe)]
{
- unsafe { COUNTERS.$counter_name += 1 }
+ unsafe { $crate::stats::COUNTERS.$counter_name += 1 }
}
};
}
@@ -244,6 +244,10 @@ make_counters! {
gbpp_block_param_modified,
gbpp_block_handler_not_iseq,
+
+ // Currently, it's out of the ordinary (might be impossible) for YJIT to leave gaps in
+ // executable memory, so this should be 0.
+ exec_mem_non_bump_alloc,
}
//===========================================================================