BlogsCloudflareMemory Allocator Optimization

Memory Allocator Optimization

Memory Allocator Optimization

1
posts
2021

Cloudflare has optimized memory usage by switching from glibc malloc to TCMalloc for services like Quicksilver, which uses RocksDB. This involved understanding the fragmentation issues inherent in glibc's arena-based allocation and the benefits of TCMalloc's front-end, middle-end, and back-end design for improved memory reuse across threads. The switch resulted in a 2.5x reduction in memory consumption.

2021

The effect of switching to TCMalloc on RocksDB memory use

2/3/2021

This post details the investigation into high memory consumption in a RocksDB-based service (Quicksilver) and the successful resolution by switching the memory allocator from glibc malloc to TCMalloc. It explains the memory fragmentation issues with glibc's multiple arenas and how TCMalloc's design, with its front-end, middle-end, and back-end components, significantly improves memory reuse and reduces fragmentation, leading to a 2.5x decrease in memory usage.