Monitoring disk activity
Problem
I want to find out which processing is reading and/or writing from a particular disk in question.
Scripts
# traceio2.stp # Copyright (C) 2006 Red Hat, Inc., Eugene Teo <eteo@redhat.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # Based on: http://sources.redhat.com/systemtap/wiki/WSFileMonitor # probe kernel.function ("vfs_write"), kernel.function ("vfs_read") { # kernel 2.6.21-1.3194.fc7 dev_nr = $file->f_path->dentry->d_inode->i_sb->s_dev inode_nr = $file->f_path->dentry->d_inode->i_ino if (dev_nr == ($1 << 20 | $2)) printf ("%s(%d) %s 0x%x\n", execname(), pid(), probefunc(), dev_nr) }
Output
[eteo@kerndev ~]$ ls -laF /dev/sdc1 brw-r----- 1 root disk 8, 33 2007-06-12 20:25 /dev/sdc1 [eteo@kerndev ~]$ stap traceio2.stp 8 33 [...] dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021 dd(8245) vfs_write 0x800021
on another terminal, I issue a dd command just to simulate some I/O activity:
[eteo@kerndev disk]$ dd if=/dev/zero of=test count=10 10+0 records in 10+0 records out 5120 bytes (5.1 kB) copied, 0.000254216 s, 20.1 MB/s [eteo@kerndev disk]$
Lessons
Even when we do not have a Linux equivalent of the Solaris' prex command, we can still find out I/O activity from a disk. Also see WSFileMonitor and WSFileMonitor2.