I know XFS does not sync metadata even though the file being written is open with O_DIRECT and the metadata of the file is changed. But for ext4, I notice that MySQL support O_DIRECT_NO_FSYNC which means MySQL does not call fsync() and lets the filesystem sync metadata by itself.
So here comes the question: if I open a file with O_DIRECT in ext4 (say linux kernel version 5.8.0), and call fsync() after write(), what will fsync() do?
Another question to follow: what will fsync() do if open() a file with O_DIRECT | O_SYNC in ext4?
Thanks!
O_DIRECTdoes not imply anything about a disk's own volatile cache. On Linuxfsync()can request for data in that cache to be written back too.As for your
fsync()when the file is already usingO_DIRECT|O_SYNC... There will be overhead because you made a syscall, the page cache will have to be checked and that disk cache flush will be sent - they just won't have any work to do so it's something of a waste. I guess you could end up flushing data for the journal and/or another file depending on the filesystem.