|
Oct
04
|
VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card’s RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.
RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.
SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.
August 4th, 2010 at 5:11 pm
I’ve been asked this question on many job interviews and have seen it asked many times and have since started asking it when I interview people. Many people don’t have a clear understanding of these differences. Your article summed it up in a very clean, straight forward manner. Thanks!
November 4th, 2010 at 4:34 pm
Thank you! Very useful and clear
January 27th, 2011 at 4:50 am
Hold on so are you saying that this:
22120 apache 15 0 317m 31m 4468 S 0.0 1.8 0:00.69 httpd
means one apache http request is using 317MB of ram total and 31MB allocated to the httpd request?
That seems like alot!
:0
May 16th, 2011 at 3:19 pm
how about DATA and CODE? and why DATA + CODE RES?
September 2nd, 2011 at 3:07 am
thanks a lot!
September 20th, 2011 at 5:52 pm
Zane Kolnik has an interesting question i’m trying to find the answer to. Those columns, RES, VIRT and SHR sometimes have the ‘m’ character appended to the end of the value; does this mean “million” or “megebytes”? none of those sounds right. the man page says those values are in kb, but 317′million’ kb doesn’t make sense.
September 28th, 2011 at 9:49 am
maxl: The ‘m’ stands for ‘mega’. (Note the ‘a’ at the end.)
If you have a process take up enough memory, it will have a ‘g’ as the suffix, as in ‘giga’.
October 4th, 2011 at 1:24 pm
SHR in fact doesn’t reliably show how much of VIRT is shareable, as it doesn’t account for the IPC mechanism called shared memory (SHM). This gives a huge error for example with “postgres” processes, where most of VIRT is taken by the big chunk of writable shared memory that all “postgres” processes share. So, if you have a connection pool of 4 connections, you will constantly see 4 “postgres” processes, each with, let’s say, 50 MB of VIRT size and only 5M of SHR, and you believe these then eat up (50 VIRT – 5 SHR) * 4 = 180 MB-s, where in fact they only eat up (50 VIRT – 38 SHM – 5 SHR) * 4 + 38 SHM = 66 MB.
(BTW, this reply form is a crap. Not only it doesn’t re-fill the form for you when there’s something to fix, when stepping back after the error message it somehow manages to prevent FireFox from restoring its earlier content…)
January 31st, 2012 at 8:10 pm
Nice review. Does the VIRT column corresponds to the Memory cached and buffer size?