Monday, November 18, 2013

Changing Shared Memory size in linux

view Shared Memory limits

Use the ipcs command to view the limits.

ipcs -ml
Output of the above command will look like

------ Shared Memory Limits --------                                                                                                                                                          
max number of segments = 4096                                                                                                                                                                 
max seg size (kbytes) = 67108864                                                                                                                                                              
max total shared memory (kbytes) = 17179869184                                                                                                                                                
min seg size (bytes) = 1                                                                                                                                                                      

Changing shared memory size

There are 3 parameters which we should be aware of:

SHMMAX

This defines the maximum size in bytes of a single shared memory segment that a Linux process can allocate. To set this value, change /proc/sys/kernel/shmmax to the desired value

echo 2147483648 > /proc/sys/kernel/shmmax
We can also use sysctl to change it.
sysctl -w kernel.shmmax=1073741824

SHMMNI

This defines the system wide maximum number of shared memory segments.
To change:

sysctl -w kernel.shmmni=4096

SHMALL

This parameter sets the total amount of shared memory pages that can be used system wide.
Hence, SHMALL should always be at least ceil(shmmax/PAGE_SIZE). To change:

sysctl -w kernel.shmall=2097152
If not sure what the default PAGE_SIZE is, run the following command:
getconf PAGE_SIZE

To make a permanent change, edit /etc/sysctl.conf file.

echo "kernel.shmmax=2147483648" >> /etc/sysctl.conf
To load sysctl.conf after the change:
sysctl -p

No comments :