今天在配置 DCA 服务器的时候,检验 java 版本的时候忽然遇到了一个 Cannot allocate memory 错误

[root@elcid-prod1 ~]# java -version

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00007ff55c5ea000, 4096, 0) failed; error='Cannot allocate memory' (errno=12)

#

# There is insufficient memory for the Java Runtime Environment to continue.

# Native memory allocation (mmap) failed to map 4096 bytes for committing reserved memory.

# An error report file with more information is saved as:

# /root/hs_err_pid5138.log

查找了一下相关文档,发现这个错误的含义其实就是像它自己说的,没法分配内存了。

The problem is inherent with the way Java allocates memory when executing processes. When Java executes a process, it must fork() then exec(). Forking creates a child process by duplicating the current process. By duplicating the current process, the new child process will request approximately the same amount of memory as its parent process, essentially doubling the memory required. However, this does not mean all the memory allocated will be used, as exec() is immediately called to execute the different code within the child process, freeing up this memory. As an example, when Stash tries to locate git, the Stash JVM process must be forked, approximately doubling the memory required by Stash.

解决方案呢有两个,第一个是用别的方法(例如 posix_spawn)替换掉 Java 的 fork/exec 方法从而申请到内存,第二个是开启系统的 Over-commit,跳过系统的可用内存检查直接分配。

第一个方法比较麻烦,需要使用一个 custom JNI binding 去更改 Java 底层调用,所以先不尝试。

第二个方法比较简单,但可能会导致依赖 C 语言 malloc() 的程序出错。

总之先试试第二个吧,毕竟就是改下系统变量的事儿。

临时更改: echo 1 > /proc/sys/vm/overcommit_memory

永久更改: 编辑 /etc/sysctl.conf,修改参数 vm.overcommit_memory = 1,重启服务器或者用户重新登录

参考:http://bryanmarty.com/2012/01/14/forking-jvm/

处理 Java 的“Cannot allocate memory”错误的更多相关文章

  1. redis报Cannot allocate memory错误

    昨天16:27开始将dp的日志使用ELK处理,当时redis使用内存的量不是很大,100M多点,结果今天早上到了一看xshell被关掉了,赶紧将各服务启动起来,elasticsearch启动没有问题, ...

  2. 处理 Java Tomcat 的“Cannot allocate memory”错误

    参考:https://www.cnblogs.com/rabbitpei/p/6738671.html 启动tomcat报错如下 临时生效 echo 1 > /proc/sys/vm/overc ...

  3. java.io.IOException: Cannot run program "bash": error=12, Cannot allocate memory

    java.io.IOException: Cannot run program , Cannot allocate memory 云服务器运行nutch报出的异常: 解决方案: http://daim ...

  4. Android 启动模拟器是出现“Failed to allocate memory: 8”错误提示的原因及解决办法

    某天,Android 启动模拟器是出现“Failed to allocate memory: 8”错误,模拟器无法启动,如下图: 原因:设置了不正确AVD显示屏模式,4.0版默认的模式为WVGA800 ...

  5. Tomcat7 JDK8 Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000540000000, 5368709120, 0) failed; error='Cannot allocate memory' (errno=12)

    [root@crm-web- bin]# shutdown.sh bash: shutdown.sh: command not found [root@crm-web- bin]# sh shutdo ...

  6. kafka启动报错Cannot allocate memory;There is insufficient memory for the Java Runtime Environment to continue.

    kafka启动过程报错,配置没有问题,这就懵了!! Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000 ...

  7. Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000fa980000, 59244544, 0) failed; error='Cannot allocate memory' (errno=12)

    启动项目报错 Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000fa980000, 592445 ...

  8. k8s SLUB: Unable to allocate memory on node -1 错误

    Try to Fix Two Linux Kernel Bugs While Testing TiDB Operator in K8sWed, May 1, 2019 Wenbo Zhang Auth ...

  9. -bash: fork: Cannot allocate memory

    今天遇到服务器无法SSH,VNC操作命令提示fork:cannot allocate memory free查看内存还有(注意,命令可能要多敲几次才会出来) 查看最大进程数 sysctl kernel ...

随机推荐

  1. 关于Azure Storage Blob Content-Disposition 使用学习

    概述 在常规的HTTP应答中,Content-Disposition 消息头指示回复的内容该以何种形式展示,是以内联的形式(即网页或者页面的一部分),还是以附件的形式下载并保存到本地.通俗的解释就是对 ...

  2. RabbitMQ快速入门python教程

    摘要:HelloWorld 简介 RabbitMQ:接受消息再传递消息,可以视为一个“邮局”.发送者和接受者通过队列来进行交互,队列的大小可以视为无限的,多个发送者可以发生给一个队列,多个接收者也可以 ...

  3. sql server 常用函数 及 方法

    返回受上一语句影响的行数: @@ROWCOUNT 语法@@ROWCOUNT 返回类型integer 注释任何不返回行的语句将这一变量设置为 0 ,如 IF 语句. 示例下面的示例执行 UPDATE 语 ...

  4. vue 父子组件属性传递

    父子组件属性传递 注意:0.谁被引用,谁就算子组件  1.属性命名最好完全小写,否则需要如下格式转换:myAttr == my-attr 2.引入的vue组件后必须通过 components 注册才能 ...

  5. Mac终端主题Peppermint

    Peppermint主题下载 下载地址:https://noahfrederick.com/log/lion-terminal-theme-peppermint 配置颜色: 1.写配置文件 vim ~ ...

  6. Python内置函数之chr()

    参数是一个整型对象: chr(integer) 返回整型对应的Unicode字符对象. 例子: >>> chr() '\x0c' >>> chr() 'ⲓ' > ...

  7. JSON串常用函数

    1.JSON.parse() parse 用于从一个字符串中解析出json 对象. 例如 var str='{"name":"cpf","age&qu ...

  8. OC-7-内存管理

    课程要点: 内存管理的必要性 MRC(手动管理) 自动释放池 ARC是怎么对内存进行管理的 内存管理的必要性 OC是一门面向对象的语言,在软件运行过程中会创造大量的对象,每创建一个对象系统就会给其分配 ...

  9. Introdution to Spring Mobile

    1. In Eclipse, create a new Maven Project using the spring-mvc-jpa-archetype. 2. Add the spring-mobi ...

  10. 浅谈push推送的一点感受

    在手机已成为生活必不可分的一部分,push服务伴随而来.ios的apns,android随着谷歌退出中国市场,各家在android的推送不断展开.有厂商的推送,如小米.华为.魅族.oppo等,还有中间 ...