Sample Header Ad - 728x90

Partial fsyncs when writing to block device

1 vote
1 answer
277 views
I'm writing my own data store directly on top of a block device. To ensure durability I want to sync to disk. But here's the thing: I want to sync only part of it. I'm keeping a journal for crash recovery, and write my future changes to the journal before applying them to the actual place on disk. Then I want to ensure the journal changes are written to disk, and only then make the actual changes to the rest of the disk (which I don't care about fsyncing, until I checkpoint my journal). I could simply fsync the entire block device, but that forces a lot of things that aren't urgent to be written out. I have thought of two options, but I'm surprised there is no partial fsync(2) call and nobody asking for it from what I've found. 1. mmap(2) the full block device and use msync(2) to sync part of it. 2. open(2) the block device twice, once with O_SYNC and use one for lazy writes and one for my journal writes.
Asked by Jille Timmermans (53 rep)
Jun 20, 2023, 06:42 PM
Last activity: Jun 20, 2023, 07:03 PM