I parse data from /proc/[pid]/statm
to get a clue about memory usage of a certain process. man proc
states that resident set size(measured in 'pages') is the same as VmRSS (KB??) in /proc/[pid]/status
. Since they have different values, I would like to understand the connection between these Values. Is there something like a factor I can read somewhere in /proc
(I thought of VmPTE but its sth. else...)? Which one of both should I parse to get the size of the used Memory for a certain process?
#ex 1782 = firefox
~$ cat /proc/1782/statm
224621 46703 9317 11 0 98637 0
# \--- resident set size
~$ cat /proc/1782/status | grep Vm
VmPeak: 935584 kB
VmSize: 898484 kB
VmLck: 0 kB
VmHWM: 257608 kB
VmRSS: 186812 kB
VmData: 394328 kB
VmStk: 220 kB
VmExe: 44 kB
VmLib: 61544 kB
VmPTE: 1224 kB
VmSwap: 0 kB
My understanding is that VM is the amount of virtual memory and RSS is how much of it is resident in memory. So,
virtual memory = part in physical memory + part on disk
The part in physical memory is RSS. So, VSS should be greater than RSS. If they are close to equal, that means your process is sitting comfortably in memory. If VSS is much larger, that means there isn't enough memory and parts of it have to be swapped out to disk (i.e., because of a competing process, etc.).
On my system, I can do a "man proc" and it lists the following:
* VmPeak: Peak virtual memory size.
* VmSize: Virtual memory size.
* VmLck: Locked memory size (see mlock(3)).
* VmHWM: Peak resident set size ("high water mark").
* VmRSS: Resident set size.
* VmData, VmStk, VmExe: Size of data, stack, and text segments.
If you want to report the peak memory usage, then you probably want virtual memory, which looks like VmPeak.
Hope this helps!