summaryrefslogtreecommitdiff
path: root/yjit/src/cruby.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/cruby.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/cruby.rs')
-rw-r--r--yjit/src/cruby.rs3
1 files changed, 0 insertions, 3 deletions
diff --git a/yjit/src/cruby.rs b/yjit/src/cruby.rs
index da9a84a160..51ba9c1531 100644
--- a/yjit/src/cruby.rs
+++ b/yjit/src/cruby.rs
@@ -111,9 +111,6 @@ pub use autogened::*;
// and textually included in this file
#[cfg_attr(test, allow(unused))] // We don't link against C code when testing
extern "C" {
- #[link_name = "rb_yjit_alloc_exec_mem"] // we can rename functions with this attribute
- pub fn alloc_exec_mem(mem_size: u32) -> *mut u8;
-
#[link_name = "rb_insn_name"]
pub fn raw_insn_name(insn: VALUE) -> *const c_char;