The memory budget counts the bytes we track, not the process RSS
Context#
With a 256 MB budget, peak RSS went to 313 to 330 MB at 2000 files. The gap came from the binary (16 MB), thread stacks, plain malloc users, and unused space in allocator pages.
Decision#
--memory-budget limits the memory that the engine tracks and reserves. It is not an RSS cap. The docs say what the budget leaves out and give the measured overshoot (up to about 60 MB over 256 MB, up to about 160 MB over 128 MB). For a hard limit, run the tool in a job or cgroup, with the budget at about three quarters of that limit. zlib-ng, zstd and libdeflate allocate through our allocator, so their memory is tracked.
Why#
Counting the allocator's backed bytes at the root pool made builds up to 5 times slower (2000 files, 224 threads: 0.58 s to 2.85 s) for a 10 to 25% memory cut. Part of the held bytes cannot be returned fast, so new files waited in admission. A per-thread headroom in admission changed nothing. DuckDB, Velox, Trino, DataFusion and RocksDB document the same convention: a tracked limit, with headroom or an outer cap for the rest.
Rejected options#
- Charge backed bytes to the budget: 5 times slower, still over budget in some rows.
- Subtract a per-thread headroom in admission: no measured change.
- Share heaps between I/O threads: no gain once the idle-page cap exists.
Also found by searching
- process RSS is above --memory-budget
- should the memory budget count RSS
- why does the memory budget not cap the whole process
- counting allocator held bytes against the budget made the build slow