3

I am running a lot of KVM virtual machines, which open the hard disk image with the O_DIRECT flag.

I understand, according to the open() man page, that using O_DIRECT will try to bypass the Linux page cache when writing to a file, but does that apply to block devices as well? (for instance when the hard disk image is a LVM volume, or a ZFS zvol)

NB: the use case of O_DIRECT here, is that the guest is already maintaining its own page cache, so it makes no sense to duplicate that on the host.

1

And it seems the answer is yes: opening a block device with O_DIRECT will bypass the page cache as well. I found the answer in this 2009 blog post about the Linux Page Cache .

It’s possible to bypass the page cache using O_DIRECT in Linux or NO_BUFFERING in Windows, something database software often does.

2
  • please update the answer with a valid source. the embedded link is broken
    – aspen100
    Sep 15 at 17:46
  • I found a correct, better link.
    – Manu
    2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.