Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Jul 2013 10:39:26 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-arch@freebsd.org
Cc:        "Jordan K. Hubbard" <jordan.hubbard@gmail.com>
Subject:   Re: General purpose library for name/value pairs.
Message-ID:  <201307091039.26835.jhb@freebsd.org>
In-Reply-To: <D2E98A8F-F765-4A56-96CD-4410944A2910@turbofuzz.com>
References:  <20130704215329.GG1402@garage.freebsd.pl> <20130708213351.GB1405@garage.freebsd.pl> <D2E98A8F-F765-4A56-96CD-4410944A2910@turbofuzz.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Monday, July 08, 2013 6:09:40 pm Jordan K. Hubbard wrote:
> > FYI, FreeBSD can pass shared memory as file descriptors, see SHM_ANON in
> > shm_open(2).
> 
> OS X supports this as well.  The reason we make it an explicit type is for 
two reasons.  One is lifecycle management - you can't just close a fd 
representing a shared memory segment and have all the right things happen on 
last close (the segment itself won't be GC'd).  The second reason is that both 
ends want a fd in one case and an address in the other and it would be weird 
to mix and match metaphors just because the transport wanted to canonicalize 
everything into fds.

I'll only speak to the GC point.  For anonymous shm's (SHM_ANON), the segment
is in fact GC'd on last close as there is no name to hold a reference to it.

Note that this is an extension to the POSIX API.  These anonymous objects are
in fact quite useful for creating arbitrary shms, and we even have an API for
mapping them into KVA so that they can be great tools for doing shared memory
IPC between userland and kernel.

-- 
John Baldwin



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