From owner-freebsd-hackers Tue Dec 10 11:05:25 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id LAA22267 for hackers-outgoing; Tue, 10 Dec 1996 11:05:25 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id LAA22261 for ; Tue, 10 Dec 1996 11:05:20 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id LAA04595; Tue, 10 Dec 1996 11:43:36 -0700 From: Terry Lambert Message-Id: <199612101843.LAA04595@phaeton.artisoft.com> Subject: Re: Multiple Buffer allocation of Shared Memory To: scrappy@hub.org (Marc G. Fournier) Date: Tue, 10 Dec 1996 11:43:36 -0700 (MST) Cc: erich@lodgenet.com, hackers@freebsd.org In-Reply-To: from "Marc G. Fournier" at Dec 10, 96 01:20:06 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > 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.