Linux – Shared memory: shmget fails: No space left on device — how to increase limits

linuxsysctl

I call shmget many times in my program, to get shm of of average size 85840 bytes. I obtain about 32771 shm ok, then shmget doesn't return a shm, but the error: "No space left on device".

I have increased the kernel limits to:

$ sysctl -A|grep shm
kernel.shmmax = 33554432
kernel.shmall = 1677721600
kernel.shmmni = 409600

But still get the issue. Why?

Do I have to put something into /etc/security/limits.conf too? I only have
"user – nofile 1000000"
because the program also opens about as many files as shms.

This is the output of free

$ free
          total       used       free     shared    buffers     cached
Mem:       8150236    7261676     888560          0     488100    3270792
-/+ buffers/cache:    3502784    4647452 
Swap:     12287992     554692   11733300

And ipcs

$ ipcs -lm                                                                         

------ Shared Memory Limits --------
max number of segments = 409600
max seg size (kbytes) = 1638400
max total shared memory (kbytes) = 6710886400
min seg size (bytes) = 1

Since I assume shm is capable of being swapped out, there should be enough space.

Best Answer

It turns out shmmni is limited to 32768 in the kernel:

#define IPCMNI 32768  /* <= MAX_INT limit for ipc arrays (including sysctl changes) */

in the file ...version.../include/linux/ipc.h.

So short of recompiling the kernel, that is the hard limit on the number of shared memory segments.