Shared memory
lastmod 2024-08-20created 2017-05-2317 edits
Shared memory is memory that multiple programs can access simultaneously in a computing environment. It is designed to avoid excessive copying or to enable communication between those programs. Depending on the environment, the programs may run on a single processor or on multiple processors. Using memory for communication within a single program (for example, between multiple threads) is generally not called shared memory.
Categories
- Python:mmap: IPC using Python's Memory Map
- Python:SharedArray
- Python:multiprocessing.shared_memory
Libraries
Kernel settings
You can set the maximum size with sysctl.
Check with the following command:
Related variables and status queries
- Modifying kernel parameters for DB2 Connect (Linux) - IBM Documentation
- Modifying kernel parameters (Linux) - IBM Documentation
- Maximum shared memory segment size (SHMMAX)
- The value set in the
/proc/sys/kernel/shmmaxfile. - This value specifies the maximum size of a single shared memory segment, in bytes.
- Total shared memory available system-wide (SHMALL)
- The value set in the
/proc/sys/kernel/shmallfile. - This value specifies the total size of shared memory available to the whole system, in pages. (1 page is usually 4096 bytes)
- Maximum number of shared memory segments (SHMMNI)
- The value set in the
/proc/sys/kernel/shmmnifile. - This value specifies the maximum number of shared memory segments available on the system.
After changing the settings above, you can add the following to the /etc/sysctl.conf file so that they persist across system reboots:
Then run the sysctl -p command to apply the settings.
Additionally, to check the shared memory segments currently in use on the system, you can use the ipcs command. This command shows the status of the system's current shared memory segments, semaphore arrays, and message queues:
This command prints a list of all shared memory segments currently in use on the system. You can see each segment's key, ID, owner, size, and other information.
You can also check the amount of shared memory currently in use, along with overall system memory information, through the /proc/meminfo file.
See also
Favorite site
Windows
- [https://msdn.microsoft.com/ko-kr/library/windows/desktop/aa366551(v=vs.85.aspx MSDN - Creating Named Shared Memory]
- Sharing memory between processes using file mapping
- TipsSoft > Our Stories > A brief explanation and example of Shared Memory
- Let's use shared memory (MMF)
- Shared memory usage example