RAM and Virtual Memory: vmstat

RAM Overview
Technical articles

Memory Shortages and vmstat
UNIX memory shortages impact performance once virtual memory is impacted. Therefore, when we are investigating possible memory shortages, we are investigating virtual memory as well. vmstat is an essential tool for diagnosing these issues.

vmstat can show:
  • How much swap is being used                      
  • How the physical memory is being used
  • How much memory is free    

Note:  vmstat can also be used for analyzing cpu usage .

The following arguments can be used when investigating memory statistics 
vmstat [-a] [-s] [-m] [delay [count]]

The options are:
  • -a indicates active/inactive memory rather than information about buffer and cache usage
  • -s Cannot be run in sample mode. Prints out vm table, which is memory and CPU statistics since the system was booted
  • -m For analyses of kernel’s memory usage. Same output as cat /proc/slabinfo. Gives details on how the kernel’s memory is allocated, which can be helpful for determining what area of the kernel is consuming the most memory.

The modes of vmstat
It is useful to think of vmstat having two modes:
  • Average mode
  • Sampling mode

The first line is average mod.

If delay parameter is specified, subsequent lines are sample mode. vmstat is most useful in sampling mode.

delay: The amount of seconds delay before the next line is displayed

count: The amount of lines displayed

vmstat Output
vmstat output has a header that takes up two lines. The first line indicate categories of output and the second line the specific fields within those categories.

The categories and their associated fields are:
  • procs (processes)
    • r: run queue (number of processes waiting for run time)
    • b: number of processes in uninterruptable sleep (i.e., blocked for resources such as I/O, paging, et cetera)
  • memory (RAM usage)
    • swpd: amount of virtual memory used
    • free: amount of idle memory
    • buff: amount of memory used as buffers
    • cache: amount of memory used as cache
    • inact: amount of inactive memory (appears with -a option)
    • active: amount of active memory (appears with -a option)
  • swap (pages pulled in and out of swap)
    • si: amount of memory swapped in from disk (/s) (per second)
    • so: amount of memory swapped out from disk (/s) (per second)
  • io (input/output, i.e., disk usage)
    • bi: blocks received from a block device (blocks/s)
    • bo: blocks sent to a block device (blocks/s)
  • system (number of times kernel switches into kernel code)
    • in: the number of interupts per second
    • cs: the number of context switches per second
  • cpu (percentages of total cpu time)
    • us: user time (running non-kernel code)
    • sy: system time (running kernel code) us: user time (running non-kernel code)
    • id: idle time
    • wa: waiting for I/O
    • st: stolen from a virtual machine

Suggestions for Future Learning
This information will be in the second edition of UNIX For Application Support Staff . The ETA for the second edition is December 1, 2016.

RAM Overview
Technical articles