Identify disk/swap hungry processes with iotop

cd

If you need to find out what processes on your desktop or server are doing a lot of disk I/O (reads/writes) or swapping in and out of memory a lot, then take a look at iotop.

Reading time:
2 min

What is iotop?

Iotop is a top-like program (written in python) for investigating/monitoring process disk and swap space usage. Iotop displays the disk and swap usage information as it happens. You can use iotop to identify which processes on your system are keeping your hard drive busy with reads and/or writes. You can also use it to determine which processes (if any) are swapping in the most or even thrashing swap space.

Installation

To install iotop, use:

sudo apt-get install iotop

To start iotop, just run the command:

sudo iotop

(Hit q to exit).

To only show IO happening now

You can use iotop in several modes, depending on what your aiming to do. If you want to immediately identify which processes are grinding your hard disk to a halt, hit o to only show processes that are doing IO.

To show accumulated IO

If you want to see which processes are behind the most IO over time, use the accumulated mode by hitting a.

The image below shows some accumulated data.

Processes vs threads

To toggle between showing just processes rather than each thread, hit P.

Monitor specific processes

To only monitor specific processes, start iotop with -p.

For example to monitor processes with id 12345 and 23456, use:

sudo iotop -p 12345 -p 23456

Monitor specific user(s)

To monitor IO for specific users only, start iotop with --user for each user your interested in for example

sudo iotop --user root --user jimbob

Sort field and sort order

By default the results are sorted by IO bandwidth used. You can change the field used for sorting by using the left and right arrows. The active sort field will have a > or < beside it. The sorting order can be changed by hitting r (note the > change to < or vice versa).

Change iteration delay

You can change the delay (in seconds) between iterations by starting iotop with -d.

for example for a 2 second refresh interval, run:

sudo iotop -d 2

Batch mode (non-interactive)

To continually dump the display to screen (or wherever), use batch mode. If you use batch mode, you cannot use the interactive options. To start in batch mode:

sudo iotop -b

(Just use Ctrl+c to exit batch mode).

To add a timestamp to each line, use the -t command line option, which automatically sets iotop to batch mode.

sudo iotop -t

To save to file (with timestamps)

sudo iotop -f > iotop_sample.txt

See the man page for further information.

Thanks to Guillaume Chazarain for writing iotop.

Thank you for reading this article.
Please share if you liked it.