vmstat & iostat
vmstat fields for system-level stats, iostat -x for disk I/O deep-dive, and await vs svctm.
Overview
vmstat and iostat provide system-wide and per-device performance statistics at a level of detail that top doesn't offer. vmstat shows the whole machine at a glance: processes, memory, swap, disk blocks, interrupts and CPU. iostat then zooms in on each disk, which is where you go once vmstat points at I/O.
Reading vmstat
Run vmstat 1 to print a new sample every second. The first row after the header is averages since boot, so ignore it; every row after it is a 1-second sample.
The columns come in six groups.
- procs: r is the number of processes in the run queue, waiting for CPU. b is the number in uninterruptible sleep (D state), blocked on I/O.
- memory: swpd is swap used, free is free RAM, buff is the buffer cache (block I/O) and cache is the page cache (file data). On Linux, free RAM is intentionally low, because the OS uses it for cache.
- swap: si is swap in, in KB/s: pages being read from swap into RAM. so is swap out, in KB/s: pages being written to swap. Any nonzero si or so means active swapping, which is a serious performance problem.
- io: bi is blocks in (read from disk) and bo is blocks out (written to disk), counted in 1,024-byte blocks per second.
- system: in is interrupts per second and cs is context switches per second. A very high cs (above 100,000/sec) with low CPU can indicate excessive threading or system calls.
- cpu: the same columns as top's CPU line, us sy id wa st.
Key concepts
- vmstat r/b columns
- si/so for swap activity
- iostat await vs %util
- aqu-sz queue length
Interview questions
- You see vmstat showing si and so values consistently above 0. What does this mean and how urgent is it?
- Explain the difference between await and svctm in iostat -x output. What does a large gap between them indicate?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio