httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brad.Good...@schange.com
Subject APR Shared Memory Usage
Date Tue, 12 Apr 2011 14:19:57 GMT
I am a bit confused about the "correct" way to use the shared memory 
functions in the APR library, namely, how do I create/open a shared memory 
segment on the "first" process, and have subsequent processes use the same 
shared memory area.

If I do a apr_shm_create and pass a NULL filename, APR uses the following 
call (Unix) to open the shared memory segment:

        shmget(IPC_PRIVATE, new_m->realsize,SHM_R | SHM_W | IPC_CREAT)

This will create and open an unnamed segment. Since there is no reference 
in the code to anything getting key of the segment, I don't believe there 
is any mechanism here to allow another process to attach to this - unless 
of course I am missing something.

If I do an apr_shm_create call and pass a filename, APR tries to do an 
exclisuve file create on this filname, failing and returning an error if 
the file already exists. Therefore, the first caller can use this to 
create and open the shm, but subsequent callers cannot.

I would assume that subsequent callers could use apr_shm_attach to then 
attach to an existing shared memory segment, however, it appears that this 
function is not used anywhere in the apache (2.2) code base whatsoever. 
(It is used in one or two places in 2.3). 

So aside from the fact that I don't understand how this works as all as 
implemented - even in places where it is used and obviously works, like 
the scoreboard - what is the "correct" way to actually do this?


Mime
View raw message