23

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
lupz
  • 3,620
  • 2
  • 27
  • 43

3 Answers3

46

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.

Takashi Oguma
  • 744
  • 1
  • 6
  • 7
  • 2
    @lupz, consider validating this answer which seems correct. as documented in [proc(5)](http://linux.die.net/man/5/proc) manpage. – Franklin Piat May 29 '15 at 09:54
25

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!

Ray
  • 880
  • 1
  • 10
  • 18
  • I don't know where to get the value from proc, but I think my pagesize is 4KB. I was confused by VmPTE. It seems to be rather the 'size of [pid]s part of the page table', then the 'size of a buffer entry' :) – lupz May 04 '12 at 10:08
  • 1
    Yes, a lot of these values are system-dependent. In some systems I've worked with, some of those values will always give a 0 because support has not been compiled into the kernel. So yes, don't believe what my man pages say as they may not be relevant to your system. – Ray May 07 '12 at 02:12
  • 11
    Actually, virtual memory = part in RAM + part on disk + virtual address space not mapped to physical memory + memory mapped files + shared memory. So to measure memory consumption, VmSize is pretty useless. See the first answer to http://stackoverflow.com/questions/13308684/increase-of-virtual-memory-without-increse-of-vmsize – vcarel Jan 23 '14 at 10:30
13

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)

Dr. Xperience
  • 475
  • 1
  • 5
  • 18