Re: mmap-related questions

Benjamin LaHaise
2003-04-01T17:39:00Z

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? aart@kvack.org