Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

I don't think it's possible to have direct I/O without using either O_DIRECT or raw devices. Using sync option on mount won't bypass the buffer cache either.

Because you can't set it from the filesystem, you'd have to modify your program to either use O_DIRECT or mmap() and madvise() to get similar behaviour.

"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."

Don't worry about the your program is not the user, O_DIRECT works for open() which is file based anyway.

share|improve this answer
    
What I meant by "my program is not the user of the block device, a file system is" was that no part of my program deals with the block device. My code sits behind the block device as the backend. It's basically a Network Block Device which connects to an NBD server I've written. By bypassing the buffer cache, I was hoping to avoid some deadlocking issues with NBD setups. –  Mansour Nov 15 '11 at 12:04

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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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