mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[PR #162] [MERGED] perf: reduce server idle memory retention (jemalloc decay + pool runtime threads) #220
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#220
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/AgentENV/pull/162
Author: @huajq
Created: 8/12/2026
Status: ✅ Merged
Merged: 8/13/2026
Merged by: @yingdi-shan
Base:
main← Head:perf/jemalloc-decay-fc-pool-runtime📝 Commits (2)
e247a1fperf(server): shorten jemalloc page decay via malloc_conf56de617perf(sandbox): run firecracker pool runtime on one worker thread📊 Changes
2 files changed (+15 additions, -1 deletions)
View changed files
📝
src/bin/server.rs(+10 -0)📝
src/sandbox/firecracker/pool.rs(+5 -1)📄 Description
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.