What is the best way to reduce dirty memory in a Rust runtime — hot-path allocation, unbounded queues, and so on?
Built from 12 published recommendations across 4 independent hosts (docs.rs, microsoft.github.io, swe.servos.dev, mucahitkurtlar.com). Several rows repeat the same bounded-channel and mimalloc purge-delay advice from different pages; the narrative consolidates them, and specialized allocators are treated as options to benchmark, not defaults.
Hover a stage for concrete actions. Blue stages fix live memory; the orange stage only treats freed pages the allocator retains.
Cow instead of cloning inside loops, and measure every change with criterion before committing it — docs.rsreset() stabilizes at one warm chunk and makes no system calls per round — but skip the reset and it grows forever — docs.rsretained payload ≈ queue capacity × max item bytes + in-flight concurrency × per-task working-set bytes
Allocator fragmentation, task/future and channel bookkeeping, TLS state, socket buffers and kernel overhead sit on top of this and must be budgeted separately — a payload-only figure does not predict RSS exactly. The point is that once every retaining edge is finite, this number exists at all and is reviewable in code review.
Find who owns the bytes: unbounded queues, retry lists, fan-out, caches, clones kept alive. Allocator tuning cannot help — stages 2–4 are the fix.
The allocator retains freed pages. Enable jemalloc's background_thread with a dirty decay, or lower mimalloc's purge delay — set early, before pre-main allocation latches it. Over-aggressive purging trades OOM risk for madvise churn on the hot path.
| Technique | Action | Tradeoff | Source |
|---|
Source: 12 technique recommendations (action, benefit, tradeoff) gathered from 4 independent hosts; one row per source page. Numbers such as RSS in MB and purge delays in ms are the figures reported by each source, not re-measured here. Actions and tradeoffs are truncated in the table for space; benefits are summarized in the narrative and findings.