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.

written by MG


9 Responses to “The difference among VIRT, RES, and SHR in top output”

  1. 1. Nick Says:

    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!

  2. 2. upen Says:

    Thank you! Very useful and clear

  3. 3. Zane Kolnik Says:

    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

  4. 4. hash Says:

    how about DATA and CODE? and why DATA + CODE RES?

  5. 5. gilm Says:

    thanks a lot! :)

  6. 6. maxl Says:

    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.

  7. 7. Victor Says:

    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’.

  8. 8. ddekany Says:

    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…)

  9. 9. bioknight Says:

    Nice review. Does the VIRT column corresponds to the Memory cached and buffer size?

Leave a Reply

*