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.
vmstat [OPTIONS] [DELAY [COUNT]]
Try it
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.
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
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.
rconsistently above the number of cores means CPU contention. Seenprocanduptime. - Swapping is the signal. Non-zero
siandsoover many lines means the system is short of memory. A staticswpdis harmless. - High
wawith lowusandsymeans the CPU is idle because the disk (or network filesystem) is slow.brises with it. Follow up withvmstat -dorlsof. - High
ston a virtual machine means the hypervisor is giving CPU time to others. - Memory columns are not a full picture.
freeis low on healthy systems; usefreeand itsavailablecolumn to judge. - Parsing.
vmstat 1 2 | tail -1gives the most recent one-second sample. Fields are separated by variable spaces, so useawk, notcut -d' '. - Cost.
vmstatis very light, so leavingvmstat 5running during an incident is safe. - Units. Blocks for
biandboare 1024 bytes in current procps versions.
Related
free,uptime,top,lsof,/proc/meminfo- Lessons: Processes, Tracing and Profiling