Subject: Re: POSIX shm_open() vs. mmap(MAP_ANON|MAP_SHARED)....
To: NetBSD Kernel Technical Discussion List <tech-kern@netbsd.org>
From: Greywolf <greywolf@starwolf.com>
List: tech-kern
Date: 07/09/2003 13:00:03
Thus spake Greg A. Woods ("GAW> ") sometime Today...

GAW> shm_unlink(), like unlink(), takes a pathname parameter, so given the
GAW> fact shm_open() names are strictly outside the normal visible filesystem
GAW> space then you need a matching unlink() interface to work in this
GAW> private, invisible, namespace.  (or at least you do so long as you don't
GAW> also have something like a funlink() call that takes an open file
GAW> descriptor as its parameter :-)

Um, slightly off-topic, but wouldn't funlink() be somewhat disastrous in
practice? (I presume that's why the smiley).  That would require a file-
system cleaner process or a routine that knew instantly how to match inode
numbers to pathnames (as it was explained to me, "The kernel routine is
called namei() for a reason.  You will note that there is no converse
routine, since while name -> ino-dev is unique for each ino-dev, the
reverse is untrue -- consider /foo/bar/.. and /foo, for example...").

GAW> > Thus the horrible
GAW> > mmap() of /dev/zero hack, btw..
GAW>
GAW> Hmmm.... yes.  What a stupid idea that was.  :-)  (A NULL vnode pointer
GAW> was apparently supposed to suffice such that a /dev/zero vnode was
GAW> unnecessary.)

Wow, a (vno_t *) NULL was supposed to allow one to create pre-cleared
pages in memory?

Despite its ugliness, /dev/zero has other uses, such as creating
arbitrarily large filespaces (for, e.g., swap (don't go there.)) without
having to rewrite a program to handle it -- one can use dd for it,
though I wouldn't have minded a 'mkfile' program to do the same thing
(thus avoiding the need for /dev/zero).

I have a question regarding mmap()ing /dev/zero:

    Purportedly this was used by crt0.o and/or ld.so to create blank spots
    into which to load the dynamic libraries.  Surely the same thing could
    have been accomplished with *alloc() and a clear routine, or
    mmap() could just pre-zero whatever pages it maps.  Was /dev/zero
    *truly* necessary?  Its sudden disappearance once or thrice on
    SunOS was the cause of some concern (more so after it was discovered
    that mknod(8) was dynamically linked (genius--;)).

				--*greywolf;
--
I pushed my DeLorean to 88 MPH, and all I got was this stupid speeding ticket.