1

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?

4

1 回答 1

1

Massif gives 2 numbers for the number of bytes allocated:

  • The "logical number" of bytes allocated by your program.
  • The "overhead"

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

于 2019-03-22T05:40:55.377 回答