I noticed that my application is leaking memory in stack area. There are many threads going on, stopping/starting quite often. I noticed (by using pmap) that [anon] areas number is growing, even when thread count stays the same. I can't think of anything else, that would occupy that area of memory, other than stack of threads.
I'm now struggling, how to identify who (which thread) is occupying that area? And also to understand why those areas are not unmapped as they are on x86.
I'm working on mips target, I can't reproduce it on x86.
I have no valgrind for mips.
I thought about LD_PRELOAD for mmap, but failed to make it work.
I assume that these are all mmaped regions, so I think none "leak-find" tools would help here, as they are all malloc based.
I'm looking for a way to identify those [ anon ] areas. Having a stack trace to see, which thread allocated it would be nice.
Is there a way to see, which memory regions were mapped by specific thread? Or this way: Is there a way to get thread's stack pointer from outside? Perhaps I could make a kernel module to list all threads and their stack pointer, but I don't know where kernel keeps this information.
Following trace is just for illustration, if you didn't see pmap before:
Code:
0000000000400000 744K r-x-- /bin/bash
00000000006b9000 40K rw--- /bin/bash
00000000006c3000 20K rw--- [ anon ]
0000000001766000 3488K rw--- [ anon ]
00007f6f59753000 40K r-x-- /lib/libnss_files-2.7.so
00007f6f5975d000 2048K ----- /lib/libnss_files-2.7.so
00007f6f5995d000 8K rw--- /lib/libnss_files-2.7.so
00007f6f5995f000 40K r-x-- /lib/libnss_nis-2.7.so
00007f6f59969000 2044K ----- /lib/libnss_nis-2.7.so
00007f6f59b68000 8K rw--- /lib/libnss_nis-2.7.so
00007f6f59b6a000 84K r-x-- /lib/libnsl-2.7.so
00007f6f59b7f000 2044K ----- /lib/libnsl-2.7.so
00007f6f59d7e000 8K rw--- /lib/libnsl-2.7.so
00007f6f59d80000 8K rw--- [ anon ]
00007f6f59d82000 28K r-x-- /lib/libnss_compat-2.7.so
00007f6f59d89000 2044K ----- /lib/libnss_compat-2.7.so
00007f6f59f88000 8K rw--- /lib/libnss_compat-2.7.so
00007f6f59f8a000 1320K r-x-- /lib/libc-2.7.so
00007f6f5a0d4000 2044K ----- /lib/libc-2.7.so
00007f6f5a2d3000 12K r---- /lib/libc-2.7.so
00007f6f5a2d6000 8K rw--- /lib/libc-2.7.so
00007f6f5a2d8000 20K rw--- [ anon ]
00007f6f5a2dd000 8K r-x-- /lib/libdl-2.7.so
00007f6f5a2df000 2048K ----- /lib/libdl-2.7.so
00007f6f5a4df000 8K rw--- /lib/libdl-2.7.so
00007f6f5a4e1000 236K r-x-- /lib/libncurses.so.5.7
00007f6f5a51c000 2044K ----- /lib/libncurses.so.5.7
00007f6f5a71b000 20K rw--- /lib/libncurses.so.5.7
00007f6f5a720000 112K r-x-- /lib/ld-2.7.so
00007f6f5a7bf000 1368K r---- /usr/lib/locale/locale-archive
00007f6f5a915000 8K rw--- [ anon ]
00007f6f5a931000 28K r--s- /usr/lib/gconv/gconv-modules.cache
00007f6f5a938000 12K rw--- [ anon ]
00007f6f5a93b000 8K rw--- /lib/ld-2.7.so
00007fff62927000 84K rw--- [ stack ]
00007fff629fe000 4K r-x-- [ anon ]
ffffffffff600000 4K r-x-- [ anon ]