Re: mmap-related questions

Benjamin LaHaise (bcrl@redhat.com)
Tue, 1 Apr 2003 12:50:20 -0500


On Mon, Mar 31, 2003 at 07:25:46PM -0800, Kenny Simpson wrote:
> --- Benjamin LaHaise <bcrl@redhat.com> wrote:
> > No. You must use msync().
>
> > Note that fsync() after
> > munmap() will flush the
> > pages to disk under Linux.
> Sweet! Paydirt! Is this documented/guaranteed to
> continue to work for a while?
> Is this true for all non-mmap()ed dirty buffers for a
> given file?

It's only true for the pages the munmap() removes from the process' page
tables: the act of unmapping them transfers the dirty bit from the page
tables into the page cache where fsync() acts on them.

> Just to restate what you said:
> - if part of a file is mmap()ed, msync() MUST be used
> to sync it.
> - any non-mmap()ed portions are synched with fsync().

Pretty much.

> I'm assuming this is a per-process thing. i.e. The
> above is true regardless of what other processes are
> doing (e.g. even if another process has the same file
> mmap()'d, I don't care).

Right. Other processes are responsible for managing their own syncing of
dirty bits to disk at the appropriate times. The one case this breaks down
on is when the mmap()'d file is on NFS -- the reordering there can result in
writebacks from mmap()s occuring in unexpected ways. But then, nobody trusts
their data to NFS, right? ;-)

-ben

-- 
Junk email?  <a href="mailto:aart@kvack.org">aart@kvack.org</a>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/