buffer cache flushing problems

Alexander L. Belikoff (abel@bfr.co.il)
09 Feb 1998 14:19:05 +0200


Hello everybody,

I want to do some I/O testing for Linux. To measure a "pure" disk I/O
without an impact of the buffer cache, I'd like to be able to flush
the cache, so that the next read will be done from the disk itself ,
an not from the cache. So far, the only way to do it I've found out
(in hdparm) is:

fsync(fd); /* flush buffers */

if (ioctl(fd, BLKFLSBUF, NULL)) /* do it again, big time */
perror("BLKFLSBUF failed");

However this doesn't seem to have any impact on input performance. As
a very simple test, try to cat a reasonably big file (3Mb) to
/dev/null, then to invalidate the cache, and to read this file
again. As you may see below, my attempt to flush the cache is not very
successful:

$ for x in 1 2 3 4 5 6 7 8 9 0; do time cat /var/lib/rpm/pathidx > /dev/null; done; ./bcache /dev/hda1; for x in 1 2 3 4 5 6 7 8 9 0; do time cat /var/lib/rpm/pathidx > /dev/null; done

0.00user 0.33system 0:02.06elapsed 15%CPU (0avgtext+0avgdata 0maxresident)k
^^^^^^^^^^^^^^^^^^^^^^^^^
0inputs+0outputs (633major+9minor)pagefaults 0swaps
0.00user 0.02system 0:00.07elapsed 26%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (84major+9minor)pagefaults 0swaps
0.01user 0.01system 0:00.01elapsed 125%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (72major+9minor)pagefaults 0swaps

Flushing buffers for /dev/hda1...

0.00user 0.01system 0:00.04elapsed 21%CPU (0avgtext+0avgdata 0maxresident)k
^^^^^^^^^^^^^^^^^^^^^^^^^
0inputs+0outputs (72major+9minor)pagefaults 0swaps
0.00user 0.01system 0:00.01elapsed 62%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (72major+9minor)pagefaults 0swaps
0.01user 0.01system 0:00.01elapsed 125%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (72major+9minor)pagefaults 0swaps

As you see, even after flushing, the read time is way too low. So my
question is: is the way I do flushing correct? Maybe I'm missing
something... Of course, the thing is not documented anywhere...

Thanks in advance,

-- 
Alexander L. Belikoff
Berger Financial Research Ltd.
abel@bfr.co.il
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu