We have a program that crashes at 4Gb due to insufficient memory after running for a long period of time. The project is in C++, openSuse11,12, including linking to various shared memories and other libraries.
Monitoring the heap increase and total memory increase from the pmap of the PID, they are totally analogous. Meaning the process starts with 2.5Gb and heap ~0 , and before crashing Total = 4 Gb
and heap = 1.5 Gb
.
We have made some runs with valgrind and the result is quite puzzling. Below you can see the summaries for running 20 minutes.
==30042== HEAP SUMMARY:
==30042== in use at exit: 706,413 bytes in 3,345 blocks
==30042== total heap usage: 1,770,240 allocs, 1,766,895 frees, 173,813,303 bytes allocated
==30042== LEAK SUMMARY:
==30042== definitely lost: 96 bytes in 3 blocks
==30042== indirectly lost: 27 bytes in 3 blocks
==30042== possibly lost: 344 bytes in 2 blocks
==30042== still reachable: 705,946 bytes in 3,337 blocks
==30042== of which reachable via heuristic:
==30042== stdstring : 62 bytes in 2 blocks
==30042== suppressed: 0 bytes in 0 blocks
Monitoring the pmap, we know that the total memory increased by 130 Mb
but comparing this to the valgrind report, we can see there are leaks but nothing really close to the 130 Mb
.
Now to the questions:
Can someone help me understand the valgrind summary and how it can relate to the
130 Mb
lost ?Is this a leak or not ?
- Does valgrind report what is going on inside the shared memories ?
- Even if there is a leak in the SM, wouldn't it still be in heap in them? Their sizes are in reasonable levels.
- I have read in various sources, that even when freeing the memory with
delete[] or free()
the system still may keep the space reserved for future use. If that is the case, what can be done ?
*EDIT The place this heap usage seems to be unrestricted is when the program which is a server, makes calls to a DB (solid SQL) for large data continuously, which allocates a lot of space. It is not in a shared memory. And we see that frees are correctly managed, what can be done ?