It’s also possible on Linux to get per process I/O statistics, so you can see exactly who is reading and writing heavily, using a program named iotop. iotop needs to be started with the root user. You can use iotop, for example, to learn how fast your hard disk can read and write, then press the q key to exit. Read the manual section on iotop to learn more about its shortcuts, for example, for sorting columns.
In order to view which process is writing to disk we can use “iotop” command to get that information
# iotop
It displays an output like the following example:
Total DISK READ : 0.00 B/s | Total DISK WRITE : 88.95 M/s Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 88.95 M/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 27236 be/4 root 0.00 B/s 88.95 M/s 0.00 % 87.91% dd if=/dev/zero of=test.zero bs=1024k count=1000 oflag=direct conv=notrunc 25600 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % less -s 1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 22 2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd] 3 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0] 6 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/u30:0] 7 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_sched] 8 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_bh] 9 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcuos/0] 10 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcuob/0] 11 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0] 12 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [watchdog/0] 13 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [khelper] 14 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kdevtmpfs] 15 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [netns] 16 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [perf] 17 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [xenwatch] 18 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [xenbus] 20 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [khungtaskd] 21 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [writeback] 22 be/5 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksmd] 23 be/7 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [khugepaged] 24 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [crypto] 25 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kintegrityd] 26 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [bioset] 27 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kblockd] 28 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [md] 29 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [devfreq_wq] 31 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kswapd0] 32 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [fsnotify_mark] 1058 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % cupsd -f
Of the columns presented here, we may be interested in the following:
- TID: This column provides the PID of the process that makes I/O requests. This can be used to investigate or terminate the program.
- DISK READ: This column illustrates the number of bytes read per second by the listed process.
- DISK WRITE: This column details the number of bytes written per second by the listed process.
- IO: This column shows the percentage of time that the listed process spent issuing I/O requests.
- COMMAND: This column depicts the name of the process that handles I/O. If this is a master process, it might include command-line switches as well.
In the above example we ran in another ssh session a dd test (dd if=/dev/zero of=test.zero bs=1024k count=1000 oflag=direct conv=notrunc) to view the W/R action going onto the disk.
If you want to see only the current processes writing to disk, press “o” key and you will get output like:
Total DISK READ : 0.00 B/s | Total DISK WRITE : 86.90 M/s Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 86.90 M/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 27239 be/4 root 0.00 B/s 86.90 M/s 0.00 % 89.17 % dd if=/dev/zero of=test.zero bs=1024k count=1000 oflag=direct conv=notrunc
The following are some of the most common options we can use:
- Hit the left and right arrow keys to change the sorting.
- Hit r to reverse the sorting order.
- Hit o only to see processes or threads actually doing I/O, instead of showing all processes or threads.
- Hit p only show processes. Normally iotop shows all threads.
- Hit a display accumulated I/O instead of bandwidth. In this mode, iotop shows the amount of I/O processes have done since iotop started.
- Hit i to change the priority of a thread or a process thread(s) i.e. ionice.
- Hit q to quit iotop.
Refer to the man pages for further information.
# man iotop