Shared Memory Settings In Linux With Examples

February 25, 2011 | By
| Reply More

Shared Memory

Shared memory is the memory that may be accessed by multiple processes; i.e. a memory region that can be shared between different processes and a better way of passing data between two processes. Shared memory is the fastest form of Inter Process Communication which is currently available. Assume that the program will create a memory portion, which another process can access (if permitted). A shared segment can be attached multiple times by the same process. Whenever the memory is mapped into the address space of the process, i.e. sharing the common memory region, the kernel will not involve while passing data between the processes. Many applications, like oracle SGA requires shared memory settings, use this feature .

Example:

[root@localhost ~]# ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 65536 root 600 393216 2 dest
0x00000000 98305 root 600 393216 2 dest

Print information about active shared memory segments.

[root@localhost ~]# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages

Print information about active shared memory queues.

[root@localhost ~]# ipcs -s
------ Semaphore Arrays --------
key semid owner perms nsems

Print information about semaphores that is accessible semaphores. The ipcs –l shows limit of shared memory, semaphores and messages.

[root@localhost ~]# ipcs -l
------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 4194303
max total shared memory (kbytes) = 1073741824
min seg size (bytes) = 1

------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767

------ Messages: Limits --------
max queues system wide = 16
max size of message (bytes) = 65536
default max size of queue (bytes) = 65536

Below command shows maximum size of the single memory segment that linux process can allocate in its virtual address space. You can limit maximum size of the single memory segment by executing following command.

[root@localhost kernel]# cat /proc/sys/kernel/shmmax
4294967295

You can set shmmax value by echoing to the concerned/proc file as below. Below command will set maximum size (in terms of bytes) single memory segment is set to 8388698.

[root@localhost kernel]# echo 8388608 > /proc/sys/kernel/shmmax

In similar fashion, you can set maximum allowable size of any single message in a System V IPC message queue, in bytes.

[root@localhost kernel]# echo 8192 > /proc/sys/kernel/msgmax

You can check current kernel parameter for semaphore with following command.

[root@localhost kernel]# cat /proc/sys/kernel/sem
250 32000 32 128
where
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767

Filed Under : HOWTOS, LINUX HOWTO

Tagged With :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.