Record Locking Help ....

Roger Oberholtzer roger
Tue Aug 16 08:11:33 PDT 2005


On Tue, 2005-08-16 at 14:44, Ben Duncan wrote:
> There is a msync that flushes the mmap page to write. There is a
> sync or async setting one can use for guaranteeing atomicity.
> 
> Now, my NEXT questions is what happens with multiple opens on mmap?
> 
> If process A opens and initiates a mmap, then along comes process B,
> then C, etc...,all reading/writing the same file and process A
> ends, does it "CLOSE" and 'munmap' the mmap file? Does the next
> process, B, need to establish a mmap for the file? If process A DOES NOT
> 'munmap' the file when it ends, how does the memory get freed when ALL
> process's are done ?

Each mmap is independent. It is per-process. Just like the open/close.
How the different processes see updates from another process is a bit
unclear to me. I think (could be wrong) they share any file segment by
the virtual memory system mapping the same memory page into each
process. Which is why you need the locks. But this may also mean that
the changes may be seen by the other processes before they are sent to
disk with msync. Or maybe it is the MS_INVALIDATE flag to msync that
will cause this to happen.

> 
> 
> Thanks ...
> 
> Roger Oberholtzer wrote:
> > On Mon, 2005-08-15 at 23:19, Ben Duncan wrote:
> > 
> 
> <SNIP>
> > 
> > With mmap files, there really is no flush in the traditional sense. If a
> > memory page is 'dirty' (something has changed since taken from the disk)
> > it will be saved automatically by the paging system upon which mmap is
> > written. Initially it will (I think) be saved to your swap space (if
> > memory is full) and, when the file is closed, all dirty pages are
> > written. There may be a flag somewhere that tells the system to write
> > dirty pages based on some other criterion. The virtual memory system
> > takes care of all this. So, there is also no write() call...
> > 
> > 
+????????????????????????????+???????????????????????????????+
? Roger Oberholtzer          ?   E-mail: roger at opq.se        ?
? OPQ Systems AB             ?      WWW: http://www.opq.se/  ?
? Kapellgr?nd 7              ?                               ?
? P. O. Box 4205             ?    Phone: Int + 46 8   314223 ?
? 102 65 Stockholm           ?   Mobile: Int + 46 733 621657 ?
? Sweden                     ?      Fax: Int + 46 8   314223 ?
+????????????????????????????+???????????????????????????????+



More information about the Linux-users mailing list