Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Dec 1996 11:43:36 -0700 (MST)
From:      Terry Lambert <terry@lambert.org>
To:        scrappy@hub.org (Marc G. Fournier)
Cc:        erich@lodgenet.com, hackers@freebsd.org
Subject:   Re: Multiple Buffer allocation of Shared Memory
Message-ID:  <199612101843.LAA04595@phaeton.artisoft.com>
In-Reply-To: <Pine.NEB.3.95.961210130845.374A-100000@hub.org> from "Marc G. Fournier" at Dec 10, 96 01:20:06 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> 	Okay...maybe I'm missing something as far as mmap() is concerned,
> but what I want to be able to do is allocated X bytes of memory to be
> shared amongst several processes.  After the memory is allocated, I will
> *then* want to fill the memory (ie. with data read from a socket).
> 
> 	From reading the mmap() man page (any good reference/textbooks that
> I might want to pick up?), mmap() allocates and fills the memory space at
> the same time, based on a previously opened, already existing, file (fd).
> 
> 	Is there something I'm missing?  With shared memory, this isn't a
> problem, or, at least, from what I've read, won't be a problem...

OK.

The cannonically "correct" kludge for this is to mmap() an fd opened
on /dev/zero in order to get your anonymous pages.

This works because the /dev/zero mapping entry point knows to make
an anonymous zero-filled region attacked to an open vnode that does
not have an FS name space entry.

This is different that mapping /dev/zero copy-on-write, since it means
that there is a shared copy of the zero-filled pages, and that the shared
copy is seperate.

Then you pass the fd to the other processes using a POSIX (UNIX) domain
socket.  Same fd == same mapping region.


I have no idea if this actually works in FreeBSD, like it's supposed to;
my gut feeling is that it would not, since a lot of people just ignore
FS interaction details, and they get lost in the cracks (this is an
FS implementation detail; if you don't believe me, I can explain in
great gory detail about struct fileops and character device nodes,
like /dev/zero).

John?  How does mmap'ing /dev/zero work?


In any case, if this does not work for you, you *can* write out an
empty file for the region size, map it instead, and then once all
mappings exist, unlink the file (and pass the fd around with a
UNIX domain socket).  If you do this method, then the mapping can
be non-copy-on-write and still not run into problems (since multiple
programs doing this same thing would not crap on /dev/zero itself).



					Regards,
					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612101843.LAA04595>