In C file I/O, the O_DIRECT
flag can be used to minimize cache effects for a file being open()
ed. I understand that this is not a POSIX feature, has been present in the Linux kernel since version 2.4.10, and that Linus is opposed to the interface in general. Under NetBSD, it seems to work as advertised. Example call:
int fd = open(filename, O_DIRECT);
I am attempting to write some low-level disk benchmarking utilities, and using O_DIRECT
looks to be a potentially good way of measuring the disk and drive performance without the effects of the OS filesystem/block cache. Ideally, I would like to be able to run the benchmark on Linux, Windows (Cygwin is OK), Mac OS X, and BSD systems. Is O_DIRECT
the best way to bypass the OS disk caches, in terms of portability and reliability for benchmarking? Are there alternatives?