linux共享内存分配失败原因分析
2010-03-22 21:01
225 查看
新版本的服务器使用基于UDP的多进程架构,进程之间的通过共享内存来互相通讯。
linux下共享内存的使用通过shmget函数来建立。
#include <sys/ipc.h>
#include <sys/shm.h>
int shmget(key_t key, size_t size, int shmflg);
由于要分配固定大小的共享内存来存放在线用户表,在内网测试的时候,分配10000个用户同时在线的内存没有问题,放到外网测试的时候,只能分配
到100个用户所需的共享内存,当分配大于100个用户所需内在的时候,就失败了,失败号为: EINVAL
查看shmget手册:
可能导致出现这个问题主要有两点
1.A shared memory segment is to be created and the value of size is less than the system-imposed minimum or greater than the system-imposed maximum。
2.No shared memory segment is to be created and a shared memory segment exists for key but the size of the segment associated with it is less than size and size is not 0.
1.分配的共享内在大小小于系统提供的最小共享内在或者大于系统提供的最大共享内存
2.申请共享内存的KEY已经存在(通过ipcs命令查看),并且现在申请的内存大于已经存在的共享内在大小。
通过查看linux内核参数,将第一点排除,由于把程序放到外网的时候,开始是按100个用户同时在线来分配内存来测试,再按照10000个用户来分配共享内存,当然失败了。
解决方案:
找出已经存在的共享内存的Key,使用ipcrm -m Key(Key为共享内存的ID)将已经存在的共享内存删除,再开到10000个用户,成功了。。。
linux下共享内存的使用通过shmget函数来建立。
#include <sys/ipc.h>
#include <sys/shm.h>
int shmget(key_t key, size_t size, int shmflg);
由于要分配固定大小的共享内存来存放在线用户表,在内网测试的时候,分配10000个用户同时在线的内存没有问题,放到外网测试的时候,只能分配
到100个用户所需的共享内存,当分配大于100个用户所需内在的时候,就失败了,失败号为: EINVAL
查看shmget手册:
可能导致出现这个问题主要有两点
1.A shared memory segment is to be created and the value of size is less than the system-imposed minimum or greater than the system-imposed maximum。
2.No shared memory segment is to be created and a shared memory segment exists for key but the size of the segment associated with it is less than size and size is not 0.
1.分配的共享内在大小小于系统提供的最小共享内在或者大于系统提供的最大共享内存
2.申请共享内存的KEY已经存在(通过ipcs命令查看),并且现在申请的内存大于已经存在的共享内在大小。
通过查看linux内核参数,将第一点排除,由于把程序放到外网的时候,开始是按100个用户同时在线来分配内存来测试,再按照10000个用户来分配共享内存,当然失败了。
解决方案:
找出已经存在的共享内存的Key,使用ipcrm -m Key(Key为共享内存的ID)将已经存在的共享内存删除,再开到10000个用户,成功了。。。
相关文章推荐
- 分析:大数据失败案例及背后原因!
- 占座网失败原因分析
- 企业信息化应用软件项目失败原因分析
- win32下的内存分配失败原因
- 注册数据源失败常见原因分析
- C#动态生成DropDownList执行失败原因分析
- CSS加载失败原因的总结与分析
- 邮箱css加载失败怎么办 网站css加载异常原因分析
- 系统启动失败的原因分析及解决办法
- fopen函数失败原因分析以及分析原因的方法
- 在Yii2中使用Pjax导致Yii2内联脚本载入失败的原因分析
- 项目失败原因分析
- 软件新产品开发失败原因分析
- tomcat启动失败原因分析
- Mysql安装注意事项、安装失败的五个原因分析
- malloc 内存分配失败很可能的一种原因
- 中国SaaS模式失败原因分析
- HTTP下载文件校验失败原因分析与解决
- ROS HTB限速失败原因分析和需注意事项
- ORA-04030: 在尝试分配...字节(...)时进程内存不足的原因分析解决方法