valgrindheap-memorymassif

Different results from running program with Valgrind with(out) using Massif


I'm creating a performance-driven program for a school project and as such, I thought I'd profile the memory usage of my program.

For that I used Valgrind, both with and without the Massif tool. The results for using each test are below:

Running valgrind --leak-check=full -v ./main gave me the above output. Okay, got it, a total of around 67MB of heap usage, right?

enter image description here

enter image description here

But then I wanted to know how much memory was allocated by my program at runtime, so I did some digging and found the Massif tool, which does exactly that.

Thus I ran valgrind --tool=massif ./main, followed by ms_print massif.out.<pid>, in which <pid> is the process ID of the now dead process which executed my program. That provided me with the output shown in the above 2 pictures.

So my question is, how can it be that the total heap usage is around 67MB but Massif says it peaked at 109.9MB at a certain point?


Solution

  • Massif gives 2 numbers for the number of bytes allocated:

    Each block your program allocates implies a certain overhead, e.g. due to alignment/padding. In the list of snapshots, the column useful-heap(B) shows what your program has requested. The extra-heap(B) shows the overhead.

    The 109MB is the useful + extra heap.

    You can tune the overhead using --heap-admin=size