Repository navigation
Commit ffc4ac1
authored
perf(alloc): compile jemalloc's never-purge policy into the binary (#996)
* perf(alloc): compile jemalloc's never-purge policy into the binary
jemalloc is unchanged and stays: it is here because the platform allocator keeps
freed arena chunks resident, and the recursion campaign measured the same proves
reading up to 13 GiB higher under glibc. What changes is its decay policy. Each
jemalloc `#[global_allocator]` site now exports jemalloc's compile-time
configuration string beside it:
dirty_decay_ms:-1,muzzy_decay_ms:-1
The decay timers hand freed pages back to the OS. The prover allocates and frees
multi-hundred-MiB host buffers continuously, so those pages are re-faulted almost
immediately, and the fault lands on the worker threads doing the proving. The
default policy cost about 13 M extra minor faults and about 15 s of extra system
time per run on the arms below.
Measured on an RTX 5090 box on the recursion campaign's branches, ABBA in each,
every arm at one commit and one set of knobs:
* WHIR prover (keccak, whir/lfm @ 64393da) — 39.69-39.88 s a block with the
setting against 43.94-44.07 s without.
* Per-table STARK tree (0e4f461) — 187 / 163 / 166 / 171 s, both never-purge
arms under both default arms, 5-24 s a block, proof bytes unmoved.
The cost is peak RSS: +1.4 GiB and +2.9-3.3 GiB respectively, an order below the
13 GiB the allocator choice itself is worth, which is why the lever is the decay
setting and not the allocator. `background_thread:true` recovers none of it: the
cost is the re-touch, not the `madvise` call. This branch's own pipeline has not
been measured under the setting.
`MALLOC_CONF` / `_RJEM_MALLOC_CONF` in the environment still override the
compiled-in default, which is how a benchmark arm puts the old policy back.
Nothing about the export is compiler-checked: a misspelled symbol, a wrong value
type, or a jemalloc built without the `_rjem_` prefix each leave a binary that
links, runs, and quietly purges. `prover/tests/jemalloc_conf.rs` reads
`opt.dirty_decay_ms` and `opt.muzzy_decay_ms` back out of the allocator serving
the test process and asserts both are -1, after asserting neither environment
variable is set so it cannot pass for the wrong reason. It is its own test binary
because the check needs a jemalloc process of its own; that the shipped binary
carries the symbol is a link-time property, read with `nm`.
No proof byte moves: an allocator is not an input to any transcript.
* Correct four comment claims in the never-purge export
The escape hatch named a variable this binary does not read. `tikv-jemalloc-sys`
builds with `--with-jemalloc-prefix=_rjem_` under default features, and jemalloc
picks exactly one env name at configure time (`obtain_malloc_conf`, source 3),
so only `_RJEM_MALLOC_CONF` is read here — plain `MALLOC_CONF` is inert. An arm
that followed the comment to "put the default policy back" would have measured
never-purge on both sides, with no warning, and read the lever as dead. The
prefixed file source `/etc/_rjem_malloc.conf` is now named too, since it is the
one remaining way to set `opt.*` from outside the binary.
`jemalloc_conf.rs` was described in two places as what fails if the export stops
being read. It carries its own copy of the block and reads its own process, so
deleting either production export leaves it green: it pins the pattern, not the
two sites that ship it. Both comments now say that, and the test's module doc
says it of itself.
"An order below the 13 GiB" holds for the +1.4 GiB figure (9x) but not for
+2.9-3.3 GiB (4x). Now "a ninth to a quarter of".
"+13 M minor faults and +15 s of system time per arm" sits under the WHIR bullet
and is that arm's figure; the body says "arms". Scoped to the arm it belongs to.
The only non-comment change is the order of the two names in the env guard, so
the prefixed one — the one that can actually affect the reading — is checked
first. Both still have to be unset; plain `MALLOC_CONF` stays guarded so a future
unprefixed build cannot pass here silently.1 parent c2ac5d5 commit ffc4ac1
3 files changed
Lines changed: 146 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
13 | 62 | | |
14 | 63 | | |
15 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
24 | 40 | | |
25 | 41 | | |
26 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
0 commit comments