Linux IPC and Limits

Note: POSIX implementation provides better and cleaner api to IPC compared to System V. Prefer using POSIX api if you are known to be running on 2.6 or later kernel.

System V IPC implementation on Linux includes Shared memory, Semaphores and Message queues. There are system imposed limits that are important to keep in mind when developing application/services in Linux.


To know the limits use ipcs command. For example on my system:
[root@f7 ~]# ipcs -l

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

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

------ Messages: Limits --------
max queues system wide = 16
max size of message (bytes) = 8192
default max size of queue (bytes) = 16384

Or via sysctl interface:
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.shmmax = 33554432

kernel.sem = 250 32000 32 128

kernel.msgmni = 16
kernel.msgmax = 8192
kernel.msgmnb = 16384

We can understand more about these limits by reading the man pages for svipc, shmget, semget, msgget.
  • MSGMNI - System wide maximum number of message queues: policy dependent (on Linux, this limit can be read and modified via /proc/sys/kernel/msgmni).
  • MSGMAX - Maximum size for a message text: 8192 bytes (on Linux, this limit can be read and modified via /proc/sys/kernel/msgmax).
  • MSGMNB - Default maximum size in bytes of a message queue: 16384 bytes (on Linux, this limit can be read and modified via /proc/sys/kernel/msgmnb). The superuser can increase the size of a message queue beyond MSGMNB by a msgctl() system call.
  • The implementation has no intrinsic limits for the system wide maximum number of message headers (MSGTQL) and for the system wide maximum size in bytes of the message pool (MSGPOOL).
  • SEMMNI - System wide maximum number of semaphore sets: policy dependent (on Linux, this limit can be read and modified via the fourth field of /proc/sys/kernel/sem).
  • SEMMSL - Maximum number of semaphores per semid: implementation dependent (on Linux, this limit can be read and modified via the first field of /proc/sys/kernel/sem).
  • SEMMNS - System wide maximum number of semaphores: policy dependent (on Linux, this limit can be read and modified via the second field of /proc/sys/kernel/sem). Values greater than SEMMSL * SEMMNI makes it irrelevant.
  • SHMALL - System wide maximum of shared memory pages (on Linux, this limit can be read and modified via /proc/sys/kernel/shmall).
  • SHMMAX - Maximum size in bytes for a shared memory segment: policy dependent (on Linux, this limit can be read and modified via /proc/sys/kernel/shmmax).
  • SHMMIN - Minimum size in bytes for a shared memory segment: implementation dependent (currently 1 byte, though PAGE_SIZE is the effective minimum size).
  • SHMMNI - System wide maximum number of shared memory segments: implementation dependent (currently 4096, was 128 before Linux 2.3.99; on Linux, this limit can be read and modified via /proc/sys/kernel/shmmni).
  • The implementation has no specific limits for the per process maximum number of shared memory segments (SHMSEG)
These numbers can be changed by writing to the corresponding /proc files. Or you can use the sysctl to do the same. To persist the settings across reboots, they have to written to /etc/sysctl.conf

Popular posts from this blog

htop: more than top. pstree: ps with tree.

Access Apache WebDAV from Windows XP