Linux – Force block device (NBD) to bypass the buffer cache

block-devicecachelinux

I'd like to know if there is a way to force a block device to bypass the linux buffer cache (ie direct IO) and pass the requests directly to the underlying layer. I know one can open a file using O_DIRECT flag to achieve this, but my program is not the user of the block device, a file system is. And so far, I have not had any luck telling various FSes to use direct IO.

In summary, I want the raw device functionality without using raw devices (since they're
deprecated in my distro, Fedora).

If this is of any importance, my block device is a Network Block Device.
Any help would be appreciated.

Best Answer

You can achieve this by mounting with the sync-option.

From the mount(8)-man page:

   sync   All I/O to the filesystem should be done synchronously. In  case
          of  media  with  limited number of write cycles (e.g. some flash
          drives) "sync" may cause life-cycle shortening.