1WRITE_CACHE_PAGES(9) Memory Management in Linux WRITE_CACHE_PAGES(9)
2
3
4
6 write_cache_pages - walk the list of dirty pages of the given address
7 space and write all of them.
8
10 int write_cache_pages(struct address_space * mapping,
11 struct writeback_control * wbc,
12 writepage_t writepage, void * data);
13
15 mapping
16 address space structure to write
17
18 wbc
19 subtract the number of written pages from *wbc->nr_to_write
20
21 writepage
22 function called for each page
23
24 data
25 data passed to writepage function
26
28 If a page is already under I/O, write_cache_pages skips it, even if
29 it's dirty. This is desirable behaviour for memory-cleaning writeback,
30 but it is INCORRECT for data-integrity system calls such as fsync.
31 fsync and msync need to guarantee that all the data which was dirty at
32 the time the call was made get new I/O started against them. If
33 wbc->sync_mode is WB_SYNC_ALL then we were called for data integrity
34 and we must wait for existing IO to complete.
35
36 To avoid livelocks (when other process dirties new pages), we first tag
37 pages which should be written back with TOWRITE tag and only then start
38 writing them. For data-integrity sync we have to be careful so that we
39 do not miss some pages (e.g., because some other process has cleared
40 TOWRITE tag we set). The rule we follow is that TOWRITE tag can be
41 cleared only by the process clearing the DIRTY tag (and submitting the
42 page for IO).
43
44 To avoid deadlocks between range_cyclic writeback and callers that hold
45 pages in PageWriteback to aggregate IO until write_cache_pages returns,
46 we do not loop back to the start of the file. Doing so causes a page
47 lock/page writeback access order inversion - we should only ever lock
48 multiple pages in ascending page->index order, and looping back to the
49 start of the file violates that rule and causes deadlocks.
50
52Kernel Hackers Manual 3.10 June 2019 WRITE_CACHE_PAGES(9)