3

Background : in Java I'm memory mapping a file (shared).

I'm writing some value at the address 0 of that file. I understand the corresponding PAGE in the PAGE CACHE is flagged as DIRTY and will be written later depending on the dirty_ratio and the like settings.

So far so good.

But I'm wondering what is happening when writing once more at the address 0 while the kernel is writing back the dirty page to the file. Is my process blocked somehow waiting for the writeback to be completed?

Marc Polizzi
  • 9,275
  • 3
  • 36
  • 61
  • With what permissions are you memory mapping the file? A snippet of code would be very helpful. –  Oct 29 '17 at 23:52
  • -rw-rw-r-- : as for the code : once I got the memory mapped file buffer I'm simply buffer.putInt( addr, value ) quite randomly possibly writing several times different values at the same addresse in the file. – Marc Polizzi Oct 30 '17 at 07:06

1 Answers1

0

It may be. It is only necessary when the device-level I/O requests include a checksum alongside the written data. Otherwise, the first write may be torn, but it can then be corrected by the second write.

As always, carefully consider your safety against power-failure, kernel crashes etc.

The waiting is allegedly avoided in btrfs. (Also, by happenstance, in the legacy ext3 filesystem. But not ext4 or ext2).

This looks like it is a bit of a moving target. The above (as far as I could tell) describes the first optimization of this "stable page write" code, following the complaints when it was first introduced. The commit description mentions several possibilities for future changes.

  1. bdi: allow block devices to say that they require stable page writes
  2. mm: only enforce stable page writes if the backing device requires it

Does my device currently use "stable page writes"?

There is a sysfs attribute you can look at, called stable_pages_required

sourcejedi
  • 3,051
  • 2
  • 24
  • 42