linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Question about memory-mapped files
@ 2003-05-28 16:32 John M Collins
  2003-05-28 17:26 ` Hugh Dickins
  0 siblings, 1 reply; 4+ messages in thread
From: John M Collins @ 2003-05-28 16:32 UTC (permalink / raw)
  To: linux-kernel

Please cc me (jmc@removespam.xisl.com) in any reply as I'm not subscribed.

Could someone advise me on the answer to the following question:

If I invoke mmap to map a file to memory, and it succeeds, can I safely 
close the original file descriptor and rely on the memory still being 
mapped and the file still updated (possibly with mysnc)?

I've looked through the kernel (2.4) source and it seems I can. I've 
tried a test program on my machine and also Solaris and HP and it works 
OK the file getting updated.

On the Linux machine /proc/<pid>/maps seems to have all the right stuff 
in after the file is closed.

The only thing that doesn't happen is that the file mod time doesn't get 
changed (on any machine).

Of course "munmap" and "mremap" don't oblige you to pass an fd so it 
would seem logical. But no manual page actually seems to say it.

Could anyone advise? Thanks.

-- 
John Collins Xi Software Ltd www.xisl.com



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

* Re: Question about memory-mapped files
  2003-05-28 16:32 Question about memory-mapped files John M Collins
@ 2003-05-28 17:26 ` Hugh Dickins
  2003-05-28 19:20   ` John M Collins
  0 siblings, 1 reply; 4+ messages in thread
From: Hugh Dickins @ 2003-05-28 17:26 UTC (permalink / raw)
  To: John M Collins; +Cc: linux-kernel

On Wed, 28 May 2003, John M Collins wrote:
> 
> If I invoke mmap to map a file to memory, and it succeeds, can I safely 
> close the original file descriptor and rely on the memory still being 
> mapped and the file still updated (possibly with mysnc)?

Yes, that's definitely a part of the specification of mmap,
even if it's not mentioned on the man page.

Note that the file on disk is likely not to be updated until
some time after you unmap it, unless you use msync to force it.

Hugh


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

* Re: Question about memory-mapped files
  2003-05-28 17:26 ` Hugh Dickins
@ 2003-05-28 19:20   ` John M Collins
  2003-05-29  6:17     ` Hugh Dickins
  0 siblings, 1 reply; 4+ messages in thread
From: John M Collins @ 2003-05-28 19:20 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: linux-kernel

Hugh Dickins wrote:

>On Wed, 28 May 2003, John M Collins wrote:
>  
>
>>If I invoke mmap to map a file to memory, and it succeeds, can I safely 
>>close the original file descriptor and rely on the memory still being 
>>mapped and the file still updated (possibly with mysnc)?
>>    
>>
>
>Yes, that's definitely a part of the specification of mmap,
>even if it's not mentioned on the man page.
>
>Note that the file on disk is likely not to be updated until
>some time after you unmap it, unless you use msync to force it.
>
Thanks - FYI the file mod time eventually got updated on HP-UX but not 
on Solaris (2.9) or Linux (2.4.21) - and it doesn't seem to update it 
even if you don't close the f.d. I think that has to be wrong if the 
manual page is anything to go by.

-- 
John Collins Xi Software Ltd www.xisl.com




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

* Re: Question about memory-mapped files
  2003-05-28 19:20   ` John M Collins
@ 2003-05-29  6:17     ` Hugh Dickins
  0 siblings, 0 replies; 4+ messages in thread
From: Hugh Dickins @ 2003-05-29  6:17 UTC (permalink / raw)
  To: John M Collins; +Cc: linux-kernel

On Wed, 28 May 2003, John M Collins wrote:
>
> Thanks - FYI the file mod time eventually got updated on HP-UX but not 
> on Solaris (2.9) or Linux (2.4.21) - and it doesn't seem to update it 
> even if you don't close the f.d. I think that has to be wrong if the 
> manual page is anything to go by.

I agree with you.  I hate files being modified without mtime changing,
and the mmap(2) man page is so surprisingly specific about those times
that I bet the text comes directly from one of the standards.

It's not something I'm rushing to fix; but I've made a note to
look at it later (days not hours) if nobody else gets there first.
It may turn out to be too difficult to get right - mmap and [amc]time
don't fit well together; but that text you've noticed at least gives
something to aim for - thanks.

Hugh


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

end of thread, other threads:[~2003-05-29  6:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-28 16:32 Question about memory-mapped files John M Collins
2003-05-28 17:26 ` Hugh Dickins
2003-05-28 19:20   ` John M Collins
2003-05-29  6:17     ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).