I've been able to calculate unshared memory use by summing anonymous and stack mappings from pmap -x
e.g.
sudo pmap -x $THE_PID |egrep 'anon|stack' | awk '{print $2}' | paste -sd+ | bc
but can't find any way to get similar info from ps
at all. top
shows a SHR
column, but doesn't appear to offer a way to sort by UNshared memory. Sorting by RSS isn't useful since RSS contains shared pages but only AFAICS those shared pages the process has touched.
So if you have two processes, both using the same 16GB shared address space, they'll sort based on which has touched more of the shared memory. Not by which has allocated more private (unshared) memory, unless both have touched the same amount of shmem or close to it.
Similar issues arise with read/write mappings of shared libraries, and with fork
ed-but-not-exec
'd processes that share copy-on-write pages from their ancestor.
This is ... unhelpful.
I've looked into ways to sort top
output by expressions. But if it supports it in its sort syntax I can't figure it out.
This seems like such an obvious thing, but ps doesn't even expose shared info at all!
Please tell me I'm missing something.