Ubuntu System Monitor and valgrind for detecting memory leaks in C ++ applications

I am writing a C ++ application that uses some open source external libraries. I tried to look at the monitor of the Ubuntu system to get information about how my process uses resources, and I noticed that the resident memory continues to increase to very large values ​​(more than 100 MB). This application should work in the embedded device, so I have to be careful.

I started thinking that there should be a (some) memory leak, so I use valgrind. Unfortunately, valgrind does not seem to report significant memory leaks, only some minor problems in the libraries that I use, no more.

So, do I need to conclude that my algorithm really uses so much memory? It seems very strange to me ... Or maybe I do not understand the meaning of the system monitor columns? Can someone clarify the meaning of “Virtual memory”, “Resident memory”, “Record memory” and “Memory” in the system monitor when it is related to software profiling? Should I expect that these values ​​will immediately represent how much memory my process takes in RAM?

In the past, I used tools that could tell me where I use memory, such as Apple Profiling Tools. Is there something similar that I can use on Linux?

Thank!

+5
source share
1

, - /lib/libmemusage.so:

$ LD_PRELOAD=/lib/libmemusage.so vim 

Memory usage summary: heap total: 4643025, heap peak: 997580, stack peak: 26160
         total calls   total memory   failed calls
 malloc|      42346        4528378              0
realloc|         52           7988              0  (nomove:26, dec:0, free:0)
 calloc|         34         106659              0
   free|      28622        3720100
Histogram for block sizes:
    0-15          14226  33% ==================================================
   16-31           8618  20% ==============================
   32-47           1433   3% =====
   48-63           4174   9% ==============
   64-79           4736  11% ================
   80-95            313  <1% =
...

( vim .)

, , , .

valgrind ; --leak-check=full --show-reachable=yes , .


" ", "-", " " ""

- , . malloc(1024*1024*100);, malloc(3) 100 ( ). 100 mmap(..., MAP_ANONYMOUS), - . ( . Rant malloc(3).) .

, , .

- , . C 1,5 , 100k ( ) , -. paging , . , , , Resident.

- , . ( pmap(1): pmap $$ , , , , , .) , .

, , 50-100 , C, . ( , mmap(..., MAP_PRIVATE|PROT_WRITE), , .) top(1) , SHR. ( , , (libc) .)

. , .

+6

All Articles