Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list "cold" memory areas

I'm trying to hunt down a very evasive bug in a server software that look like a memory leak, but memcheck didn't help at all. My guess is that the memory that has been instantiated and never removed is indeed not leaked, so there is a reference to it, but is now useless for the program and should be removed. Is there a tool that can count accesses, not references, in memory, and so give a evaluation of the effective usage of objects in heap?

like image 690
Lorenzo Pistone Avatar asked Dec 26 '11 17:12

Lorenzo Pistone


1 Answers

I ended up with implementing my own tool. My approach was slightly different from what I intended: I wrote a malloc hooking library. It hooks malloc, realloc and free, and maintains a list of living malloc'd memory blocks. Whenever you send a SIGUSR1 to your application, it dumps its info in a file, and evaluate it as a Mathematica expression. The Mathematica notebook finally provide some very useful graphs: top scored instantiations by call stack, and a complete overview of calls to malloc. With these tools, I just had to hover my mouse on the fattest and most distant from the center green dot of the second graph, and, voilà, I have the address that instantiates loads of not leaked but useless memory.

P.S. The circular calls that you can see in the second graph are definitely a bug in libc's backtrace().

like image 56
Lorenzo Pistone Avatar answered Nov 06 '22 05:11

Lorenzo Pistone