0

In the manpage of top,

What is the difference between USED and VIRT? USED is "RES" + "SWAP". Is "VIRT - USED" equal to pages that have been mapped but not used?

Does "VIRT" or "USED" include the size used by kernel space?

Does "RES" contain "CODE" and "DATA"?

What is "pgms"?

Thanks.

For each such process, every memory page is restricted to a single quadrant from the table below. Both physical memory and virtual
memory can include any of the four, while the swap file only includes #1 through #3. The memory in quadrant #4, when modified, acts as its own dedicated swap file.

                             Private | Shared
                         1           |          2
    Anonymous  . stack               |
               . malloc()            |
               . brk()/sbrk()        | . POSIX shm*
               . mmap(PRIVATE, ANON) | . mmap(SHARED, ANON)
              -----------------------+----------------------
               . mmap(PRIVATE, fd)   | . mmap(SHARED, fd)
  File-backed  . pgms/shared libs    |
                         3           |          4

The following may help in interpreting process level memory values displayed as scalable columns and discussed under topic `3a.
DESCRIPTIONS of Fields'.

  %MEM - simply RES divided by total physical memory
  CODE - the `pgms' portion of quadrant 3
  DATA - the entire quadrant 1 portion of VIRT plus all
         explicit mmap file-backed pages of quadrant 3
  RES  - anything occupying physical memory which, beginning with
         Linux-4.5, is the sum of the following three fields:
         RSan - quadrant 1 pages, which include any
                former quadrant 3 pages if modified
         RSfd - quadrant 3 and quadrant 4 pages
         RSsh - quadrant 2 pages
  RSlk - subset of RES which cannot be swapped out (any quadrant)
  SHR  - subset of RES (excludes 1, includes all 2 & 4, some 3)
  SWAP - potentially any quadrant except 4
  USED - simply the sum of RES and SWAP
  VIRT - everything in-use and/or reserved (all quadrants)

....

  1. USED -- Memory in Use (KiB) This field represents the non-swapped physical memory a task is using (RES) plus the swapped out portion of its address space (SWAP).

    See `OVERVIEW, Linux Memory Types' for additional details.

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

    See `OVERVIEW, Linux Memory Types' for additional details.

1 Answer 1

1

What is the difference between USED and VIRT? USED is "RES" + "SWAP". Is "VIRT - USED" equal to pages that have been mapped but not used?

Yes. In general, this is space that's been allocated by the program that it just never touched (lots of stuff allocates in large chunks, quite often overallocating, because allocating space is computationally expensive).

Does "VIRT" or "USED" include the size used by kernel space?

Neither of them accounts for space allocated on the process's behalf in kernel-space. In most cases, this just doesn't matter because most programs simply don't use much space in the kernel's memory.

Does "RES" contain "CODE" and "DATA"?

Yes, but not necessarily all of both of them. Both CODE and DATA may reside partially in SWAP (they can actually reside entirely in SWAP, but only if the process isn't actually executing any code at the time).

1
  • Thanks. What is "space allocated on the process's behalf in kernel-space" used for?
    – Tim
    Oct 29, 2018 at 20:31

You must log in to answer this question.

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