POSIX shared memory

The Linux kernel supports POSIX shared memory through a special filesystem called tmpfs, which is mounted on to /dev/shm of the rootfs. This implementation offers a distinct API which is consistent with the Unix file model, resulting in each shared memory allocation to be represented by a unique filename and inode. This interface is considered more flexible by application programmers since it allows standard POSIX file-mapping routines mmap() and unmap() for attaching and detaching memory segments into the caller process address space.

Following is a summarized description of interface routines:

API Description
shm_open() Create and open a shared memory segment identified by a filename
mmap() POSIX standard file mapping interface for attaching shared memory to caller's address space
sh_unlink() Destroy specified shared memory block
unmap() Detach specified shared memory map from caller address space

 

The underlying implementation is similar to that of SysV shared memory with the difference that the mapping implementation is handled by the tmpfs filesystem.

Although shared memory is the easiest way of sharing common data or resources, it dumps the burden of implementing synchronization on the processes, as a shared memory infrastructure does not provide any synchronization or protection mechanism for the data or resources in the shared memory region. An application designer must consider synchronization of shared memory access between contending processes to ensure reliability and validity of shared data, for instance, preventing a possible write by two processes on the same region at a time, restricting a reading process to wait until a write is completed by another process, and so on. Often, to synchronize such race conditions another IPC resource called semaphores is used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.6.75