Get confused about how to calculate SHMMAX and SHMALL on Linux.
xportMar 16 2013 — edited Mar 17 2013 Hi guys,
thanks for your time over here.
recently, I'd read the linux kernel header file '/usr/include/linux/shm.h' and seen something of the macro definitions for SHMMAX and SHMALL, it looks like these:
-----
/*
* SHMMAX, SHMMNI and SHMALL are upper limits are defaults which can
* be increased by sysctl
*/
#define SHMMAX 0x2000000 /* max shared seg size (bytes) */
#define SHMMIN 1 /* min shared seg size (bytes) */
#define SHMMNI 4096 /* max num of segs system wide */
#define SHMALL (SHMMAX/getpagesize()*(SHMMNI/16))
#define SHMSEG SHMMNI /* max shared segs per process */
-----
did you see the SHMALL = SHMMAX/getpagesize()*(SHMMNI/16)?
so if PAGE_SIZE was set to 4096, we can get SHMALL = SHMMAX/16 based on the above formular.
but I found acturally the system did NOT run as the macro definitions, because sysctl -a output display like these:
-----
kernel.shmmax = 1073741824
kernel.shmall = 262144
kernel.shmmni = 4096
-----
did you see that shmall had been set by SHMMAX/PAGE_SIZE in pages.
Finally, I'm getting confused why the acctually behavior was not like the kernel header files, and how to calculate the two kernel parameters in real word.
thanks for your help.