rs-malloc-tracker
This tool is meant to solve a specific use-case: Troubleshooting unexplained memory usage in a C application (namely asterisk).
Ideally, you'd make every memory allocation go through a custom allocator that does proper tracking for your use-case. In my case though, I had a couple problems:
- Shared libraries obviously don't follow this pattern
- The memory that I was tracking through my custom allocator did not add up to the observed RSS of my application. Not even close:

From these observations, it was clear that a lower-level instrumentation was required to properly shine light on what was going on. Hence, this tool.
What this does
- Use the
LD_PRELOADtrick to:- Wrap
malloc(3),free(3)and related functions to tabulate memory usage - Wrap
mmap(3)andmunmap(3)to tabulate VSS and RSS separately
- Wrap
- Expose the results in prometheus format in a per-process UNIX socket
The end result looks like this:
![]()
This allowed me to understand what my problem was: https://github.com/facebook/jemalloc/issues/46