21

Using ps, I can see the size, the vsize (same as top's VIRT?), and the rss (same as top's RES?). (One more I see in top is SHR.)

Could someone summarize for me what these different fields mean?

1
  • I'd rather see a nice summary on this page than a link that might disappear so that this page can live as a reference. Jul 31, 2009 at 15:53

2 Answers 2

39

In short:

  • Virtual size: is the amount of address space that a process is managing. The virtual address space contains everything that the process can access through pointers (memory address references). For example, if your program gets access to the framebuffer of your video card, that memory is mapped to the process virtual space and receives an address that is stored to a pointer. Memory-mapped files and anonymous mappings are also accounted into the virtual address space size. Pretty much everything is in the virtual size. If you sum up the size of all address ranges listed in /proc/<pid>/maps, it should return you roughly the same value of the virtual size.

  • Resident size: is the amount of memory that belongs specifically to that process that is currently resident in memory. That means, the amount of memory that is not in swap. Note that parts of the process can be in swap memory even when the process is running. The operating system will pull these regions from the swap when the process tries to access it. This should include the heap, the stacks of all threads and other private mappings. If you look in /proc/<pid>/maps, the [stack], [heap] and other anonymous mappings (those without file paths) are either swapped or accounted in the resident size.

  • Shared size: is the amount of memory that may belong to multiple processes. For example, if you have four instances of the same application loaded in memory, you will have four instances of the heap and at least four stacks, one for each process (this is the resident memory), but you will have only one instance of the binary code of the program and its libraries. This is the shared space. Not only it includes the program binary code and its libraries, but also localization files, read-only program data, SysV and POSIX shared memory segments, semaphores, etc... If you look in /proc/<pid>/maps, most mappings tied to library and program files are shared.

Note that VIRT contains the union of RSS and SHR, and will always be greater than any one of them. There may be regions accounted as both RSS and SHR.

2
  • 3
    Incidentally, on recent versions of linux you can see a very detailed breakdown of memory usage in /proc/<pid>/smaps
    – bdonlan
    Jul 31, 2009 at 17:26
  • 3
    Shared size is memory that may be shared. If an application is sole user of library the library will be kept in memory by single process. This way even shared memory can be "process owned" memory. Dec 31, 2012 at 10:33
6

In Juliano answer:

Note that RSS + SHR <= VIRT, always.

This is just false. SHR contains all virtual memory that could be shared with other processes, and RSS contains all memory physically in RAM that is used by the process.

Thus all shared memory currently in RAM is counted both in SHR and in RSS, so SHR + RSS has no meaning since it can contain duplicates counts.

To construct a process with RSS + SHR > VIRT, just mmap a large file (1GB), then read it completely: the mmaped file will be loaded in RAM, and VIRT, SHR and RSS will each be slighly larger than 1GB, so SHR + RSS > VIRT.

1
  • Yeah, it was more of a statement about VIRT than the other two. What I had in mind was more about the union of RSS and SHR than their sum, i.e. VIRT contains both RSS and SHR. Poor mathematical representation.
    – Juliano
    Sep 5, 2017 at 0:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .