How to calculate the total RAM used by several processes
Each process can have "normal" memory, shared memory (which may or may not be shared!) and code/library files, all of which seem to be included in the %RSS column on top.
We are trying to graph a breakdown of the RAM used by process, each running as a different user.
Is there some way we can work out how much system RAM (not swap space) is being used by a given list of PIDs, or even for each user?
Currently we are running top and scraping the values in the %RSS column, but these seem to add up to more than the total RAM used (excluding buffers+cached). I suspect this is because of shared code and libraries, and other shared memory, being counted multiple times.
I know about /proc/#/statm and /proc/#/status but I can't work out how to link the values between different processes.
For an abstract example (I don't have much real data at the moment), consider that two processes, A and B, both use libbig.so (50Mb), and B and C both share a 1Mb shared memory segment, and each happens to have a working-memory+code footprint of 10Mb:
Total RAM used by A = 60Mb
Total RAM used by B = 61Mb
Total RAM used by C = 11Mb
Sum total RAM used by A, B and C together = 182Mb (not a useful value!)
Aggregate total RAM used by A, B and C together = 81Mb (since the .so are shared).
Can anyone point me at some reference for this?