Are there any good memory fragmentation profilers? (linux gcc version would be nice). Valgrind cannot analyze this because it uses custom malloc/free functions.
Thanks, Andrew
Are there any good memory fragmentation profilers? (linux gcc version would be nice). Valgrind cannot analyze this because it uses custom malloc/free functions.
Thanks, Andrew
I have trouble understanding how any tool you might find would understand the segment data structures of your custom memory management. You might be able to get the busy distribution(hooking into malloc/free) but the free distribution (which essentially is the fragmentation) seems up in the air.
So why not add busy/free statistics/histograms to your custom memory manager. If bins are indexed by something proportional to log2(size) its O(1) to keep these statistics as when you split and coalesce you know the sizes and you can find the bin by direct lookup using an index proportional to log2(size)
eg histogram bin intervals
[2^n,2^(n+1) ) ...
(eg if you want finer bins use log base square root 2(size) which can be calculated with 4 integer instructions on x86 [bit scan, compare, set, add])
another set of reasonable bin sizes to use are the following open intervals
[2^n, 2^n+2^(n-1) ),[2^n+2^(n-1),2^(n+1) )...
again easily calculable [bit scan, shift, and, add])
nedmalloc is a very good custom allocator, comes with source, optimized to avoid fragmentation.
I would plug that in, and start looking at its internal logging for fragmentation statistics.
I would start with mtrace. When you have a trace, glibc comes with a perl script mtrace(1) which finds leaks. However, the trace format is easy to understand, so it should be straight-forward process this into fragmentation analysis.