About

Shared memory is the third type of memory.

It's a way to shared state between process.

The structure that is shared is called a segment.

Shared memory, as its name implies, is a method to share data between process. Both processes define the same memory area as shared, and they can then exchange information simply by writing into it. This (used to be, and still is somewhat) faster than the alternative of sending network or pipe-based messages between processes.

If you see the memory as a mean of storing data, a file on a file system can be seen as shared memory (ie shared file).

It is difficult to account for shared memory. Does it belong to one process? Both? Neither? If we naively sum the memory belonging to multiple processes, we grossly “over-count”.

As the name implies, the Shared (Virtual) Memory refers to virtual memory that are shared by more than one process and then can be used by multiple programs simultaneously.

Although virtual memory allows processes to have separate address spaces, there are times when you need processes to share memory.

Shared memory (SHM) is another method of interprocess communication (IPC) whereby several processes share a single chunk of memory to communicate.

Shared memory provides the fastest way for processes to pass large amounts of data to one another.

Linux

  • In Linux, shared memory looks like a regular file system - /dev/shm (but is under the hood Tmpfs).
  • Linux supports the Unix TM System V shared memory IPC.

Documentation / Reference