Comment by blattimwind

8 years ago

A more advanced (and somewhat easy to get wrong) option would be sync_file_range combined with fdatasync, which allows to roughly emulate O_DSYNC overall but without blocking synchronously for IO.

sync_file_range is different to fsync, fdatasync and O_DSYNC in that it does not flush the disk write cache (whereas the latter explicitly do on newer kernels):

https://linux.die.net/man/2/sync_file_range:

  This system call does not flush disk write caches and thus does not
  provide any data integrity on systems with volatile disk write caches.

  • Hence "sync_file_range combined with fdatasync". sfr is only useful to get the kernel to start the write-out now.