Question

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
Was it helpful?

Solution

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!

OTHER TIPS

The RSS value of /proc/<pid>/stat is number of pages, whereas the VmRSS value of /proc/<pid>/status is in kB.

In your case, 46703 * 4kB (page size) = 186812 kB.

Man page for proc states following in statm context

/proc/[pid]/statm  
 Provides information about memory usage, measured in pages.  The columns are:  

  size       (1) total program size  
             (same as VmSize in /proc/[pid]/status)  
  resident   (2) resident set size  
             (same as VmRSS in /proc/[pid]/status)  
  share      (3) shared pages (i.e., backed by a file)  
  text       (4) text (code)  
  lib        (5) library (unused in Linux 2.6)  
  data       (6) data + stack  
  dt         (7) dirty pages (unused in Linux 2.6)  

But what it fails to state is that size and resident are expressed in number of pages.

~$ cat /proc/1782/statm
  224621 46703 9317 11 0 98637 0
#          \--- resident set size

Thus, 46703 is resident set size expressed in number of pages and 224621 is Virtual Memory Size expressed in number of pages as well.

Now to get them in KB multiply them with Page Size. You can get Page Size with getconf PAGESIZE command or in C/C++ program by calling sysconf(_SC_PAGE_SIZE) (defined in unistd.h). This will give you page size in bytes. Divide it with 1024 to get page size in KB.

Example :

$getconf PAGESIZE
4096

4096/1024 = 4 KB

Thus, resident set size in KB is 46703 x 4 = 186812 kB (VmRSS).
Total Program size in KB is 224621 x 4 = 898484 kB (VmSize)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top