Skip to content

Shared Memory

All the files Aeron Transport creates are in shared memory. Here's a quick explainer on how shared memory is used, for those that might not be familiar with it.

Memory mapped files

In an application, you can open a regular disk file in a memory-mapped mode. This gives you a buffer in memory that appears to contain the file's contents. You can use simple buffer operations to read / write the contents rather than file operations and the buffer operations are mapped to the file by the OS automatically, in an efficient manner.

Shared memory files

On Linux systems, you can create memory buffers that can be shared between processes, i.e. shared memory. The shared memory device shm exposes these buffers as files with filenames. The shm device is mounted within the devices directory, giving /dev/shm, so files below the /dev/shm directory aren't actually files on disk, they are shared memory regions, identified by filenames. They can be created, read, written and have permissions set on them just like any other file on a Linux filesystem, but they don't exist on disk, they exist in memory.

Memory mapping shared memory files

If you combine the above two concepts and open a shared memory file as a memory mapped file, you are creating a memory map of a file that happens to be a chunk of shared memory. In reality, you don't end up with a memory map buffer that is mapped to a shared memory buffer - you end up accessing the shared memory buffer directly.

This means if two processes on the same machine open the same file within /dev/shm, they will both have direct access to the same buffer in memory and can thus communicate with each other very efficiently through it.

In Aeron, you can talk to another process via IPC if it's on the same machine. This works by both applications sharing the same memory mapped shared memory files as described here.