Here is an explanation on how
fdatasync() works vs how
fdatasync() flushes all data buffers of a file to disk (before the system call returns). It resembles
fsync() but is not required to update the metadata, such as access time.
Applications that access databases or log files often write a tiny data fragment (e.g., one line in a log file) and then call
fsync() immediately in order to ensure that the written data is physically stored on the harddisk. Unfortunately,
fsync() will always initiate two write operations
- one write operation for the newly written data
- one write operation in order to update the modification time stored in the inode
If the modification time is not a part of the transaction concept, then
fdatasync() can be used to avoid unnecessary inode disk write operations.
O_DSYNC is faster than
fsync() twice (one for logs and one for data) and
fsync() verifies data writes via two write operations. Using
fsync(). You can think of
fdatasync() as doing an asynchronous
fsync() (not verfying data).
Looking at the numbers,
O_DSYNC does four write ops, two of which are verified, while
fsync() does four write operations, all being verfied afterwards.
- faster than
- Data may/may not be consistent due to latency or an outright crash
- more stable
- data consistent
- naturally slower
I hope this answer helps, and I hope I didn't make things worse for you.