shmmax和shmall

Linux kernel中针对shared memory有两个重要的配置项:shmmaxshmall

shmmax定义了一次分配shared memory的最大长度,单位是byte

# cat /proc/sys/kernel/shmmax
18446744073692774399

shmall定义了一共能分配shared memory的最大长度,单位是page

最大“shared memory” = shmall(cat /proc/sys/kernel/shmall) * pagesize(getconf PAGE_SIZE)

shmmax为例,介绍一下修改值的方法:

(1)现在系统shmmax的值:

# sysctl -a | grep shmmax
kernel.shmmax = 18446744073692774399

(2)修改shmmax的值:

# echo "536870912" > /proc/sys/kernel/shmmax
# sysctl -a | grep shmmax
kernel.shmmax = 536870912

可以看到值发生了变化。但是重启系统以后,shmmax又变回之前的值。如果要让值永久生效,可以使用下列方法:

# echo "kernel.shmmax = 536870912" >>  /etc/sysctl.conf
# sysctl -a | grep shmmax
kernel.shmmax = 18446744073692774399
# sysctl -p
kernel.shmmax = 536870912
# sysctl -a | grep shmmax
kernel.shmmax = 536870912

另外,关于如何设置shmallshmmax的值,也可以参考这个脚本

参考资料:
The Mysterious World of Shmmax and Shmall
Configuring SHMMAX and SHMALL for Oracle in Linux
What is shmmax, shmall, shmmni? Shared Memory Max