You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Ioan Popescu <ip...@dataq.com> on 2007/10/23 21:52:26 UTC

SHM

Why does APR use file-backed shared memory for unix and win32?

Isn't it preferable to have key-based shared memory? Windows supports it
(both desktop and CE, I checked). I believe Unix supports it (I checked, but
I'm not sure) through System V IPC. Shouldn't the implementation default to
key-based unless the platform doesn't support it?

Re: SHM

Posted by Ioan Popescu <ip...@dataq.com>.
Mladen Turk wrote:
> What we could do is to have a backup file but like with unix
> APR_USE_SHMEM_SHMGET only store the size of the shared memory in it
> and use named swap for the actual share. You can do it for CE only, cause
> IMO there are no real benefits on NT platforms where it might even not
> work if the share is on the network drive.

I was under the impression that the file had to be the same size as the
mapped region.

In your case, not having a file would solve the network storage issue... Why
do you need the file? Why store the size? CreateFileMapping() on NT/CE tells
you if the map already exists and how big it is, no guessing. Unfortunately,
this doesn't seem to be available on all platforms... Is that the reason for
file backing? To determine the size?

Again, I'm just looking for a way to use shared memory, plain and simple; no
file, etc. If there's another portable way to do it, great. But I still
don't see the point of having two different interfaces shm/mmap behave
exactly the same way.

Re: SHM

Posted by Mladen Turk <mt...@apache.org>.
Ioan Popescu wrote:
> William A. Rowe, Jr. wrote:
>>
>> Win32 anonymous shared memory is actually file backed (backed, of course
>> by the swap file).
> 
> I'm not talking about anonymous shared memory (which can only be shared with
> child processes). Maybe I misunderstand how shm/mmap work, but my concern is
> I'm using half the memory allocated (one part file, one part RAM). This is
> an unnecessary problem on CE where files are stored in RAM (there's no swap
> file as it would be stored in RAM). Although there are persistent storage
> areas, they're not needed/used in this case.
>

What we could do is to have a backup file but like with unix
APR_USE_SHMEM_SHMGET only store the size of the shared memory in it
and use named swap for the actual share. You can do it for CE only, cause
IMO there are no real benefits on NT platforms where it might even not
work if the share is on the network drive.

Regards,
Mladen


Re: SHM

Posted by Ioan Popescu <ip...@dataq.com>.
William A. Rowe, Jr. wrote:
> Why?
> 
> Win32 anonymous shared memory is actually file backed (backed, of course
> by the swap file).

I'm not talking about anonymous shared memory (which can only be shared with
child processes). Maybe I misunderstand how shm/mmap work, but my concern is
I'm using half the memory allocated (one part file, one part RAM). This is
an unnecessary problem on CE where files are stored in RAM (there's no swap
file as it would be stored in RAM). Although there are persistent storage
areas, they're not needed/used in this case.

As you point out, it would result in three copies of the same data when only
one copy may be desired. In my case, only one copy is desired.

It seems like extra work to me to have to provide an actual file for shared
memory rather than just have a key-based (for uniqueness) block of shared
memory. It also doesn't differentiate between memory-mapped files. What's
the point of shared memory if it behaves exactly like memory-mapped files?

Re: SHM

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Ioan Popescu wrote:
> Why does APR use file-backed shared memory for unix and win32?
> 
> Isn't it preferable to have key-based shared memory? Windows supports it
> (both desktop and CE, I checked). I believe Unix supports it (I checked, but
> I'm not sure) through System V IPC. Shouldn't the implementation default to
> key-based unless the platform doesn't support it?

Why?

Win32 anonymous shared memory is actually file backed (backed, of course
by the swap file).

Bill