Search code examples
ccachingflushdisk

c - Write directly to disk, bypass page cache?


I am trying to determine a way to time a write to disk as accurately as possible.

Calling the write() function writes the file first to the page cache, and then later the system automatically flushes it to disk (if my understanding is correct).

Is there a way to bypass the page cache? Or, would the process involve writing to the page cache, and then flushing the page cache (but how would you then time how long simply flushing the specific data that was written takes)


Solution

  • For Linux you can open the disk device with the O_DIRECT flag to bypass page cache.