How to Change Kernel Semaphore Limits in CentOS/RHEL

How to Change Kernel Semaphore Limits in CentOS/RHEL

 

The post explains how kernel semaphore limits can be changed in a CentOS/RHEL server.

Kernel Parameters to set semaphore limits

The kernel parameters to set the semaphore limits are:

kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI
SEMMSL - max semaphores per array
SEMMNS - max semaphores system wide
SEMOPM - max ops per semop call
SEMMNI - max number of arrays

Changing Semaphore Limits

If a limit needs to be changed there should be taken in to account that (max number of arrays)*(max semaphores per array) >= (max semaphores system-wide). No need to have more semaphores system-wide if limited by the amount of a possible number of arrays with max semaphores per it.

 

For example:

# sysctl -a| grep kernel.sem
kernel.sem = 250 32000 32 128

For this example, we need to increase max semaphores per array limit from 128 to 192. The max semaphores system-wide can be also increased to 48000 ( 250*192 = 48000 >= 32000) or kept as 32000. In this scenario, it is kept at 32000.

To set kernel parameter dynamically i.e. without the need for server reboot.

# sysctl -w kernel.sem="250 32000 32 192"
kernel.sem = 250 32000 32 192

If all is fine with the system as expected, modify kernel parameter by adding it to the /etc/sysctl.conf file to ensure the value persist after server reboot.

# cat /etc/sysctl.conf | grep kernel.sem
kernel.sem = 250 32000 32 192

If you choose to set it directly in the file without using the sysctl -w, you’ll need to reload the file:

# sysctl -p

You can verify limits currently set by:

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

A semaphore is like a counter used to control access to shared resources by multiple processes. It is often used as a locking mechanism to prevent processes from accessing a particular resource while another process is performing operations on it. Semaphore value can be incremented or decremented until maximum set by variable SEMVMX, “semaphore max value”.

posted @ 2022-02-23 20:12  耀阳居士  阅读(83)  评论(0编辑  收藏  举报