Rust Service Isn't Leaking – It Could Be the Allocator
17 hours ago
- #memory management
- #Rust performance
- #allocator comparison
- Memory usage remained high after processing events despite no memory leak in Rust code, due to allocator behavior.
- Glibc's ptmalloc allocator retains freed memory in arenas, causing high RSS as freed chunks may not be returned to the OS, especially with thread arenas and fragmentation.
- Switching to jemalloc resolved the issue because it uses size-class-segregated slabs, allowing independent memory reclamation via background threads and decay timers.
- Mimalloc did not work well for bursty workloads because cross-thread frees delayed reclamation, and RSS remained high without continuous allocation activity.