Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Processes and Signals

Linux vmstat command

Reference for the Linux vmstat command: read the procs, memory, swap, io, system and cpu columns, sample at intervals, and spot memory pressure or I/O waits.

vmstat reports virtual memory statistics together with process, block I/O, interrupt and CPU figures, all in one compact table. Run with a delay (vmstat 1) it prints a new line every second, which makes trends visible: a growing run queue, swapping, a disk that cannot keep up.

The first line is special: it shows averages since boot, not the current second. Every following line covers the interval you chose, and those are the lines to read.

Terminal
vmstat [OPTIONS] [DELAY [COUNT]]

Try it

Bash The columns and the sampling rule

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Interpreting a sample

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
vmstat [-a] [-w] [-n] [-S UNIT] [-t] [DELAY [COUNT]]
vmstat -s | -d | -D | -p DEVICE | -f
Option Description
DELAY Seconds between reports. Without it, one report (the average since boot) is printed.
COUNT Number of reports. Without it and with a delay, runs until interrupted.
-a Show active and inactive memory instead of buffers and cache.
-w Wide output, for large numbers.
-n Print the header only once.
-S k|K|m|M Unit for memory columns (1000 or 1024 based). The default is KiB.
-s Print a table of event counters and memory totals, then exit.
-d Per-disk statistics.
-p DEVICE Statistics for one partition.
-t Add a timestamp column.
-f Number of forks since boot.
Column Meaning
r Processes ready to run (the run queue).
b Processes in uninterruptible sleep, usually waiting for I/O.
swpd, free, buff, cache Swap in use, unused memory, buffers and page cache.
si, so Memory swapped in from and out to disk (per second).
bi, bo Blocks received from and sent to block devices (per second).
in, cs Interrupts and context switches per second.
us, sy, id, wa, st CPU time: user, kernel, idle, waiting for I/O, stolen by the hypervisor.

Returns: 0 on success; non-zero for bad options or when /proc cannot be read.

Usage notes

  • Skip the first line. The first sample is the average since boot. For current behavior look at the second line onwards.
  • Run queue versus CPUs. r consistently above the number of cores means CPU contention. See nproc and uptime.
  • Swapping is the signal. Non-zero si and so over many lines means the system is short of memory. A static swpd is harmless.
  • High wa with low us and sy means the CPU is idle because the disk (or network filesystem) is slow. b rises with it. Follow up with vmstat -d or lsof.
  • High st on a virtual machine means the hypervisor is giving CPU time to others.
  • Memory columns are not a full picture. free is low on healthy systems; use free and its available column to judge.
  • Parsing. vmstat 1 2 | tail -1 gives the most recent one-second sample. Fields are separated by variable spaces, so use awk, not cut -d' '.
  • Cost. vmstat is very light, so leaving vmstat 5 running during an incident is safe.
  • Units. Blocks for bi and bo are 1024 bytes in current procps versions.