I found this post titled: Understanding memory usage on Linux which I think does a better job than the one I'd found previously on the linuxquestions.org site, titled: How to accurately measure memory usage?.
excerpt from the Understanding memory ... post
ps output
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
dbunker 3468 0.0 2.7 25400 14452 ? S 20:19 0:00 kdeinit: kedit
pmap output
Address Kbytes Mode Offset Device Mapping
08048000 40 r-x-- 0000000000000000 0fe:00000 kdeinit
08052000 4 rw--- 0000000000009000 0fe:00000 kdeinit
08053000 1164 rw--- 0000000008053000 000:00000 [ anon ]
40000000 84 r-x-- 0000000000000000 0fe:00000 ld-2.3.5.so
40015000 8 rw--- 0000000000014000 0fe:00000 ld-2.3.5.so
40017000 4 rw--- 0000000040017000 000:00000 [ anon ]
... (trimmed) ...
mapped: 25404K writeable/private: 2432K shared: 0K
description of what's going on
If you go through the output, you will find that the lines with the
largest Kbytes number are usually the code segments of the included
shared libraries (the ones that start with "lib" are the shared
libraries). What is great about that is that they are the ones that
can be shared between processes. If you factor out all of the parts
that are shared between processes, you end up with the
"writeable/private" total, which is shown at the bottom of the output.
This is what can be considered the incremental cost of this process,
factoring out the shared libraries. Therefore, the cost to run this
instance of KEdit (assuming that all of the shared libraries were
already loaded) is around 2 megabytes. That is quite a different story
from the 14 or 25 megabytes that ps reported.
How much swap is process X using?
You can find out a processes' swap space that it's using with this command:
$ grep VmSwap /proc/$(pidof chrome | awk '{print $1}')/status
VmSwap: 1324 kB
The above is getting the first PID of chrome
returning the VmSwap
value for it.
memstat
You might want to check out this tool instead if you're looking for accurate measures of memory, it's callled memstat
:
There's a tutorial on cyberciti.biz titled: Linux: Find Out What’s Using Up All Virtual Memory that shows memstat
in action.
References