如何设置共享内存并使其可用?

如何设置共享内存并使其可用?

我尝试在 CentOS 上为 Sybase ASE 12.5 设置共享内存。我的服务器有 17G 内存,我想让 14G(=17-1-2)可用于 sybase。(1G 用于 os,2G 用于 ramdisk 14 = 17-1-2)。

以下是信息:

[sybase@myserver ASE-12_5]$ free -g
total used free shared buffers cached
Mem: 17 7 9 0 0 7
-/+ buffers/cache: 0 17
Swap: 3 0 3

有2G ramdisk设置。

[sybase@myserver ASE-12_5]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 12G 2.6G 8.8G 23% /
/dev/sda1 251M 19M 220M 8% /boot
none 8.7G 0 8.7G 0% /dev/shm ---what's this? is it related kernel.shmmax?
/dev/sdb1 30G 8.4G 20G 30% /home
tmpfs 2.1G 20M 2.1G 1% /db/tempdb -----this is ramdisk, what 's the difference between this and /dev/shm???

然后我修改 /ect/sysctl.conf 为:

[sybase@myserver ASE-12_5]$ cat /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 1
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
# kernel.shmmax = 10737418240
kernel.shmmax= 14738890752 ------modify this to 13.7G
kernel.shmmni = 4096
kernel.shmall = 2097152

然后运行:

echo "kernel.shmmax=14738890752" >> /etc/sysctl.conf

然后重新启动 CentOS。

然后我尝试将 sybase 最大内存设置为 7196724(2K),但无法启动 sybase 并出现错误:

00:00000:00000:2014/04/02 16:50:26.92 kernel os_create_region: shmget(0xf402f74d): No space left on device
00:00000:00000:2014/04/02 16:50:26.92 kernel kbcreate: couldn't create kernel region.
00:00000:00000:2014/04/02 16:50:26.92 kernel kistartup: could not create shared memory

它只允许我将最大内存设置为 40000009(2k)=7.6G

不知道为什么。所以在 CentOS 上设置共享内存,只更改 /etc/sysctl.conf 中的 kernel.shmmax 还不够吗?还是需要做更多?

另外,我不在输出的 2 行以下df -h

none 8.7G 0 8.7G 0% /dev/shm ---what's this? is it related kernel.shmmax
tmpfs 2.1G 20M 2.1G 1% /db/tempdb -----this is ramdisk

如何解决这个问题?

答案1

尝试分配大于允许的段shmmax会导致EINVAL (Invalid argument),但这并不是您所得到的。尝试分配大于已提交内存限制的段会导致 ,但这ENOSPC (No space left on device)正是您所得到的。

据我所知,该限制默认为物理 RAM 的一半加上总交换空间。您可以使用以下命令查看当前值grep CommitLimit /proc/meminfo

文件系统的大小tmpfs由 mount 选项控制size,如中所述man mount

/dev/shm调用时会使用文件系统。这与源自 Posix 和 SysV 的两个不同 APIshm_open无关。shmget

相关内容