Skip to main content

vmstat — Virtual Memory and CPU Statistics

vmstat reports a compact set of system activity metrics: runnable processes, memory, swap, I/O, interrupts, context switches, and CPU usage. Use it when WordPress feels slow and you suspect swapping, I/O wait, or CPU saturation. Unlike free, which is a snapshot, vmstat is most useful when sampled repeatedly (for example every second).

Quick Summary

Run vmstat 1 5 and watch si/so (swap in/out) and wa (I/O wait). Sustained swap activity or high I/O wait often correlates with slow page loads.

Reading the Columns (Mental Model)

vmstat-column-groups.txt
procs -> r (run queue), b (blocked)
memory -> swpd, free, buff, cache
swap -> si (swap in), so (swap out)
io -> bi (blocks in), bo (blocks out)
system -> in (interrupts), cs (context switches)
cpu -> us, sy, id, wa, st

Prerequisites

vmstat is provided by procps/procps-ng and is installed by default on most Linux servers.

Verify it exists:

verify-vmstat-installed.sh
which vmstat
vmstat -V

Core Syntax

vmstat-syntax.sh
vmstat [options] [delay [count]]
  • delay is the sampling interval in seconds.
  • count is the number of samples.

Key Options

OptionWhat it doesExampleWordPress / VPS use case
delay countSample repeatedlyvmstat 1 5Observe real-time pressure
-wWide outputvmstat -w 1 5Easier to read on modern systems
-tAdd timestampvmstat -t 1 5Correlate with logs
-ySkip the first report linevmstat -y 1 5Avoid the "since boot" first sample
-sSummary statisticsvmstat -sBaseline counters
-dDisk statisticsvmstat -dQuick disk activity counters
-p <dev>Partition statisticsvmstat -p sda1Target a specific partition
-aActive/inactive memoryvmstat -a 1 5Memory behavior under load

Examples (Commands + Expected Output)

Output varies

Column meanings stay consistent, but exact values depend on workload.

Sample every second (5 samples)

vmstat-sample-1s-5.sh
vmstat 1 5

Expected output:

example-output-vmstat-1-5.txt
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 20000 100000 60000 900000 0 0 1 2 120 300 5 2 90 3 0
0 0 20000 90000 60000 910000 0 0 0 1 110 280 4 2 92 2 0

Use case: Spot swap (si/so) and I/O wait (wa) during slow requests.

Wide output

vmstat-wide-output.sh
vmstat -w 1 3

Expected output:

example-output-vmstat-wide.txt
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- ----------cpu----------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 20000 90000 60000 910000 0 0 0 1 110 280 4 2 92 2 0

Use case: Better readability when columns would otherwise wrap.

Add timestamps

vmstat-with-timestamps.sh
vmstat -t 1 3

Expected output:

example-output-vmstat-timestamp.txt
... (columns omitted)
0 0 20000 90000 60000 910000 0 0 0 1 110 280 4 2 92 2 0 2026-03-01 10:05:01

Use case: Correlate spikes with application logs.

Skip the first "since boot" report

vmstat-skip-first-line.sh
vmstat -y 1 3

Expected output:

example-output-vmstat-no-first.txt
... (only sampled lines, not the initial summary)

Use case: Focus on current behavior instead of boot-averaged counters.

Summary statistics

vmstat-summary-stats.sh
vmstat -s

Expected output:

example-output-vmstat-s.txt
2048000 K total memory
900000 K used memory
100000 K free memory
20000 K swap used

Use case: Baseline counters and totals.

Disk statistics

vmstat-disk-stats.sh
vmstat -d

Expected output:

example-output-vmstat-d.txt
disk- ------------reads------------ ------------writes----------- -----IO------
total merged sectors ms total merged sectors ms cur sec
sda 10000 200 800000 12000 5000 100 200000 8000 0 10

Use case: Quick disk activity counters (pair with iostat for deeper detail).

WordPress VPS Use Cases

SymptomWhat to watchCommandInterpretation
Site slow under loadwa and rvmstat 1 10High wa suggests disk bottleneck; high r suggests CPU saturation
Uploads failingsi/so and freevmstat 1 10Swap activity indicates memory pressure
DB-heavy queries slowwa + bovmstat 1 10Disk write pressure can slow MySQL

Troubleshooting

ObservationLikely causeNext step
si/so stays > 0Active swappingCheck memory with free -h; identify top memory processes
wa is consistently highDisk I/O waitUse iostat -xz 1 5 and review storage
r is high vs CPU coresCPU contentionCheck top/htop and per-CPU with mpstat

Best Practices

  • Use vmstat as a time series (vmstat 1 10), not a single sample.
  • Skip the first line with -y when you're focused on current behavior.
  • Pair with free, top, and iostat to confirm the root cause.
Cheat Sheet
vmstat-cheat-sheet.sh
vmstat 1 5
vmstat -w 1 5
vmstat -t 1 5
vmstat -y 1 5
vmstat -s
vmstat -d
vmstat -p sda1
vmstat -a 1 5

What's Next