Per-filesystem i/o statistics.

Nicholas Dronen (ndronen@frii.com)
Tue, 28 Sep 1999 00:07:59 -0600


Greetings,

I've been a little annoyed by the apparent absence of a way to see
per-filesystem I/O statistics so I wrote a patch for it. I've
put a new entry in /proc/sys/fs to turn the feature on, as
folks who don't need the information shouldn't be penalized
with the extra instructions. It's implemented as a linked
list, so it handles a variable number of filesystems.

In kernel_stat.h:

struct fs_stat {
kdev_t dev;
unsigned int rcount;
unsigned int wcount;
unsigned int rbytes;
unsigned int wbytes;
struct fs_stat *next;
}

Originally I just declared a static array of structures, like
the per-drive accounting, but that seemed somewhat artificial.
(I'd like to see the per-drive statitistics handle a variable number
of drives as well, or at least be able to handle a larger number
of drives. This could be useful on systems with more drives than
the average home-user's computer. It seems that it would be useful
as well for /proc/stat to include the dev_t of the disk in question,
as I've done with filesystems.)

$ grep ^f /var/log/procstat (just a file I've been logging to at boot time)
filesystems 1 833 834 835 836
fs rcount 1 0 0 0 0
fs wcount 4 0 0 0 0
fs rbytes 3605 0 0 0 0
fs wbytes 8 0 0 0 0
filesystems 1 833 834 835 836
fs rcount 0 0 0 0 0
fs wcount 0 0 0 0 0
fs rbytes 0 0 0 0 0
fs wbytes 0 0 0 0 0

The first is before I added fs-stat to /proc/sys/fs; the second is after.

Preliminary but simple tests on a cheap pc don't indicate any huge performance
hit with the statistics gathering on (or off, for that matter, as it has to
test the variable to determine whether to increment the counter).

kernel w/per-filesystem code

test 1: after reboot

$ ./teststat
fs-stats -> 0
running test w/o i/o statistics . . .

real 0m9.425s
user 0m0.070s
sys 0m4.030s
fs-stats -> 1
running test with i/o statistics . . .

real 0m10.839s
user 0m0.080s
sys 0m4.310s

$ ./teststat
fs-stats -> 0
running test w/o i/o statistics . . .

real 0m1.382s
user 0m0.090s
sys 0m1.290s
fs-stats -> 1
running test with i/o statistics . . .

real 0m1.351s
user 0m0.050s
sys 0m1.300s

test 2: after reboot -- stock 2.3.18 kernel

$ ./teststat-nodev
running test with i/o statistics code in kernel . . .

real 0m11.348s
user 0m0.110s
sys 0m4.110s
running test w/o i/o statistics code in kernel again . . .

real 0m9.016s
user 0m0.090s
sys 0m4.100s

$ ./teststat-nodev
running test with i/o statistics code in kernel . . .

real 0m2.009s
user 0m0.090s
sys 0m1.910s
running test w/o i/o statistics code in kernel again . . .

real 0m1.428s
user 0m0.060s
sys 0m1.370s

$ cat teststat
#!/bin/bash

file=linux-2.3.18.test

echo 1 >/proc/sys/fs/fs-stats

echo "fs-stats -> $(cat /proc/sys/fs/fs-stats)"
echo "running test with i/o statistics . . . "

time bash -c "cp /usr/src/$file.2 /usr/local/src/ ; rm /usr/local/src/$file.2"

echo 0 >/proc/sys/fs/fs-stats

echo "fs-stats -> $(cat /proc/sys/fs/fs-stats)"
echo "running test w/o i/o statistics . . . "

time bash -c "cp /usr/src/$file.1 /usr/local/src ; rm /usr/local/src/$file.1"

The other script does the same work.

Comments and suggestions are welcome. I'm going to spend some time
testing and tightening up and will post a url with the patch soon.
I'm aware that not everyone wants or needs to be able to gather
this sort of information, but I do believe that it can be useful.
Perhaps it should be a module or at least modularizable.

Regards,

Nicholas Dronen
ndronen@io.frii.com

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/