Watching Linux disks with iotop and iostat

Summary

On Hackaday, Al Williams presents tools that quickly show what the disks of a Linux system are doing. iotop shows read and write load per process, iostat per device, duf the used space at a glance and lsof the open files. As an addition he mentions atop, which combines process and disk load in one view.

Per process or per device

iotop works like top but sorts by input and output. The o key or the -o switch hides idle processes; other keys switch to threads or set the ionice priority. iostat from the sysstat package summarises per device instead; iostat -t 5 prints a report with timestamp every five seconds, -x adds extended values and -z hides devices without activity.

atop shows a summary at the top with DSK lines that change colour under high load. The d key switches to the disk view, D sorts by disk load.

Space and open files

duf replaces df with a readable table and can filter and sort by device type. lsof lists open files; wildcards do not work, so lsof /home/alw only shows who has exactly this directory open.

For the contents of a directory there are dedicated options: according to the manual, lsof +d searches one level deep and lsof +D recursively.

Ideas

  • iotop finds the process currently loading the disk.
  • iostat answers the same question per device instead of per process.
  • iotop's -o option hides idle processes.
  • duf makes used storage space readable at a glance.
  • lsof shows who holds a file or directory open.
  • atop combines process and disk load in one view.

Insights

  • The right question, process or device, determines the right tool.
  • An overview in seconds does not replace monitoring with history, but it shortens troubleshooting.

Facts

  • iostat belongs to the sysstat package.
  • lsof searches a directory one level deep with +d and recursively with +D.
  • The kernel's delay accounting is disabled at boot; iotop shows SWAPIN and IO% only after sysctl kernel.task_delayacct=1, and only for processes started afterwards.
  • Debian Trixie includes duf 0.8.1.

References

Critique

  • The article names the lsof options -d and -D; correct are +d and +D, because -d selects file descriptors.

Remarks

  • iotop needs root privileges; without them the process list stays empty or the program aborts.

Recommendations

  • Set kernel.task_delayacct=1 only for the duration of a measurement, because the accounting costs some performance.
  • Use iostat -xz 5 to see busy devices without noise.
  • Look for processes with lsof +D before unmounting a file system.

Read the original article

Search the Web Archive

Found a mistake or have something to add? Get in touch.