title: Why does the memory mapped file ever need to be flushed when access is RDWR?
body: <p>I was reading through one of golang's implementation of memory mapped files, <a href="https://github.com/edsrzf/mmap-go/" rel="nofollow">https://github.com/edsrzf/mmap-go/</a>. First he describes the several access modes:</p>
  
  <pre><code>// RDONLY maps the memory read-only.
  // Attempts to write to the MMap object will result in undefined behavior.
  RDONLY = 0
  // RDWR maps the memory as read-write. Writes to the MMap object will update the
  // underlying file.
  RDWR = 1 &lt;&lt; iota
  // COPY maps the memory as copy-on-write. Writes to the MMap object will affect
  // memory, but the underlying file will remain unchanged.
  COPY
  </code></pre>
  
  <p>But in gommap test file I see this:</p>
  
  <pre><code>func TestReadWrite(t *testing.T) {
    mmap, err := Map(f, RDWR, 0)
    ... omitted for brevity...
    mmap[9] = 'X'
    mmap.Flush()
  </code></pre>
  
  <p>So why does he need to call Flush to make sure the contents are written to the file if the access mode is RDWR? </p>
  
  <p>Or is the OS managing this so it only writes when it thinks it should? </p>
  
  <p>If the last option, could you please explain it in a little more detail - what i read is that when the OS is low in memory it writes to the file and frees up memory. Is this correct and does it apply only to RDWR or only to COPY?</p>
  
  <p>Thanks</p>