Mimalloc Cigarette: Losing one week of my life catching a memory leak
2 days ago
- #rust
- #memory-leak
- #mimalloc
- A pricing engine application at work was RAM-bound and started OOMing in production despite the dataset fitting in memory multiple times.
- The issue was traced to a memory leak when using the mimalloc allocator, which behaves differently based on thread allocation patterns.
- Mimalloc assumes threads allocate memory periodically; if a thread allocates a lot then sleeps, memory blocks aren't properly recycled.
- The problem manifested when a thread allocated memory, spawned other threads to work on it, then went to sleep, leaving memory blocks unreleased.
- The solution involved keeping memory-intensive operations on a single thread and using channels for communication to avoid the issue.