Our software implement a actor model system, and we allocate/deallocate the small object very often.I am very sure the each object be destroyed without memory leak. ( I have used valgrind and tcmalloc tool to check the memory leak in my software. No leak be found.)
When we change to use tcmalloc for replacing the malloc in glibc, we found the memory continually increasing until the process be killed by OOM(Out of Memory). Then we found glibc also have same issue, but increase rate is less than tcmalloc.
I used the malloc_stats() to show the memory information
after first execution(top show 0.96G)'
- MALLOC: 960110592 ( 915.6 MB) Heap size
- MALLOC: 15886016 ( 15.2 MB) Bytes in use by application
- MALLOC: 907419648 ( 865.4 MB) Bytes free in page heap
- MALLOC: 0 ( 0.0 MB) Bytes unmapped in page heap
- MALLOC: 27121208 ( 25.9 MB) Bytes free in central cache
- MALLOC: 151040 ( 0.1 MB) Bytes free in transfer cache
- MALLOC: 9532680 ( 9.1 MB) Bytes free in thread caches
- MALLOC: 14275 Spans in use
- MALLOC: 27 Thread heaps in use
- MALLOC: 7602176 ( 7.2 MB) Metadata allocated
After 5th same execution(top show 1.2G)
- MALLOC: 1173131264 ( 1118.8 MB) Heap size
- MALLOC: 18001048 ( 17.2 MB) Bytes in use by application
- MALLOC: 1082458112 ( 1032.3 MB) Bytes free in page heap
- MALLOC: 21168128 ( 20.2 MB) Bytes unmapped in page heap
- MALLOC: 37992328 ( 36.2 MB) Bytes free in central cache
- MALLOC: 252928 ( 0.2 MB) Bytes free in transfer cache
- MALLOC: 13258720 ( 12.6 MB) Bytes free in thread caches
- MALLOC: 17651 Spans in use
- MALLOC: 27 Thread heaps in use
- MALLOC: 8126464 ( 7.8 MB) Metadata allocated
We can seen from thus data. after 5th same behavior, only 17.2 be used in our software. But the tcmalloc hold 1.1G memory without return to system. Of course, It does not matter tcmalloc hold those memory. But it keep increasing when our program be killed by OOM(actual used memory is less than 1G).
We have doubt that it is related to heap fragmentation. Anybody have some experience could share with us? I think I have same situation as https://bugzilla.redhat.com/show_bug.cgi?id=843478
Thanks very much.