加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – fork()失败,出现内存不足错误

发布时间:2020-12-13 19:13:04 所属栏目:Linux 来源:网络整理
导读:父进程在尝试分叉子进程时失败,并且errno = 12(内存不足).父进程在 Linux 3.0内核上运行 – SLES 11.在分叉子进程时,父进程已经占用了大约70%的RAM(180GB / 256GB).这个问题有解决方法吗? 该应用程序用C语言编写,用g 4.6.3编译. 解决方法 可能在您的系统中
父进程在尝试分叉子进程时失败,并且errno = 12(内存不足).父进程在 Linux 3.0内核上运行 – SLES 11.在分叉子进程时,父进程已经占用了大约70%的RAM(180GB / 256GB).这个问题有解决方法吗?

该应用程序用C语言编写,用g 4.6.3编译.

解决方法

可能在您的系统中阻止了提交虚拟内存.

如果被阻止,则虚拟内存不能大于物理RAM交换的大小.如果允许,则虚拟内存可以大于RAM交换.

当您的进程分叉时,您的进程(父进程和子进程)将具有2 * 180GB的虚拟内存(如果您没有交换则太多).

所以,通过这种方式允许过度提交:

echo 1 > /proc/sys/vm/overcommit_memory

如果子进程立即执行,它应该有所帮助,或者在父进程写入太多内存之前释放已分配的内存.所以,要小心,如果两个进程都继续使用所有内存,则内存杀手可能会起作用.

proc(5)的手册页说:

/proc/sys/vm/overcommit_memory

This file contains the kernel virtual
memory accounting mode. Values are: 0: heuristic overcommit (this is
the default) 1: always overcommit,never check 2: always check,never
overcommit

In mode 0,calls of mmap(2) with MAP_NORESERVE are not checked,and
the default check is very weak,leading to the risk of getting a
process “OOM-killed”. Under Linux 2.4 any nonzero value implies mode
1. In mode 2 (available since Linux 2.6),the total virtual address space on the system is limited to (SS + RAM*(r/100)),where SS is the
size of the swap space,and RAM is the size of the physical memory,
and r is the contents of the file /proc/sys/vm/overcommit_ratio.

更多信息:Overcommit Memory in SLES

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读