From manpage of top

VIRT  --  Virtual Memory Size (KiB)
           The total amount of virtual memory used by the task.  It includes
           all code, data and shared libraries plus pages that have been
           swapped out and pages that have been mapped but not used.

USED  --  Memory in Use (KiB)
           This field represents the non-swapped physical memory a task has
           used (RES) plus the non-resident portion of its address space

It seems to me that VIRT and USED mean the same, i.e. they are both the sum of what a process occupies in the physical memory and what in the swap. So what are their differences and relations?

By the way, by default, top doesn't show USED. How can I make it visible?

2 Answers 2

  • RES is the amount of RAM currently used by the process. This value can vary because memory pages might be swapped in or out. It might even be 0 for a process that has been sleeping for a long time, e.g. an unsolicited daemon.

  • VIRT is the full size of all memory the process is using, whether in RAM or on disk (shared objects, mmaped files, swap area) so VIRT is always larger than or equal to RES. A process is always dealing with (i.e. allocating / accessing / freeing) virtual memory. It is up to the operating system to map some or all of these pages to RAM.

  • USED is less than VIRT because it doesn't include the memory that is backed by something else than swap, for example code and libraries.

  • +1 but riddle me this..shared objects (and similar) does not have to reside in RAM or swap? They can be simply on disk and referred to the disk location?
    – heemayl
    Jun 13, 2016 at 13:52
  • @heemayl They are either in RAM or in the file that originally contain them, no need to duplicate their storage in swap.
    – jlliagre
    Jun 13, 2016 at 15:26
  • Sorry for being a noob here, but before using those they should be brought to RAM, right?
    – heemayl
    Jun 13, 2016 at 15:51
  • @heemayl Only the part of these files that is actually required (i.e. addressed) need to be brought to RAM.
    – jlliagre
    Jun 13, 2016 at 15:53
  • 1
    @heemayl they do need to be in RAM when they're actively used (at least, the pages that are in use do), but they can be evicted at any time and loaded from disk later. This is different from anonymous pages which can't be evicted from RAM without being written to swap first.
    – hobbs
    Jun 13, 2016 at 18:47

RES means the actual memory assigned currently to the running process in (physical memory) resident in RAM.

VIRT shows virtual memory (assigned on the hard disk and/or RAM) to the process (as explained in the man page).

USED = RES + that part of the executable which currently not resides in RAM. ps shows VIRT using vsz flag.

  • Memory located in RAM (RES) might be swapped out in the future.
    – jlliagre
    Jun 13, 2016 at 15:51
  • Right, fixed the answer!
    – Vombat
    Jun 13, 2016 at 16:02
  • 1
    and VIRT is not necessarily assigned on the hard disk, might simply be in RAM and that's it.
    – jlliagre
    Jun 13, 2016 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.