1

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.
3
  • This looks like a question for stackoverflow.com Jun 20, 2023 at 18:43
  • @ArtemS.Tashkinov I say you're right, that's definitely a software programming question, but also, it asks about specific operating system capabilities of Linux, and or POSIX, so I think it's actually very well here :) Jun 20, 2023 at 19:04
  • Msync just synchronizes memory view and filesystem view of the opened file. Does it really enforce a flush to disk? Jun 20, 2023 at 19:15

1 Answer 1

1

There is a Linux-specific system call: sync_file_range()

(Sidenote, using block devices is not portable to FreeBSD)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .