The effect of switching to TCMalloc on RocksDB memory use
Quicksilver's memory roughly doubled after its storage moved to RocksDB, climbing from about 15GB to 30GB over several days. Heap profiling showed the heap was about a third of RSS, which pointed to the allocator rather than a leak. glibc malloc gives threads independent per-thread arenas (60-80 arenas for about 25 threads), and memory cannot move between them, so fragmentation multiplies. Mitigations such as MALLOC_ARENA_MAX, periodic malloc_trim and M_MMAP_THRESHOLD each cost lock contention or syscalls, while TCMalloc's middle-end moves freed memory between per-core caches and cut memory use by 2.5x.
Related posts
- Optimizing Ruby’s Memory Layout: Variable Width Allocation
Shopify Engineering hardMasterRuby 3.2's Variable Width Allocation replaces CRuby's single 40-byte RVALUE slot with five size pools (40, 80, 160, 320 and 640 bytes) so classes, strings, arrays and objects can store their data adjacent to the object instead of in separate malloc'd memory. Heap pages grew from 16 KB to 64 KB, and compaction moves resized objects into the best-fitting pool to restore data locality. Embedded strings now go up to 615 bytes and arrays and objects up to 78 elements or instance variables. Microbenchmarks show up to 35% speedups and railsbench gains 2.1%. The change also adds GC.stat_heap, offers a build flag to disable the feature, and opens the door to MMTk-based garbage collector research.
- A Database Without Dynamic Memory Allocation
TigerBeetle mediumAdeptTigerBeetle allocates all memory once at startup and never again, using fixed limits for connections, in-flight messages per client, replicas, message size and queries per message so that total memory is a simple compile-time sum. Beyond avoiding GC and use-after-free, static allocation bounds overload, makes resource use predictable for operators, and lets assertions on pool availability surface sizing mistakes under fuzzing rather than as production resource exhaustion. Supporting choices include fixed-size, cache-line-aligned 128-byte account and transfer structs sent zero-copy over the wire, batched queries (up to 8191 per message), and an LSM forest whose in-memory portion is preallocated and kept bounded by small incremental flushes to disk.
- How we tracked down a Go 1.24 memory regression across hundreds of pods
Datadog Engineering mediumAdeptUpgrading a data-processing service to Go 1.24 raised container memory by about 20% even though Go runtime metrics and heap profiles stayed flat. Comparing `/proc/[pid]/smaps` showed the Go heap's RSS had grown to nearly match its virtual size. Reproducing the workload with heapbench and running `git bisect` traced the cause to a `mallocgc` refactor. That refactor dropped an optimization that skipped re-zeroing fresh OS memory for large (>32 KiB) pointer-containing allocations, so untouched pages were committed to RAM. The fix ships in Go 1.25, and in the worst case RSS should roughly equal Go-reported virtual memory, which is useful when checking memory-limit headroom before rollout.
- chDB - A Rocket Engine on a Bicycle
ClickHouse hardMaster
chDB embeds the ClickHouse engine as an in-process Python module instead of shelling out to the 500MB clickhouse-local binary, using WriteBufferFromVector, Python memoryview and Pybind11 for zero-copy result retrieval. Getting jemalloc to work inside the shared library meant redirecting malloc with the linker flag -Wl,-wrap,malloc. That exposed crashes when glibc functions like getcwd returned glibc-malloc'd memory that was then freed by je_free, so the author patched jemalloc (PR #2424) to make arenas.lookup safe for checking ownership. The result cut memory usage by 50%, and chDB ranks as the fastest stateless/serverless engine on ClickBench. Later releases added SQL over Pandas DataFrames, query stats and Python UDFs.
- Supporting faster file load times with memory optimizations in Rust
Figma mediumAdept
Figma's Rust multiplayer server represented each file node as a BTreeMap from u16 property IDs to pointers, and memory profiling showed this map used over 60% of a file's memory. Because the schema has fewer than 200 fields and nodes average about 60 keys, the team swapped it for a flat sorted vector. Despite worse big-O complexity, the cache-friendly layout cut p99 deserialization time by 20% and fleet memory by about 20%. A further experiment stored the field ID in the unused top 16 bits of x86-64 pointers, saving only about 5% more RSS. That change was not shipped because of the risk of getting reference counts wrong and corrupting memory.