I try to minimize disk writes to my new SSD system drive. I'm stuck with iostat output:
~ > iostat -d 10 /dev/sdb
Linux 2.6.32-44-generic (Pluto) 13.11.2012 _i686_ (2 CPU)
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sdb 8,60 212,67 119,45 21010156 11800488
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sdb 3,00 0,00 40,00 0 400
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sdb 1,70 0,00 18,40 0 184
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sdb 1,20 0,00 28,80 0 288
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sdb 2,20 0,00 32,80 0 328
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sdb 1,20 0,00 23,20 0 232
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sdb 3,40 19,20 42,40 192 424
As I see there are writes to sdb. How can I resolve which process writes?
I know about iotop, but it doesn't show which filesystem is being accessed.
You could at least start with iotop. It won't tell you which filesystem is being written but it will give you some processes to investigate.
It shows instantaneous disk reads and writes and the name of the command reading or writing.
If you are trying to catch a process that writes infrequently, you can use the
--accumulate
option or log the output to a file:Obviously the writing of the log file will show up in the results, but you should also be able to grep for other processes writing to disk.
By this point you should be able to find some candidate suspect processes. The left column in iotop shows the pid. Next, find out which file descriptor the process is writing to:
You should see output like this when the process writes:
The first argument to write is the file descriptor. We are probably looking for values greater than 2, because 0, 1 and 2 are just stdin, stdout and stderr. File descriptor 4 looks interesting.
You can now find out what file the file descriptor points to with:
Which should yield output like:
Look at the 4th column.
4w
means that file descriptor 4 is open for writing and the file isanother_test_file
.It is possible for a process to open, write and then close a file, in which case lsof would not show it. You might catch this happening with:
The following uses the kernel's virtual memory block dump mechanism. First get the perl script:
Then turn on block dump:
And run the following:
..and press Controlc to finish, you will see something like the following:
And turn off block dump when you are finished:
Thanks to http://www.xaprb.com/blog/2009/08/23/how-to-find-per-process-io-statistics-on-linux/ for this helpful info.