Shared Memory Settings In Linux With Examples

| February 25, 2011 | 0 Comments

Shared Memory

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

Example:

[root@localhost ~]# ipcs -m
—— Shared Memory Segments ——–
key shmid owner perms bytes nattch status
0×00000000 65536 root 600 393216 2 dest
0×00000000 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

Tags: ,

Category: Linux Administration

Leave a Reply

You must be logged in to post a comment.