Re: shared anonymous memory

Richard Jones (rjones@orchestream.com)
Mon, 12 Jan 1998 11:57:33 +0000


Roger Espel Llima wrote:
> Right, it is only shared via fork. The fd can be -1, or a rw fd on
> /dev/zero; some systems support it with /dev/zero but not with -1. If
> the fd is not -1, then the MAP_ANONYMOUS flag is not needed.
>
> Actually, the BSD folks who came up with this interface had it planned
> so that unrelated processes could have a way to rendez-vous and set up a
> shared memory zone. As far as I can understand, they were supposed to
> use the file descriptor as a meeting point, possibly by passing it
> through a Unix-domain socket (or at least, I can't think of any other
> way that makes sense).
[...]

But, in fact, you can get a similar effect by mapping
from a common file. If the last process to map the
file also unlink()s it, then the inode will be automatically
cleaned up when the last process using the file exits (or
closes the fd).

My only question on this is: is it possible for Linux
to notice when an inode is not linked to an actual
directory entry and never bother to synchronise that
`file' when sync() is called? This would be an optimization
in several situations - for the mmap case above (writes
to the shared memory wouldn't ever be written out to
the disk), and for various daemons that open temporary
files on /tmp and immediately unlink them. Again, there's
no need to actually write anything to the disk in this
case. If there's enough memory spare, then the dirty disk
blocks can just accumulate in memory.

Rich.

-- 
Richard Jones  rjones@orchestream.com Tel: +44 171 460 6141 Fax: .. 4461
Orchestream Ltd.  262a Fulham Rd.  London  SW10 9EL.  "you'll write in
PGP: www.four11.com     telegraphic, or you won't write at all" [Céline]
Copyright © 1998 Richard W.M. Jones