views:

571

answers:

2

Hi.

Having learnt a bit about the subject, can anyone tell, what is the real difference between POSIX shared memory (shm_open) and POSIX mapped files (mmap)?

Both seems to use the /dev/tmpfs subsystem, rather then older IPC mechanism.

So is there any advantage of using mmap file over shared memory?

Thanks.

+2  A: 

The distinction is not always clear. Shared memory can be implemented via memory mapped files. An excellent write on this can be found here (as applied to C/C++ programming).

ennuikiller
A: 

My understanding is that that shared memory is built on top of mapped files, but This Page seems to indicate that the ability to use memory mapped files as shared memory is conditional.

The use of the mmap() function is restricted by the QSHRMEMCTL System Value. When this system value is 0, the mmap() function may not create a shared mapping having with PROT_WRITE capability. Essentially, this prevents the creation of a memory map that could alter the contents of the stream file being mapped. If the flags parameter indicated MAP_SHARED, the prot parameter specifies PROT_WRITE and the QSHRMEMCTL system value is 0, then the mmap() functions will fail and an error number of EACCES results.

John Knoeller
Fairly certain QSHRMEMCTL is iSeries specific. There is no mention of it in http://www.opengroup.org/onlinepubs/007908775/xsh/mmap.html for instance. Like so many questions about Unix apis, the answer really depends on which unix.
Logan Capaldo
@Logan: fair enough, it did seem like an unreasonable restriction.
John Knoeller