Skip to content

Linux Foundations / Manage a Linux host ยท Step 37 of 50

Lesson: Monitoring disk I/OSwitch
โ† Linux Foundations

System administration

Monitoring disk I/O

Find out whether the disks are the bottleneck and which process is using them.

A machine can feel slow while its CPUs are mostly idle. A common cause is waiting for I/O, meaning input and output such as reading and writing disks.

First clues

In top, the wa figure shows CPU time spent idle while I/O was outstanding. In vmstat, watch these columns:

bash
$ vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  2      0 180000  80000 2500000   0    0   200   300  300  500  4  2 90  4  0
 0  3      0 178000  80000 2500000   0    0     0 85000  900 1200  2  6 40 52  0
 1  2      0 177000  80000 2500000   0    0     0 91000  950 1300  3  7 38 52  0

b counts processes blocked waiting for I/O to complete. bi and bo show data read from and written to block devices, in KiB per second. The first line is an average since boot.

Per device with iostat

iostat comes from the sysstat package, which you may need to install.

bash
$ iostat -dxz 1
Device     r/s    w/s   rkB/s    wkB/s  r_await  w_await  %util
sda       2.00 180.00   64.00 91000.00     3.10    45.60  98.00

This output is trimmed: real output has more columns, and they vary by version.

  • -d shows devices, -x extended statistics, -z hides idle devices
  • r_await and w_await are average milliseconds per request, including time queued
  • %util is the share of time the device had requests in progress

For a simple spinning disk, %util near 100 suggests saturation. SSDs and RAID arrays serve many requests in parallel, so they can show 100% and still have room. Check the wait times too. As with vmstat, the first report covers the time since boot.

Which process?

iotop shows I/O per process, like top. It is a separate package and normally needs root:

bash
sudo iotop -o      # only processes doing I/O now

From sysstat, this also works:

bash
pidstat -d 1

Without root it reports only on your own processes.

Note that df answers a different question: how full a filesystem is, not how busy the disk is.

Try it

Run vmstat 1 10 in one terminal. In another, write a file with dd if=/dev/zero of=testfile bs=1M count=500 conv=fsync, watch bo rise, then remove it with rm testfile. Make sure you have the free space first. The processes and cron lab has a shell to practise in.

Check your understanding

Monitoring disk I/O

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.