|<< prev||next >>|
A shared memory arena file is a regular or shared memory device file /dev/shm that is mapped and shared by one or more processes. The Shared Memory Arena application programming interface (API) library provides structure to the file such that you may get pointers to the file that are in your processes virtual address space using a simpler interface than the underlying operating system provides. The API provides an abstraction layer that gives you a string name space to access pieces of the arena file. As a human you may think of address 0x2aaaaaed40c0 as being the segment named "cat". The address of "cat" will likely be different for process 0 as it is for process 2, but they get the pointers to these addresses using the name "cat" when you call sm_get(), sm_connect(), sm_create(), or shm_get(). The user of Shared Memory Arena has the option to select the a processes virtual address of the start of the shared memory by setting the environment variable SHM_ADDRESS to the address as a hex number. This enables processes to share pointers that point to addresses in shared memory from the Shared Memory Arena API.
There is a default shared memory arena file that is provided and can be changed through several user interfaces: the default configured C macro define, environment variables, or function arguments to shm_arena_create(). You may make and connect to any numbers of shared memory arena files from a given process or thread. To use a shared memory arena file you make a shared memory arena allocator object in your program with shm_arena_create(). shm_arena_create() is also used to create a shared memory arena file if it does not exist yet.
The main idea to get is that a shared memory arena file exists as a file and the Shared Memory Arena library API provides a simple user interface to it. The reading and writing to the shared memory in this file is fast given that the operating system does not synchronize the data in the file to your hard-drive unless it really needs to or it has time to waste.
Though the above image shows the segment as a flat array there is meta data maintained with the segment data that orders them into a self balancing AVL tree, making finding, inserting, and deleting of segments very fast.
The first time we heard of shared memory arenas was from SGITM. The SGI shared memory arenas where limited to a fixed size, and the memory mapping addresses where the same between processes, which would lead to address space conflicts if you were not lucky. Programs using SGI arenas were sometimes required to manage the virtual address of the shared memory in order to use it. On the plus side, you could have structures with pointers to addresses in the shared memory when using SGI shared memory arenas. When designing Shared Memory Arena we thought that it was nicer to be assured that any program could access the shared memory, than to have general use of pointers in shared memory to shared memory. With Shared Memory Arena the user may at their option map to the same addresses between processes by setting the environment variable SHM_ADDRESS.
|<< prev||next >>|