feat(fspy): route preload allocations through a lock-free global allocator - #599
feat(fspy): route preload allocations through a lock-free global allocator#599wan9chi wants to merge 1 commit into
Conversation
…cator Alternative to #596 for the same problem: the preload library runs inside libc calls that programs may make from a signal handler or from the child of fork() in a multithreaded process, where libc malloc's lock may be held by a thread that is paused or gone. Where #596 hands each intercepted call its own bump arena, and converts call sites one at a time, this installs one lock-free allocator as the preload cdylib's #[global_allocator]. Every Rust allocation in the library is covered at once, with no call-site changes: power-of-two size classes carve blocks out of 1 MiB mmap'd slabs, freed blocks recycle through per-class Treiber free lists made ABA-resistant by a 40-bit generation tag, and larger or over-aligned requests map directly. Includes the same access-relative benchmark suite as #596 so the two approaches can be compared on identical workloads. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
fspy benchmarklinuxmacoswindows |
Comparison with #596Both PRs now have benchmark runs against the same base (
Reading:
RecommendationLand #596, close this one. It is cheaper on every row that moved, one quarter of the code (~350 vs ~1400 lines), and its lifetimes are compiler-enforced rather than unrestricted. The one thing this PR does better — covering allocations nobody has converted yet — is exactly what the remaining migration work in #596 addresses incrementally, and the numbers say that blanket coverage is not worth what it costs. Worth keeping from this branch: it is the only measurement showing what full allocator replacement costs, which is useful if the remaining conversions ever stall. 🤖 Generated with Claude Code |
Alternative to #596. Both PRs solve the same problem; this one exists so CI can price the two approaches against each other on identical workloads. One of them should be closed once the numbers are in.
Motivation
The preload library runs inside libc calls such as
open,stat, andexecve. Programs are allowed to make these calls from a signal handler, or in the child offork()in a program with many threads. In both situations, using libc'smalloccan hang the program forever: the lock insidemallocmay be held by a thread that is paused or no longer exists.The two approaches
This PR installs one
#[global_allocator]in the preload cdylib: power-of-two size classes carve blocks out of 1 MiB mmap'd slabs, freed blocks recycle through per-class Treiber free lists made ABA-resistant by a 40-bit generation tag, and requests larger than the biggest class (or over-aligned) map and unmap directly. All memory comes from anonymous mappings; libc malloc is never called, no locks are taken, and no thread-local state is used, so a thread that vanishes atfork()or is suspended by a signal cannot strand another.The trade-off in one line: the global allocator converts the whole library immediately but pays its cost on every allocation, while the arena is cheaper per allocation but only covers code that has been rewritten to use it.
Comparing
This PR carries the same
access-relativebenchmark suite as #596, so both report the same rows against the same base.accessprices the absolute-path lane (a borrowed pointer, no directory resolution);access-relativeprices the lane that resolves the working directory and joins a path — where #596's arena is actually used.Read the two benchmark comments together: #596 changes one hot call site, this one changes the allocator underneath all of them.
🤖 Generated with Claude Code