apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject Re: Shared memory segment management
Date Wed, 19 Apr 2006 10:41:38 GMT
On Tue, Apr 18, 2006 at 01:39:54PM -0700, Tyler MacDonald wrote:
> 	The problem is/was that APR's implementation of "portable" shared
> memory falls back on one of several different shared memory implementations,
> which have different operating patterns. Under linux, it seems to default to
> System V IPC; if that fails, it falls back on other implementations, one of
> which is mmap().
> 	But the two systems work in completely different ways. The main
> problem I was having, was that when an apache process is forcibly killed, it
> has no way to tell the OS that the shared memory is no longer needed. Then
> when it restarts, SysV IPC is still holding onto the memory so
> apr_shm_create fails.

Two points to note here: apr_shm_remove() was added in APR 1.0 which 
somewhat mitigates the problem: but really it sounds like you should be 
using anonymous shm (pass a NULL filename to apr_shm_create).  At least 
some of the anon shm implementations give the behaviour you're 

> 	Looking at the configure.in for APR distributed with Apache 2.2, it
> looks like SysV IPC is still the choice preferred by APR, even though this
> creates an obvious behavioural difference for the same code running against
> APR on operating systems that have SysV IPC and operating systems that
> don't. 
> 	Has there been any further discussion among the APR developers about
> this? Why is SysV IPC the "preferred" choice in the first place? For the
> behaviour I want (shared memory goes away when creating process dies) is
> there a better implementation available using APR, or will I be forced to
> bring another library into the mix, such as libmm?

IIRC the logic for choice of name-based shm implementation for APR does 
exactly match that of MM - is that not true?  I don't know why shmget is 
preferred over mmap in this case.  For anonymous shm, mmap/MAP_ANON is 
indeed preferred over shmget, which does seem inconsistent.


View raw message