Shared Memory and Its Features

Shared Memory helps in passing on data between programs. A memory portion created by a program can be accessed by other processes, if allowed. In other words, Shared memory is an extra portion of memory that is attached to some address spaces, which the owners can use. Here all the processes can access and share the same memory segment. Shared memory is a feature that is supported by UNIX System V, including Linux, SunOS and Solaris systems.

Using the key, one process will explicitly ask for a portion to be shared by other processes. This process will be then called in the server. All other processes / clients who know the shared area can now access the same. The disadvantage of shared memory is that it lacks in security feature as there is no protection to a shared memory and any process that knows it can freely access it. A synchronization protocol should be setup to protect a shared memory from being accessed at the same time by several processes.

A shared memory segment is identified by unique integers, which are known as the shared memory IDs. The shared memory itself is described by a structure of type ‘shmid_ds in header file sys/shm.h’. To use this file, files sys/types.h and sys/ipc.h’ should be included. Therefore, the program should start with the following lines:

Example:

#include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h>

In the Solaris 2.x operating system, the most efficient way to implement shared memory application is to rely on the mmap() function and on the system’s native virtual memories facilities. Solaris 2.x also supports System V shared memories, which is another way to let multiple processes attach the segment of physical memory to their virtual address space. When write access is allowed for more than one processes, an outside protocol or mechanism such as a semaphore can be used to prevent the inconsistencies and collisions. shmctl() is used to alter the permission and other characteristics of a shared memory segment. It is prototyped as follows:

int shmctl(int shmid, int cmd, struct shmid_ds *buf);

The processes must have an effective shmid of owner, creator or super-user to perform this command. “The cmd argument is one of the following control commands: SHM_LOCK — Locks the specified shared memory segments in memory. The process must have the effective ID of super-user to perform this command. SHM_UNLOCK — Unlocks the shared memory segments. The process must have the effective ID of superuser to perform this command. IPC_STAT — Returns the status information contained in the control structure and place it in the buffer pointed to by buffer. The process must have read permissions on the segment to perform these commands. IPC_SET — Set the effective user, group identification and access permissions. The process must have an effective ID of owner, creator or super-user to perform this command. IPC_RMID — Remove the shared memory segment. “

The shared memory systems is relatively easy to program, since all the processors share a single view of data and the communication between processors can be really fast, as memory is always accessed to the same location. The issues with shared memory systems are that CPUs demand fast access to memory and will rely on cache memory, which has two complications:

1. Access time degradations: when several processors try to access the same memory locations, it causes contention.

2. Lack of data coherence: Whenever the cache is updated with information that may be used by other processor, the changes need to be reflected in the other processors as well; otherwise the different processor will be working with the incoherent data.

Related Posts

WAF, a Popular Automation Tool

WAF is one among the various popular automation tools like Apache Ant, Bazel, CMake, and Make. Automation tools are used to facilitate the compilation and installation of an application/software/package in a system. The importance of automation can be best explained through an imaginary situation like 100 coded files required to be compiled to complete the… Read more »

NMAP, The Free and Open Source Tool

In an unsecured scenario, security tools are inevitable to safeguard your system. A plethora of security tools are available in the market for network administrators to make use of. These are paid tools, which are based on FOSS (Free and Open Source Software). Here, let’s have a look at Nmap. Nmap stands for Network Mapper…. Read more »

Features of NewSQL

NewSQL is a class of modern Relational Database Management System that seek to provide the same scalable performance of NoSQL systems for Online Transaction Processing (OLTP) and read-write workloads, while maintaining the ACID guarantees of a traditional database system. The term was first used by 451 Group analyst Matthew Aslett in a 2011 research paper,… Read more »

MemSQL : SQL based Database Management System

MemSQL is a distributed SQL based Database Management System. On April 23, 2013, MemSQL launched its first generally available version of the database to the public. In order to process highly volatile workloads, MemSQL combines lock-free data structures and just-in-time compilation (JIT). More specifically, MemSQL implements lock-free hash tables and lock-free skip lists in memory… Read more »