Identify Disk/Swap Hungry Processes with Iotop

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.

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 e.g.

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".
e.g. 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.