Could not reserve enough space for object heap解决办法

Posted caiwuzi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Could not reserve enough space for object heap解决办法相关的知识,希望对你有一定的参考价值。

原文:http://www.cnblogs.com/liuchao102/p/4588590.html

 

1.在终端输入Java命令报错

[root@localhost local]# java
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

2.是系统参数(overcommit_memory和overcommit_ratio)配置的问题

3.查看系统内存分配状态

[root@localhost local]# grep -i commit /proc/meminfo
CommitLimit:    15550904 kB
Committed_AS:   15098404 kB

  看到CommitLimit和Committed_As参数。

  CommitLimit是一个内存分配上限,CommitLimit = 物理内存 * overcommit_ratio(默认50,即50%) + swap大小
  Committed_As是已经分配的内存大小。

4.内核参数overcommit_memory

[root@localhost local]# cat /etc/sysctl.conf | grep overcommit_memory
vm.overcommit_memory=2

  它是 内存分配策略

  可选值:0、1、2。
  0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
  1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
  2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

5. 解决办法
  将vm.overcommit_memory 设为1即可
  有三种方式修改内核参数,但要有root权限:

1)编辑/etc/sysctl.conf ,改vm.overcommit_memory=1,然后sysctl -p 使配置文件生效

2)sysctl vm.overcommit_memory=1

3)echo 1 > /proc/sys/vm/overcommit_memory

参考:http://blog.csdn.net/whycold/article/details/21388455

以上是关于Could not reserve enough space for object heap解决办法的主要内容,如果未能解决你的问题,请参考以下文章

Could not reserve enough space for 1572864KB object heap

启动tomcat报错 Could not reserve enough space for object heap的解决办法

android studio报错“Could not reserve enough space for 1572864KB object heap”

全网首发:MAC对应用签名,运行JAVA时报错“Could not reserve enough space for code cache”的JDK流程

Error occurred during initialization of VM Could not reserve enough space for 2097152KB object heap(

gatling压力测试工具启动gatling.bat命令行窗口报Error occurred during initialization of VM Could not reserve enough