How-to

The vmstat Command: A Quick Health Check for Linux

vmstat prints one line every few seconds with processes, memory, swap, I/O and CPU in a single row. It answers "what is this box short of" faster than any other tool.

How do I run vmstat?

vmstat 3 10
vmstat -w -t 5

The first number is the interval in seconds, the second the number of samples. Ignore the first line: it shows averages since boot, not current activity. -w widens the columns so large memory values do not run together, and -t adds a timestamp to each row, which helps when you save output to a file during an incident. vmstat is part of the procps package and comes with every image we install.

What do the columns mean?

GroupColumnMeaning
procsrTasks running or waiting for a CPU
procsbTasks blocked in uninterruptible sleep, usually on I/O
memoryswpd, free, buff, cacheSwap used, unused RAM, buffers, page cache, in KiB
swapsi, soKiB per second swapped in from and out to disk
iobi, boBlocks per second read from and written to devices
systemin, csInterrupts and context switches per second
cpuus, sy, id, wa, stUser, kernel, idle, I/O wait and stolen time in percent

Newer procps versions add a gu column for guest time from VMs you run yourself.

How do I spot a CPU bottleneck?

Watch r against your thread count from nproc. If r stays above it and id sits near zero, tasks are queuing for CPU. High sy next to high cs means the kernel spends a lot of time switching between tasks, common with too many worker threads. On bare metal st should always be 0; stolen time only appears inside a virtual machine whose host is busy, which is one reason people move from shared hosts to their own hardware.

How do I spot a memory problem?

Low free on its own is fine. Linux uses spare RAM as page cache, and the cache column shrinks when apps need memory. The warning sign is si and so: steady nonzero values mean the system pages memory to disk and back. Occasional small numbers are harmless. Thousands per second mean you are short of RAM. See Swap on Linux for tuning and Check memory usage for a per process view.

How do I spot a disk bottleneck?

A rising b column together with high wa points at storage. bi and bo show how much data moves. If the numbers are high but wa stays low, the drives keep up; NVMe drives handle huge throughput with little wait. For per device detail, use:

vmstat -d 2 3
vmstat -p /dev/nvme0n1p2
iostat -xz 2

-d prints reads, writes and time spent per disk. -p narrows to one partition.

What other modes does vmstat have?

vmstat -s | head -25          # one time memory and event counters
vmstat -a 2 5                 # active and inactive memory instead of buff and cache
vmstat -m | head              # kernel slab caches (needs root)
vmstat -S M 5                 # values in MiB

-S M makes memory columns readable on machines with hundreds of gigabytes. On M1 with 512 GB DDR4, KiB values run to nine digits and become hard to read without it.

What does a healthy vmstat look like?

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0  41210    412  18744    0    0    12   340 4210 7810  9  2 89  0  0

Two tasks running on a machine with plenty of threads, nothing blocked, no swapping, light writes and 89 percent idle. The box has room to grow.

How do I log vmstat for later?

nohup vmstat -t -w 10 8640 > /var/tmp/vmstat-$(date +%F).log 2>&1 &

That samples every 10 seconds for a full day. For permanent history, sysstat and sar do the same job with less effort; Linux load average shows how to read sar -q. vmstat stays the tool for the live "what is happening right now" question.

How does vmstat compare with top?

top shows which processes use resources. vmstat shows which resource is short. Use vmstat first to decide whether to look at CPU, memory or disk, then The top command to find the culprit.

Machines With Memory to Spare

ServerProcessorCores / threadsMemoryStorageNetworkPer monthSmallest order
S5Intel Xeon E-2276G6 / 12128 GB DDR42x 1 TB NVMe2x 10 Gbps$88.72$88.72 (1 month)
M12x Intel Xeon Gold 5315Y16 / 32512 GB DDR42x 4 TB NVMe2x 25 Gbps$414.70$414.70 (1 month)
M32x Intel Xeon Gold 632632 / 64512 GB DDR42x 4 TB NVMe2x 25 Gbps$518.60$518.60 (1 month)

Keep Reading

Linux load average

Understand the three load average numbers, how they relate to your core count, why disk waits raise them, and when a high load is a real problem.

Open

The top command

Read every line of top, use the keys that matter, save a layout and run it in batch mode for logs and scripts.

Open

Swap on Linux

What swap is for on a RAM-rich server, how to add a swap file on ext4 or XFS, zram as an alternative and how to tell useful swap from thrashing.

Open

Check memory usage

Read free, /proc/meminfo, vmstat and per-process numbers correctly, and tell real memory pressure apart from a healthy page cache.

Open

FAQ

Quick Answers

It shows averages since boot, not current activity.

Time stolen by a hypervisor. On bare metal it stays at zero.

Not by itself. Linux fills spare RAM with cache. Watch si and so instead.

Add -S M, for example vmstat -S M 5.

procps on Debian and Ubuntu, procps-ng on the RHEL family. Both are installed by default.