How to increase semaphore value in linux?

What is semaphore ?


Semaphore can be described as counters used to control access to shared resources by multiple processes, They are most often used as a locking mechanism to prevent processes from accessing a particular resource while another process is performing operations on it.

Semaphore can be used when number of processes try to access the shared resource or same file,Semaphore stored in kernel, so that it can be accessed by all the processes,

  •  Semaphore can be identified unique id in linux kernel and it can be deleted using semdelete function,
  • semaphore values can be incremented or decremented by using functions wait and signal,   
  • If we are using ONFS (Oracle over network file system) in linux, we need to increase the kernel.sem value to improve system performance

How to Increase semaphore value in linux?

To increase semaphore value we need to increase the value of kernel.sem.

[root@server ~]# sysctl -A | grep kernel.sem
kernel.sem = 250        32000   32      128

[root@server ~]# ipcs -ls

------ 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

Increase semop value from 32 to 100, it can be increased upto 250 which is equal to semaphores per array,

Add the following line into /etc/sysctl.conf file,

#vi /etc/sysctl.conf

kernel.sem = 250 32000 100 128

or 

#sysctl -w "kernel.sem = 250 32000 100 128"

or

#sysctl -w "kernel.sem=4096 512000 1600 2048" 
   

kernel.sem: max_sem_per_id max_sem_total max_ops_sem_call max_sem_ids

Now we have modified the kernel.sem value,

Please run the following command to update the changes 

[root@server ~]# sysctl -p

Now semaphore value got changed on server.you can verify using ipcs command.

1 comments:

Post a Comment

Blogger Tips and TricksLatest Tips And TricksBlogger Tricks