Disk read and write or I/O activities affect the general performance of a system. It's often overlooked as some admins will only look into CPU activity when the system starts to slow down. The other aspect to look into when troubleshooting disk activity issue is disk latency.

Many Linux tools can be used to check disk activity, though generally, they're just another version of iostat and iotop. iostat monitors the I/O of block devices while iotop monitors the I/O of running processes. Another useful disk activity monitoring tool for Linux is ioping which monitors latency.

iostat, iotop and ioping can be installed and run from the terminal.

Steps to monitor disk I/O in Linux:

  1. Launch terminal.
  2. Install sysstat package for your distribution.

    $ sudo apt update && sudo apt install --assume-yes sysstat # Ubuntu and Debian derivatives $ sudo yum install --assumeyes sysstat # Red Hat and CentOS derivatives

  3. View I/O for all block devices using iostat.

    $ iostat Linux 5.8.0-48-generic (host) 	Jumaat 09 Apr 2021 	_x86_64_	(2 CPU)  avg-cpu:  %user   %nice %system %iowait  %steal   %idle            0.25    0.01    0.18    0.01    0.00   99.54  Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd loop0             0.00         0.02         0.00         0.00       1080          0          0 loop1             0.00         0.01         0.00         0.00        359          0          0 loop10            0.01         0.27         0.00         0.00      13555          0          0 loop11            0.00         0.00         0.00         0.00         14          0          0 loop2             0.00         0.02         0.00         0.00       1095          0          0 loop3             0.00         0.01         0.00         0.00        348          0          0 loop4             0.00         0.01         0.00         0.00        347          0          0 loop5             0.00         0.02         0.00         0.00       1073          0          0 loop6             0.00         0.01         0.00         0.00        350          0          0 loop7             0.01         0.28         0.00         0.00      13967          0          0 loop8             0.00         0.01         0.00         0.00        362          0          0 loop9             0.00         0.01         0.00         0.00        358          0          0 sda               2.95        16.00        95.17         0.00     800785    4762513          0 sdb               0.00         0.06         0.00         0.00       3233         12          0 sr0               0.00         0.00         0.00         0.00          2          0          0

  4. View I/O for a specific disk or block device on a set interval using iostat.

    $ iostat /dev/sda -y 5 Linux 5.8.0-48-generic (host) 	Sabtu 10 Apr 2021 	_x86_64_	(2 CPU)   avg-cpu:  %user   %nice %system %iowait  %steal   %idle            3.67    0.00    2.73    0.00    0.00   93.60  Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd sda               0.40         0.00         2.40         0.00          0         12          0   avg-cpu:  %user   %nice %system %iowait  %steal   %idle            4.73    0.00    2.52    0.00    0.00   92.75  Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd sda               0.00         0.00         0.00         0.00          0          0          0   avg-cpu:  %user   %nice %system %iowait  %steal   %idle            3.70    0.00    3.28    0.00    0.00   93.02  Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd sda              31.00         0.00       169.60         0.00          0        848          0

  5. Install iotop for your Linux distribution.

    $ sudo apt update && sudo apt install --assume-yes iotop # Ubuntu and Debian derivatives $ sudo yum install --assumeyes iotop # Red Hat and CentOS derivatives

  6. Monitor disk activity for all running processes in almost realtime using iotop.

    $ sudo iotop [sudo] password for user: Total DISK READ:         0.00 B/s | Total DISK WRITE:         0.00 B/s Current DISK READ:       0.00 B/s | Current DISK WRITE:       0.00 B/s     TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                                                                                                                                                                                                                                                                                                                   1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % init splash       2 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthreadd]       3 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_gp]       4 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_par_gp]       6 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/0:0H]       9 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [mm_percpu_wq]      10 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/0]      11 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_sched]      12 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/0]      13 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [idle_inject/0]      14 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [cpuhp/0]      15 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [cpuhp/1]      16 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [idle_inject/1]      17 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/1]      18 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/1]      20 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/1:0H-kblockd]      21 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kdevtmpfs]      22 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [netns]      23 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_tasks_kthre]      24 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_tasks_rude_]      25 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_tasks_trace]

  7. Monitor only processes with I/O activity using iotop.

    $ sudo iotop -o Total DISK READ:         0.00 B/s | Total DISK WRITE:       125.32 K/s Current DISK READ:       0.00 B/s | Current DISK WRITE:     148.82 K/s     TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                                                                                                                                                                                                                                                                                                                7165 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.04 % [kworker/u256:1-events_freezable_power_]     316 be/3 root        0.00 B/s  125.32 K/s  0.00 %  0.03 % [jbd2/sda3-8]

  8. Install ioping for your Linux distribution.

    $ sudo apt update && sudo apt install --assume-yes ioping # Ubuntu and Debian derivatives $ sudo yum install --assumeyes ioping # Red Hat and CentOS derivatives

  9. Check disk latency using ioping.

    $ sudo ioping /dev/sda 4 KiB <<< /dev/sda (block device 20 GiB): request=1 time=1.13 ms (warmup) 4 KiB <<< /dev/sda (block device 20 GiB): request=2 time=1.50 ms 4 KiB <<< /dev/sda (block device 20 GiB): request=3 time=2.49 ms 4 KiB <<< /dev/sda (block device 20 GiB): request=4 time=1.11 ms 4 KiB <<< /dev/sda (block device 20 GiB): request=5 time=807.4 us 4 KiB <<< /dev/sda (block device 20 GiB): request=6 time=2.02 ms