title: Does madvise(___, ___, MADV_DONTNEED) instruct the OS to lazily write to disk?
body: <p>Hypothetically, suppose I want to perform sequential writing to a potentially very large file.</p>
  
  <p>If I mmap() a gigantic region and madvise(MADV_SEQUENTIAL) on that entire region, then I can write to the memory in a relatively efficient manner.  This I have gotten to work just fine.</p>
  
  <p>Now, in order to free up various OS resources as I am writing, I occasionally perform a munmap() on small chunks of memory that have already been written to.  My concern is that munmap() and msync()will block my thread, waiting for the data to be physically committed to disk.  I cannot slow down my writer at all, so I need to find another way.</p>
  
  <p>Would it be better to use madvise(MADV_DONTNEED) on the small, already-written chunk of memory?  I want to tell the OS to write that memory to disk lazily, and not to block my calling thread.</p>
  
  <p>The manpage on madvise() has this to say, which is rather ambiguous:</p>
  
  <pre><code>MADV_DONTNEED
  Do  not expect access in the near future.  (For the time being, the 
  application is finished with the given range, so the kernel can free
  resources associated with it.)  Subsequent accesses of pages in this
  range will succeed, but will result either in re-loading  of the memory
  contents from the underlying mapped file (see mmap(2)) or
  zero-fill-on-demand pages for mappings without an underlying file.
  </code></pre>