Linux: how to measure memory usage for a thread in a process?

I want to measure the memory usage for each thread in a process. Is it possible? I am trying to figure out what kind of memory leak thread.

Edit 1. The leaking pmap process shows ~ 600 allocation [anon]

... 63b00000 772K rw--- [ anon ] 63bc1000 252K ----- [ anon ] 63c00000 772K rw--- [ anon ] 63cc1000 252K ----- [ anon ] 63d00000 772K rw--- [ anon ] ... 

Advice on what to do next?

Edit 2. Only virtual memory leaks, for example. physical memory usage is stable.

+4
source share
2 answers

No, this is impossible, because memory is not tied to a thread, but to a process. There is no connection between the stream and some part of the memory.

What you think is necessary is a profiler that points to selection points. One of them (not used it in the last decade) is Rational Purify .

+6
source

Usually you cannot determine the memory usage of a thread, because ownership of the property can move freely between threads. Kernel mapping tables will show you the use of the process as a whole, that is, the memory allocated for all threads.

Programming threads is difficult. If you really do not need to freely exchange pointers and memory between threads, which is a rather unpleasant smell of code, then it will probably be easier to debug if you process your program as a flock of processes that exchange information via IPC, which also forces you to consider which should to be shared. As a bonus, if the ongoing process is relatively short-lived, the memory is returned to the system on exit() without the need to find and fix the leak.

+2
source

Source: https://habr.com/ru/post/1444820/


All Articles