Common Misconfigured HP-UX Resources (April 2006)
Semaphores Tables
Many third-party applications, databases in particular, make extensive use of the semaphores
(commonly referred to as System V IPC) available in HP-UX 11i v1 and higher. The installation guides
of third party products often recommend changing the tunables associated with semaphores. The
purpose of this document is to describe the memory impacts that are caused by changing these
tunables.
This section addresses the following questions about semaphores:
• What is a semaphore?
• What interfaces are used to access semaphores?
• What tunables affect semaphore memory usage?
• How much memory is used to manage the semaphore tables?
• Are there any guidelines for configuring the semaphore tables?
What is a Semaphore?
Although this document will not go into the details of implementation, it is important to understand
what a semaphore is, how it is used, and what the various tunables actually control.
In simple terms, a semaphore is a construct that is used to control access to a set of resources. It has a
count associated with it that determines how many resources are available. Resources are allocated
by decrementing the count and returned by incrementing the count. All updates to the semaphore are
done atomically through system calls. When all resources have been given out, the next process that
attempts to allocate one will go to sleep until a resource is freed, at which point it will be awakened
and granted access.
A simple example will suffice to make this clear. Suppose we have three stations that can serve us.
We can control access by having 3 tokens. The first person takes a token, then the second person,
then the third person. Each of these people can be served simultaneously. If a fourth person wishes to
be served, that person must wait until a token becomes available. When any person finishes, the
token is returned and the next person in line can take it. Of course, the degenerate case is when the
count is set to 1, which is how one could implement exclusive access. This is the basic idea and is the
mechanism databases frequently use to control concurrent access.
Interfaces
There are three main interfaces that you can use to manage semaphores: semget(), semctl(),
and semop(). The semget()routine allocates a set of semaphores. You can allocate more than
one semaphore at a time and operations can be conducted on these sets. A successful call to
semget() will return a semaphore identifier. The semop()routine operates on a set of semaphores.
Finally, the semctl() routine performs control operations on the semaphore set. For more details,
refer to the manpages for these calls.
31