Previous Entry Share Next Entry
Shared memory crazyness
2005
mones
The output of some commands explains it all.

These are the default values in a Wheezy system:

$ 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


That's not enough for all the data I want to load in a single segment, so let's start with 1Gb of shared memory:

# sysctl kernel.shmmax=1073741824 kernel.shmall=1073741824
kernel.shmmax = 1073741824
kernel.shmall = 1073741824

So now, both should be equal, isn't it?

$ ipcs -l

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

Uh!?

A free $BEVERAGE when we met for the one which tells me what's happening here ;-)

Hi,

It is not that crazy after all. kernel.shmmax is set in bytes while kernel.shmall is set in pages.

Ahh, that's it! Thanks! :-)

# sysctl kernel.shmmax=1073741824 kernel.shmall=$((1073741824 / 4096))
kernel.shmmax = 1073741824
kernel.shmall = 262144


Now it looks better:
$ ipcs -l

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


Edited at 2013-11-26 12:01 pm (UTC)

oh and I forgot to mention that shmmax is limited to 4GB on 32bit systems.

shmall is a number of pages (4KiB), so setting it to 1073741824 gives you 4KiB*1073741824 = 4294967296 KiB of "max total shared memory".

shmmax is a number of Bytes, so setting it to 1073741824 leads to a "max seg size (kbytes)" of 1048576

At least that's what I gather from setting a few different values and looking at the output of "ipcs -l" :)

Right, somehow I expected both to be set in the same units.

With kernel.shmmax=1073741824 you instructed system to be able to create maximum shared memory segment of size 1073741824 [ bytes ]

With kernel.shmall=1073741824 system was instructed about "total amount of shared memory" ... in pages [ PAGES ] ( # getconf -a | grep PAGESIZE )

There is no need to change kernel.shmmax and kernel.shmall at same time, either change kernel.shmmax ( shared memory segment size ) and kernel.shmmni ( number of shared segments ) - both of them, or change only kernel.shmall.

If you change kernel.shmmax and kernel.shmmni then you say system, create kernel.shmmni memory segments with size of kernel.shmmax - that is. But this size cannot be bigger than total amount of shared memory ( kernel.shmall [ PAGES ] ).

It should be ( usually is )

kernel.shmmni * kernel.shmmax = kernel.shmall

In above case :

(kernel.shmmax) 1073741824 * ( kernel.shmmni ) 4096 = 4398046511104 [ bytes ]
(kernel.shmall) 1073741824 * (4096 = page size ) = 4398046511104 [ bytes ]

Hopefully more clear now , or I miss something .deb specific in above....I am open to learn more.

Regards

E.


You are viewing mones