Linux - Kernel Semaphore parameters

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix

1 - About

On Linux, A semaphore is a System V IPC object that is used to control utilization of a particular process.

Semaphores are a shareable resource that take on a non-negative integer value. They are manipulated by the P (wait) and V (signal) functions, which decrement and increment the semaphore, respectively. When a process needs a resource, a “wait” is issued and the semaphore is decremented. When the semaphore contains a value of zero, the resources are not available and the calling process spins or blocks (as appropriate) until resources are available. When a process releases a resource controlled by a semaphore, it increments the semaphore and the waiting processes are notified.

The Semaphore Kernel parameters

Semaphore Description Minimum
SEMMSL maximum number of semaphores per array 128
SEMMNS maximum semaphores system-wide
SEMOPM maximum operations per semop call
SEMMNI maximum arrays
Advertising

3 - How to

3.1 - Display them ?

This command displays the value of the semaphore parameters:

# /sbin/sysctl -a | grep sem

3.2 - Calculate them ?

  • Calculate the minimum total semaphore requirements using the following formula:
sum (process parameters of all database instances on the system) + system and other application requirements
  • Set semmns (total semaphores systemwide) to this total.
  • Set semmsl (semaphores per set) to 256.
  • Set semmni (total semaphores sets) to semmns / semmsl rounded up to the nearest multiple of 1024.

The following formula can be used as a guide, although in practice, SEMMNS and SEMMNU can be much less than SEMMNI * SEMMSL because not every program in the system needs semaphores.

SEMMNS = SEMMNU = (SEMMNI * SEMMSL)

3.3 - Set them ?

In the file, /etc/sysctl.conf

kernel.sem = 2200 6400 200 25

Where:

kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI

Then reboot or run this command:

# /sbin/sysctl -p
Advertising

4 - Documentation / Reference