public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* msync() needed before munmap() when writing to shared mapping?
@ 2004-04-16 22:02 Jamie Lokier
  2004-04-16 22:46 ` Andrew Morton
  2004-04-17 20:23 ` H. Peter Anvin
  0 siblings, 2 replies; 6+ messages in thread
From: Jamie Lokier @ 2004-04-16 22:02 UTC (permalink / raw)
  To: linux-kernel

I'm verifying that writing to a shared mapping and then calling
munmap() or exit() definitely propagates the dirty bits from the page
tables to the file.

This has been asked before, 1 year ago, in a thread called "Memory
mapped files question", and hpa said:

> munmap() and fsync() or msync() will flush it to disk; there is no
> reason munmap() should unless perhaps the file was opened O_SYNC.

That was talking about flushing data all the way to disk.  The
implication of hpa's response is that munmap() does propagate the
dirty bits from the page table to the file.  That is the obvious
behaviour, and what I've always assumed.

I've followed the logic from do_munmap() and it looks good:
unmap_vmas->zap_pte_range->page_remove_rmap->set_page_dirty.

Can someone confirm this is correct, please?

Also, I recall a mention on lkml that some flavour of BSD doesn't
propagate the dirty bits when unmapping, and msync is needed to ensure
data is properly written to the file.  I haven't been able to find the
message, though; perhaps I imagined it.

Can someone confirm or refute that, and similarly does anyone know of
any other OS that needs msync before munmap or exit, to ensure written
data reaches the file?

Thanks,
-- Jamie

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-04-17 20:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-16 22:02 msync() needed before munmap() when writing to shared mapping? Jamie Lokier
2004-04-16 22:46 ` Andrew Morton
2004-04-16 23:10   ` Jamie Lokier
2004-04-16 23:59     ` Andrew Morton
2004-04-16 23:55   ` Hugh Dickins
2004-04-17 20:23 ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox