1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>write_cache_pages</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="The Linux Kernel API"><link rel="up" href="ch04s03.html" title="More Memory Management Functions"><link rel="prev" href="API-tag-pages-for-writeback.html" title="tag_pages_for_writeback"><link rel="next" href="API-generic-writepages.html" title="generic_writepages"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">write_cache_pages</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-tag-pages-for-writeback.html">Prev</a> </td><th width="60%" align="center">More Memory Management Functions</th><td width="20%" align="right"> <a accesskey="n" href="API-generic-writepages.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-write-cache-pages"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>write_cache_pages — 2 walk the list of dirty pages of the given address space and write all of them. 3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">write_cache_pages </b>(</code></td><td>struct address_space * <var class="pdparam">mapping</var>, </td></tr><tr><td> </td><td>struct writeback_control * <var class="pdparam">wbc</var>, </td></tr><tr><td> </td><td>writepage_t <var class="pdparam">writepage</var>, </td></tr><tr><td> </td><td>void * <var class="pdparam">data</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1124800556"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>mapping</code></em></span></dt><dd><p> 4 address space structure to write 5 </p></dd><dt><span class="term"><em class="parameter"><code>wbc</code></em></span></dt><dd><p> 6 subtract the number of written pages from *<em class="parameter"><code>wbc</code></em>->nr_to_write 7 </p></dd><dt><span class="term"><em class="parameter"><code>writepage</code></em></span></dt><dd><p> 8 function called for each page 9 </p></dd><dt><span class="term"><em class="parameter"><code>data</code></em></span></dt><dd><p> 10 data passed to writepage function 11 </p></dd></dl></div></div><div class="refsect1"><a name="idp1124805652"></a><h2>Description</h2><p> 12 If a page is already under I/O, <code class="function">write_cache_pages</code> skips it, even 13 if it's dirty. This is desirable behaviour for memory-cleaning writeback, 14 but it is INCORRECT for data-integrity system calls such as <code class="function">fsync</code>. <code class="function">fsync</code> 15 and <code class="function">msync</code> need to guarantee that all the data which was dirty at the time 16 the call was made get new I/O started against them. If wbc->sync_mode is 17 WB_SYNC_ALL then we were called for data integrity and we must wait for 18 existing IO to complete. 19 </p><p> 20 21 To avoid livelocks (when other process dirties new pages), we first tag 22 pages which should be written back with TOWRITE tag and only then start 23 writing them. For data-integrity sync we have to be careful so that we do 24 not miss some pages (e.g., because some other process has cleared TOWRITE 25 tag we set). The rule we follow is that TOWRITE tag can be cleared only 26 by the process clearing the DIRTY tag (and submitting the page for IO). 27</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-tag-pages-for-writeback.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch04s03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-generic-writepages.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">tag_pages_for_writeback</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">generic_writepages</span></td></tr></table></div></body></html> 28