Skip to content
Search

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

Libraries

Kernel settings

You can set the maximum size with sysctl.

/sbin/sysctl -w kernel.shmmax=256000000

Check with the following command:

/sbin/sysctl -a
Maximum shared memory segment size (SHMMAX)
The value set in the /proc/sys/kernel/shmmax file.
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/shmall file.
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/shmmni file.
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:

kernel.shmmax = 2147483648
kernel.shmall = 524288
kernel.shmmni = 4096

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

author Zer0 sitemap