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).
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)
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:
which vmstat
vmstat -V
Core Syntax
vmstat [options] [delay [count]]
delayis the sampling interval in seconds.countis the number of samples.
Key Options
| Option | What it does | Example | WordPress / VPS use case |
|---|---|---|---|
delay count | Sample repeatedly | vmstat 1 5 | Observe real-time pressure |
-w | Wide output | vmstat -w 1 5 | Easier to read on modern systems |
-t | Add timestamp | vmstat -t 1 5 | Correlate with logs |
-y | Skip the first report line | vmstat -y 1 5 | Avoid the "since boot" first sample |
-s | Summary statistics | vmstat -s | Baseline counters |
-d | Disk statistics | vmstat -d | Quick disk activity counters |
-p <dev> | Partition statistics | vmstat -p sda1 | Target a specific partition |
-a | Active/inactive memory | vmstat -a 1 5 | Memory behavior under load |
Examples (Commands + Expected Output)
Column meanings stay consistent, but exact values depend on workload.
Sample every second (5 samples)
vmstat 1 5
Expected output:
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 -w 1 3
Expected output:
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 -t 1 3
Expected output:
... (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 -y 1 3
Expected output:
... (only sampled lines, not the initial summary)
Use case: Focus on current behavior instead of boot-averaged counters.
Summary statistics
vmstat -s
Expected output:
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 -d
Expected output:
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
| Symptom | What to watch | Command | Interpretation |
|---|---|---|---|
| Site slow under load | wa and r | vmstat 1 10 | High wa suggests disk bottleneck; high r suggests CPU saturation |
| Uploads failing | si/so and free | vmstat 1 10 | Swap activity indicates memory pressure |
| DB-heavy queries slow | wa + bo | vmstat 1 10 | Disk write pressure can slow MySQL |
Troubleshooting
| Observation | Likely cause | Next step |
|---|---|---|
si/so stays > 0 | Active swapping | Check memory with free -h; identify top memory processes |
wa is consistently high | Disk I/O wait | Use iostat -xz 1 5 and review storage |
r is high vs CPU cores | CPU contention | Check top/htop and per-CPU with mpstat |
Best Practices
- Use
vmstatas a time series (vmstat 1 10), not a single sample. - Skip the first line with
-ywhen you're focused on current behavior. - Pair with
free,top, andiostatto confirm the root cause.
Cheat Sheet
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