Linux : dirty page writeback and concurrent write

让人想犯罪 __ 提交于 2020-01-15 06:27:20

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/46913388/linux-dirty-page-writeback-and-concurrent-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!