Skip to content

perf(alloc): use jemalloc to reduce memory fragmentation#200

Merged
philippem merged 1 commit intoBlockstream:new-indexfrom
EddieHouston:pr/jemalloc
Mar 31, 2026
Merged

perf(alloc): use jemalloc to reduce memory fragmentation#200
philippem merged 1 commit intoBlockstream:new-indexfrom
EddieHouston:pr/jemalloc

Conversation

@EddieHouston
Copy link
Copy Markdown
Collaborator

@EddieHouston EddieHouston commented Mar 31, 2026

Summary

  • Replaces the system allocator (glibc malloc) with jemalloc via tikv-jemallocator
  • Reduces RSS by ~18% by eliminating malloc fragmentation that accumulates over time with RocksDB's allocation patterns
  • Particularly important in memory-constrained environments where fragmentation inflates resident memory toward OOM

Background

glibc malloc fragments heavily under RocksDB's allocation pattern of many small, long-lived objects (block cache entries, memtable keys). Over hours of operation, RSS grows well beyond the logical heap size. jemalloc's arena-based allocator
and thread-local caching avoid this fragmentation.

Measured on a production-sized mainnet node (62 GB RAM, 1.45 TB DB):

  • glibc malloc: RSS steadily climbed over time
  • jemalloc: RSS stable at ~18% lower than glibc baseline

Test plan

  • cargo check / cargo build with default features
  • cargo build --features liquid
  • Verify jemalloc is active (RSS should be noticeably lower than glibc on a mainnet node)
  • No functional changes — allocator swap only

  Replace the system allocator (glibc malloc) with jemalloc via
  tikv-jemallocator. Reduces RSS by ~18% by eliminating malloc
  fragmentation that accumulates over time with RocksDB's allocation
  patterns.
@philippem philippem merged commit 74e4b61 into Blockstream:new-index Mar 31, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants