3 ms·
Is there a reason to call fsync() all the time instead of using O_SYNC?
by russell_h 16y ago
Is there a reason to call fsync() all the time instead of using O_SYNC?
- antirez 16y agoThis is what I'm considering for "fsync always", but for "fsync everysec" this is now ideal unfortunately. Still O_SYNC can be able to fix at least one problem, that's cool :) Thanks for the comment. Edit: worth noting that instead O_DIRECT can't be used for an append only file, because of alignment requirements. Edit 2: yep O_SYNC helps a lot. Just updated the post with the results.
- russell_h 16y agoAh, yeah, thats what I meant, I probably should have specified that.
- btmorex 16y agoCorrect me if I'm wrong, but O_SYNC is the equivalent of calling fsync() after every single write, so even if you manage to omit one fsync() you're going to come out ahead.
- antirez 16y agoSemantically it's the same, but maybe it is somewhat optimized? Testing right now... Edit: indeed it's different, this is the result: ... Write in 219 microseconds Write in 253 microseconds Write in 264 microseconds Write in 271 microseconds Write in 246 microseconds ... 250 us instead of 13, but no big stops. So much better indeed... Even summing the times, every 10 writes this take 2500 us compared to 40000 us of fsync(). Definitely an improvement. p.s. all this, in ext4 FS.
- pquerna 16y agoits not the same on filesystems like ext3 with ordered data mode (the default). fsync on those kind of filesystems will flush everything, not just a single file, though I believe there has been some more recent work in 2.6 to improve this behavior.
- jedbrown 16y ago> recent work in 2.6 So, since 2003?