c++ - Calculating used memory by a set of processes on Linux -
i'm having trouble calculating used memory (resident) set of processes.
the issue came user set of processes share memory between themselves, simple addition of used memory ends nonsense number (>60gb when machine has 48gb memory).
is there simple way approach problem?
i can approximation. take (res mem - shared mem) * num proc + shared mem
. not processes share same memory block.
i'm looking posix or linux solution problem c/c++.
you want iterate through each processes /proc/[pid]/smaps
it contain entry each vm mapping of likes:
7ffffffe7000-7ffffffff000 rw-p 00000000 00:00 0 [stack] size: 100 kb rss: 20 kb pss: 20 kb shared_clean: 0 kb shared_dirty: 0 kb private_clean: 0 kb private_dirty: 20 kb referenced: 20 kb anonymous: 20 kb anonhugepages: 0 kb swap: 0 kb kernelpagesize: 4 kb mmupagesize: 4 kb
private_dirty
memory interested in.
if have pss
field in smaps
file amount of resident memory divided amount of processes share physical memory.
private_clean
copy-on-write mappings. commonly used shared libraries , read/no-write/execute.
Comments
Post a Comment