---
title: "The effect of switching to TCMalloc on RocksDB memory use"
description: "Quicksilver's memory roughly doubled after its storage moved to RocksDB, climbing from about 15GB to 30GB over several days."
url: "https://swe.quest/articles/the-effect-of-switching-to-tcmalloc-on-rocksdb-memory-use-97e46a9ddc75be5e"
canonical: "https://blog.cloudflare.com/the-effect-of-switching-to-tcmalloc-on-rocksdb-memory-use"
source: "Cloudflare"
published: "2021-02-03"
difficulty: "medium"
kind: "Case study"
reading_minutes: 8
tags: ["memory-management","performance","linux","storage-engines"]
---

# The effect of switching to TCMalloc on RocksDB memory use

A post on [Cloudflare](https://swe.quest/sources/cloudflare.md), published 2021-02-03, 8 min read, Case study. Original: [https://blog.cloudflare.com/the-effect-of-switching-to-tcmalloc-on-rocksdb-memory-use](https://blog.cloudflare.com/the-effect-of-switching-to-tcmalloc-on-rocksdb-memory-use)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)
- [Storage engines](https://swe.quest/tags/storage-engines.md) (Data & databases)

## Prerequisites

- heap vs RSS memory
- multithreading basics ([easy posts on Concurrency](https://swe.quest/tags/concurrency.md?difficulty=easy))
- malloc/free

## Keywords

TCMalloc, glibc malloc, RocksDB, Quicksilver, malloc\_trim, MALLOC\_ARENA\_MAX, jemalloc

## Related posts

- [Optimizing Ruby’s Memory Layout: Variable Width Allocation](https://swe.quest/articles/optimizing-ruby-s-memory-layout-variable-width-allocation-7db49cee151f4d44.md): Shopify Engineering · 2022-12-25 · Hard · 13 min read · Memory management, Ruby, Runtimes & VMs, Performance engineering
  Ruby 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.
- [A Database Without Dynamic Memory Allocation](https://swe.quest/articles/a-database-without-dynamic-memory-allocation-4be7684fa723cb5d.md): TigerBeetle · 2022-10-12 · Medium · 6 min read · Memory management, Zig, Databases, Storage engines, Testing
  TigerBeetle 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.
- [How we tracked down a Go 1.24 memory regression across hundreds of pods](https://swe.quest/articles/how-we-tracked-down-a-go-1-24-memory-regression-across-hundreds-of-pods-bbf00972d141a71d.md): Datadog Engineering · 2025-07-17 · Medium · 9 min read · Go, Memory management, Debugging, Performance engineering, Runtimes & VMs
  Upgrading a data-processing service to Go 1.24 raised container memory by about 20% even though Go runtime metrics and heap profiles stayed flat.
- [chDB - A Rocket Engine on a Bicycle](https://swe.quest/articles/chdb-a-rocket-engine-on-a-bicycle-951148e84c12126b.md): ClickHouse · 2023-09-29 · Hard · 9 min read · Analytics & OLAP, Memory management, C & C++, Python, Performance engineering
  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.
- [Supporting faster file load times with memory optimizations in Rust](https://swe.quest/articles/supporting-faster-file-load-times-with-memory-optimizations-in-rust-9b748f81216508a0.md): Figma · 2025-06-18 · Medium · 6 min read · Rust, Memory management, Performance engineering, Data structures, Real-time systems
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
