Today I stumbled upon this mount
's option:
dirsync
All directory updates within the filesystem should be done synchronously.
This affects the following system calls: creat, link, unlink, symlink,
mkdir, rmdir, mknod and rename.
What are some real-life use cases for this option? When would I want to use dirsync
instead of sync
?
Best Answer
sync
does everythingdirsync
does, plus more. Unfortunately this 'more' is a significant performance penalty. Withsync
enabled, all disk I/O is immediately written to disk. Withdirsync
, only directory operations are immediately written.The only case I've seen where one might want to use
dirsync
instead ofsync
is in the case of network filesystems. When multiple boxes are working in a shared directory, they might try to create the file at around the same time. One box will create the file, but withoutdirsync
on, the file isn't visible to other boxes yet. Withdirsync
on, the file will show up immediately, so the other servers at least know it exists and can now perform file locking on it.