【发布时间】:2011-10-17 12:34:08
【问题描述】:
我有 64 位 REHL linux,
Linux ipms-sol1 2.6.32-71.el6.x86_64 #1 SMP x86_64 x86_64 x86_64 GNU/Linux
RAM 大小 = ~38GB
我在 /etc/sysctl.conf 中更改了默认共享内存限制,并将更改的文件加载到内存中作为 sysctl -p
kernel.shmmni=81474836
kernel.shmmax=32212254720
kernel.shmall=7864320
仅作为实验基础,我已将 shmmax 大小更改为 32GB,并尝试使用 shmget() 在代码中分配 10GB,如下所示,但它无法一次性获得 10GB 共享内存,但当我将共享空间需求减少到8GB 它成功了关于我可能哪里出错的任何线索?
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#define SHMSZ 10737418240
main()
{
char c;
int shmspaceid;
key_t key;
char *shm, *s;
struct shmid_ds shmid;
key = 5678;
fprintf(stderr,"Changed code\n");
if ((shmspaceid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
fprintf(stderr,"ERROR memory allocation failed\n");
return 1;
}
shmctl(shmspaceid, IPC_RMID, &shmid);
return 0;
}
问候 喜满洲
【问题讨论】:
-
您的 shmall 大小似乎假定
getconf PAGE_SIZE是 4096。您确认了吗? -
平。你有没有想过这个?我很好奇答案是什么,因为这是其他人可能会在我们自己的项目中遇到的问题。
标签: linux