perf: reduce server idle memory retention (jemalloc decay + pool runtime threads) - #162
Open
huajq wants to merge 2 commits into
Open
perf: reduce server idle memory retention (jemalloc decay + pool runtime threads)#162huajq wants to merge 2 commits into
huajq wants to merge 2 commits into
Conversation
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). |
Set dirty_decay_ms=1000 (from the 10s default) and muzzy_decay_ms=1000 (from 0, i.e. immediate purge) so pages freed by burst allocations (RocksDB opens, image resolution, template builds) are returned to the OS within ~2s. background_thread:true is already baked into the jemalloc build by tikv-jemalloc-sys (via the background_threads cargo feature); it is repeated here only for explicitness. MALLOC_CONF can still override per environment.
The pool's owned runtime only drives occasional I/O-bound block_on calls (spawn Firecracker, poll its API socket) from the maintenance thread. The default multi-thread runtime parks one worker per CPU core for the process lifetime.
huajq
force-pushed
the
perf/jemalloc-decay-fc-pool-runtime
branch
from
August 13, 2026 05:35
777b940 to
56de617
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two small changes that reduce the API server's idle/background memory
footprint:
malloc_confstring(
dirty_decay_ms:1000,muzzy_decay_ms:1000,background_thread:true).worker thread.
Why
A production memory audit showed two server-side hygiene issues:
server RSS climbs and is slow to fall back: jemalloc's default
dirty-page decay is 10s (
muzzy_decay_msdefaults to 0, i.e.immediate), so burst pages linger as retained RSS well after the
burst. Shortening both to 1s returns them within ~2s.
Note on mechanism: background purging threads are already active —
the
background_threadscargo feature makestikv-jemalloc-sysbake
background_thread:trueinto the jemalloc build via--with-malloc-conf(build.rs). It is included in the string onlyfor explicitness; the effective change here is the decay tuning.
builder, parking one worker thread per CPU core for the process
lifetime, although it only drives occasional I/O-bound
block_oncalls from the maintenance thread.
Related issue
N/A — small performance hygiene change from a direct memory audit; no
tracking issue.
Scope and non-goals
memory, and any pool watermark/sizing changes.
Design and behavior changes
malloc_confis jemalloc's link-time configuration mechanism and isparsed at allocator init, before
main(); the TOML config systemtherefore cannot express these settings. Precedence (lowest first):
build-time
config_malloc_conf(already carriesbackground_thread:true), link-timemalloc_confsymbol (thischange),
/etc/malloc.conf,MALLOC_CONFenv var — later sourceswin per key, so deployments keep an env-level override hatch.
new_multi_thread()withworker_threads(1),so the existing spawn-based fill logic behaves identically on one
worker; pool refill concurrency is unchanged (driven by
fill_concurrency, cooperative on the single worker).Compatibility and operations
MALLOC_CONFremainsavailable as a per-environment override.
Validation
make fmtmake clippymake test-unitbehavior change; changes are allocator tuning and a runtime
worker-count setting covered by existing unit tests.
make -C services test— N/A:services/untouched.MALLOC_CONFis jemalloc's built-in override channel.affects memory retention timing and idle thread count, not a
latency/throughput path.
Commands and results:
Skipped checks and reasons: integration tests and benchmarks (no
lifecycle or latency-path change); test-unit failure is pre-existing on
the base commit in a root test environment, unrelated to these files.
Risks and reviewer notes
madvisepurging afterbursts; the purging runs on jemalloc's background thread (already
enabled at build time), so the allocation path is unaffected. Config
validity verified with an
abort_conf:truesmoke run.block_onwork;refill stays I/O-bound and off the sandbox critical path.
src/bin/server.rs(new exported symbol),src/sandbox/firecracker/pool.rs(worker_threads).Checklist
refactoring.
impractical.
registry information.
source and regenerating it.