Re: buffer cache flushing problems

Trevor Johnson (trevor@jpj.net)
Mon, 9 Feb 1998 08:18:09 -0500 (EST)


> 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:

According to the man page, "fsync copies all in-core parts of a file to
disk." In other words, it flushes the write buffers for the file you have
open, similarly to sync(2) but just for that one file. I don't think
there's a means of turning off or clearing the read buffers other than
running some other data through them which is more than they can hold. If
you had two files, bigfile which is larger than the memory available for
buffers (probably shouldn't be a sparse file either) and otherfile which
is of the size you want to test, then

% cat bigfile>/dev/null ; time cat otherfile>/dev/null

should do what you want.
___
Trevor Johnson

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu