My Memory Allocator Journey: From HZ3 to HZ12
If you're interested in the deep technical details, you can find the documentation and the source code here:
Paper: https://doi.org/10.5281/zenodo.21360690
GitHub: https://github.com/hakorune/hakozunaThe Evolution of Hakozuna
Hakozuna isn't just one tool; it's a family of allocators designed to push the boundaries of malloc/free performance, RSS (Resident Set Size) management, and safety. Each version was a response to a specific engineering bottleneck:
The HZ11 Experiment: Speed vs. Visibility
In HZ11, I went all-in on performance. The goal was to eliminate the overhead of ensuring that a thread freeing an object always returned it to the original owner. Instead of strict ownership, I implemented a tiered structure:
front cache ──> transfer cache ──> central spans ──> ownerless recyclingBy removing ownership checks from the hot path of every free call, the throughput on Linux x86-64 was staggering compared to tcmalloc in specific workloads:
But there was a massive catch. Because the recycling was "ownerless," it became a nightmare to track when a span was actually empty. If objects are scattered across various thread caches, how do you know when it's safe to decommit memory without adding heavy atomic counters to every single operation?
HZ12: The "Hint" System
This is where HZ12 comes in. I realized that if we want speed, we can't let ownership dictate the hot path. In HZ12, I decoupled ownership from safety.
The "ownership token" is no longer a hard requirement for reclamation; it's just a hint to help find candidates. The actual authority to reclaim memory is moved to a "cold path" where we perform heavy validation, such as:
This way, the malloc and free calls stay lean and mean, while the heavy lifting of memory management happens in the background. It’s a massive shift in how you think about memory safety and efficiency in an LLM agent or high-performance system environment.