我有一台64位的REHL Linux机器,
Linux ipms-sol1 2.6.32-71.el6.x86_64 #1 SMP x86_64 x86_64 x86_64 GNU/Linux
内存大小为约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;
}
敬礼, Himanshu
getconf PAGE_SIZE
为4096。你确认过了吗? - antiduh