On Tue, Feb 06, 2007 at 10:57:07AM -0500, lusec001@xxxxxxxxxx wrote: > > I want to save the access log of disk in block level. > > The number of block in disk and the I/O type (R/W) of > > the request are needed for me. > > > > What should I modify to save the log? In block cache > > code? or EXT{2,3}? > > I don't understand so well the question. But, if the information that you > want is the blocks requested and the type of operation, you need to trace > the __make_request function > [http://lxr.free-electrons.com/source/block/ll_rw_blk.c#2905] and print > the values obtained with the bio paramter > [http://lxr.free-electrons.com/source/include/linux/bio.h#072]. You could > do all this with kprobes. lusec001@xxxxxxxxxx, Ming Zhang <blackmagic02881@xxxxxxxxx> Hello, Thank you for the replies. I modified generic_make_request() in block/ll_rw_blk.c to log the number of sector on which I/O operation is and the type of operation (R/W). Follow is just what I modified in Linux 2.6.20. --- linux-2.6.20/block/ll_rw_blk.c.sx 2007-02-05 03:44:54.000000000 +0900 +++ linux-2.6.20/block/ll_rw_blk.c 2007-02-12 22:04:29.000000000 +0900 @@ -3121,6 +3121,21 @@ sector_t old_sector; int ret, nr_sectors = bio_sectors(bio); dev_t old_dev; + struct bio *b; + int r; + + r = 0; + do { + b = bio; + printk(KERN_INFO "device:[%s:%d] sector:[%8ld/%8ld] [%5s] %3d\n", + b->bi_bdev->bd_disk->disk_name, + b->bi_bdev->bd_disk->major, + b->bi_sector, b->bi_bdev->bd_disk->capacity, + (b->bi_rw << (sizeof(unsigned long) - 1)) ? "write" : "read", + r); + b = b->bi_next; + r++; + } while (b); might_sleep(); /* Test device or partition size, when known. */ And follow is the log messages I got. .... Feb 12 22:10:03 devel kernel: [ 177.035122] device:[hda:3] sector:[54527992/78165360] [write] 0 Feb 12 22:10:28 devel kernel: [ 202.228368] device:[hda:3] sector:[ 23664/78165360] [write] 0 Feb 12 22:10:28 devel kernel: [ 202.228380] device:[hda:3] sector:[ 23672/78165360] [write] 0 Feb 12 22:10:28 devel kernel: [ 202.228385] device:[hda:3] sector:[ 23680/78165360] [write] 0 Feb 12 22:10:28 devel kernel: [ 202.228600] device:[hda:3] sector:[ 23688/78165360] [write] 0 Feb 12 22:10:35 devel kernel: [ 209.662664] device:[hda:3] sector:[46081848/78165360] [ read] 0 Feb 12 22:10:36 devel kernel: [ 210.407313] device:[hda:3] sector:[33030144/78165360] [ read] 0 Feb 12 22:10:37 devel kernel: [ 211.212951] device:[hda:3] sector:[33046912/78165360] [write] 0 Feb 12 22:10:37 devel kernel: [ 211.212968] device:[hda:3] sector:[33057088/78165360] [write] 0 Feb 12 22:10:37 devel kernel: [ 211.212974] device:[hda:3] sector:[33117232/78165360] [write] 0 Feb 12 22:10:37 devel kernel: [ 211.213342] device:[hda:3] sector:[ 23696/78165360] [write] 0 Feb 12 22:10:37 devel kernel: [ 211.213348] device:[hda:3] sector:[ 23704/78165360] [write] 0 Feb 12 22:10:37 devel kernel: [ 211.213353] device:[hda:3] sector:[ 23712/78165360] [write] 0 Feb 12 22:10:37 devel kernel: [ 211.213356] device:[hda:3] sector:[ 23720/78165360] [write] 0 .... I also test the blktrace and follow is a part of the log of it. .... 3,1 0 1 0.000000000 0 C W 66709160 + 48 [0] 3,1 0 2 0.000543443 0 C W 45597703 + 32 [0] 3,1 0 3 0.000715134 0 C W 66709208 + 8 [0] 3,1 0 4 0.004712097 0 C W 89855 + 256 [0] 3,1 0 5 0.004911340 0 C W 90111 + 8 [0] 3,1 0 6 9.981945195 0 C W 90119 + 40 [0] 3,1 0 7 9.982134057 0 C W 90159 + 8 [0] 3,1 0 8 10.008405332 0 C W 72256056 + 8 [0] 3,1 0 9 10.008966459 0 C W 66709216 + 32 [0] 3,1 0 10 10.009152830 0 C W 66709248 + 8 [0] 3,1 0 11 10.090253953 0 C W 72206904 + 8 [0] .... Let me know if something wrong in my post. Thank you! -- Seongsu's blog - http://www.senux.com/ A sine curve goes off to infinity, or at least the end of the blackboard. -- Prof. Steiner -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/