Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

vmstat Command Guide for Virtual Memory Statistics

vmstat reports memory, processes, paging, and CPU activity in one compact table, refreshing every interval — and its two most useful columns for spotting problems are si/so (swap in/out) and r (runnable processes).


What is vmstat?, and Why Use It?

vmstat stands for virtual memory statistics. It prints a table of system-wide counters: processes and run queue length, memory and swap usage, IO (block) activity, and CPU breakdown. Unlike free, which is a snapshot, vmstat can keep printing a row every few seconds, so you watch trends instead of catching one moment by luck.

It was written before htop and iostat existed, and it still earns its place: one command, no install, and a single row that tells you whether your problem is memory, CPU, or disk. When a machine feels slow, vmstat 1 is often the fastest way to find out which of the three it is.

Why Learn vmstat?

  • One row answers “which resource is the problem?” — high r means CPU-bound, high si/so means memory-bound, high bi/bo means disk-bound.
  • It shows trends, not snapshots — the interval mode catches what a single free or uptime check misses.
  • It is a classic triage tool — sysadmins have used it for decades; its output appears in thousands of forum answers and runbooks.
  • It is universally available — part of the sysstat/procps toolset on virtually every distro, works over SSH on a half-booted machine.

“The first row is the average since boot.” That is the rule that trips up everyone: pass an interval (vmstat 1) and ignore the first row when judging the current state.


1. Run It and Read the Output

vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 2097152 123456 8901234    0    0    12    34  800 1200  5  2 92  1  0
 2  0      0 2095104 123456 8901400    0    0     8    16  850 1300  7  3 89  1  0
 2  1      0 2090000 123480 8902001    0    0   400   120  900 1400 10  4 78  8  0
  • 1 — print a new row every 1 second.
  • 5 — stop after 5 rows (leave it off to run until Ctrl-C).

Read it in four groups:

GroupKey columnsMeaning
procsr, br = processes runnable (want CPU); b = blocked (usually waiting on disk)
memoryswpd, free, buff, cacheSwap used, untouched RAM, buffers, page cache
swapsi, soSwap in / swap out per second — nonzero sustained means memory pressure
io + cpubi, bo, us, sy, id, waBlocks in/out, plus CPU split: user, system, idle, waiting on IO

The health shortcut: us high → CPU-bound application. wa high → disk bottleneck. si/so nonzero → swap thrashing.

2. Why the First Row Is a Trap

The very first row printed is an average since boot, not a current reading. On a machine up for 30 days, that row says almost nothing about right now.

# WRONG: judging the machine by the boot-average first row
vmstat

# RIGHT: skip the first row; the interval rows are the live data
vmstat 1

Rule of thumb: always pass an interval when you are diagnosing a “right now” problem, and mentally discard row one.

3. Spot Memory Pressure and Swap Thrashing

This is the classic vmstat use case — the sibling of free:

vmstat 2
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 3  0 524288  102400  45000  210000 2450 1890   900   750 2000 3500 42 12 18 28  0
 4  1 524288  101000  45000  209500 2600 2100   880   800 2100 3600 45 14 15 26  0
  • swpd 524288 — half a GiB sits in swap.
  • si and so in the thousands — the kernel is actively shuffling pages between RAM and swap every second.
  • us moderate, wa high — the CPU spends real time waiting for swap IO.

This is thrashing: programs run but everything is slow. Cross-check which processes hold the memory with top (sort by M) and confirm the memory totals with free -h.

4. Spot CPU Saturation

The r column counts processes that want CPU. Compare it to your core count:

nproc
vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 9  0      0 1500000 200000 6000000    0    0    50    60 3000 5000 95  4  1  0  0
  • nproc prints 4 — four cores.
  • r 9 — nine runnable processes on four cores: the run queue is backed up.
  • us 95, id 1 — CPU is pegged in user space.

Sustained r greater than the core count plus near-zero id means you are CPU-bound. Find who with top or htop.

5. Spot Disk Bottlenecks

b (blocked) plus wa (IO wait) plus bi/bo (blocks in/out) tell the disk story:

vmstat 1
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  6      0 800000 150000 3000000    0    0 12000  8500 1500 2500 22  8 40 30  0
  • b 6 — six processes blocked on IO.
  • wa 30 — 30% of CPU time spent waiting for disk.
  • bi 12000 — heavy block-input rate.

The disk is the bottleneck. vmstat says that; iostat says which device, and top says which process.


Common Pitfalls

  • Reading the first row as current state — it is the boot average; always use an interval (vmstat 1) and ignore row one.
  • Confusing free memory with headroom — same rule as free: cache is good; judge pressure by si/so, not by the free column alone.
  • Blaming swap when it is idle — a nonzero swpd with si/so at 0 is healthy; only ongoing si/so is a problem.
  • Forgetting the columns are rates — with an interval of N, values like si/so/bi/bo are per-second averages over that window, not totals.
  • Treating vmstat as per-process — it is system-wide only; it can never name a process. Hand off to top or htop for that.
PageRelationship
freeMemory snapshot — the totals behind vmstat’s swap story
iostatPer-device disk detail vmstat only summarizes
uptimeLoad averages — a quicker “is it busy?” check
topNames the processes behind the system-wide numbers
htopInteractive per-process CPU/memory view

vmstat Cheatsheet

CommandWhat it does
vmstat 1New row every second — the live view (first row is the boot average)
vmstat 1 5Five rows one second apart, then exit
vmstat -sA single detailed summary of every counter since boot
vmstat -dPer-partition IO statistics
vmstat -wWider output that adds per-task thread counts
vmstat 2 | awk 'NR>2'Skip the boot-average row in a pipeline
si/so columnsSwap in/out per second — sustained nonzero means memory pressure
r vs nprocRunnable count vs cores — queue longer than cores means CPU saturation