在启动公司内嵌的tomcat容器时出现报错, 如下:


  1. # There is insufficient memory for the Java Runtime Environment to continue.
  2. # Native memory allocation (malloc) failed to allocate 160088 bytes for AllocateHeap
  3. # An error report file with more information is saved as:
  4. # /users/xxx/hs_err_pidxxxx.log

然后查看/users/xxx/hs_err_pidxxxx.log内容:


  1. #
  2. # There is insufficient memory for the Java Runtime Environment to continue.
  3. # Native memory allocation (mmap) failed to map 357564416 bytes for committing reserved memory.
  4. # Possible reasons:
  5. # The system is out of physical RAM or swap space
  6. # The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap
  7. # Possible solutions:
  8. # Reduce memory load on the system
  9. # Increase physical memory or swap space
  10. # Check if swap backing store is full
  11. # Decrease Java heap size (-Xmx/-Xms)
  12. # Decrease number of Java threads
  13. # Decrease Java thread stack sizes (-Xss)
  14. # Set larger code cache with -XX:ReservedCodeCacheSize=
  15. # JVM is running with Unscaled Compressed Oops mode in which the Java heap is
  16. # placed in the first 4GB address space. The Java Heap base address is the
  17. # maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress
  18. # to set the Java Heap base and to place the Java Heap above 4GB virtual address.
  19. # This output file may be truncated or incomplete.
  20. #
  21. # Out of Memory Error (os_linux.cpp:2749), pid=4252, tid=0x00007f3f38bb5700
  22. #
  23. # JRE version: (8.0_201-b09) (build )
  24. # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode linux-amd64 compressed oops)
  25. # Core dump written. Default location: /users/ems/core or core.4252 (max size 521000 kB). To ensure a full core dump, try "ulimit -c unlimited" before starting Java again
  26. #
  27. ...

翻译过来就是本地内存分配失败, 可能的原因有两种

  1. 系统物理内存或虚拟内存不足
  2. 程序在压缩指针模式下运行, Java堆会阻塞本地堆的增长

然后使用free -m命令查询, 发现内存足够:


  1. total used free shared buffers cached
  2. Mem: 7983 5415 2568 0 170 1460
  3. -/+ buffers/cache: 3784 4199
  4. Swap: 15257 71 15186

那么尝试按第二个问题进行解决, 可能的方案有两种:

  1. 禁止使用压缩指针模式

    1. 方法: 在catalina.sh中JAVA_OPTS的值后面添加-XX:-UseCompressedOops, 再重启tomcat
  2. 将Java堆的起始地址设置成使Java堆大小+起始地址大于4G,
    1. 原因: 请参考 https://blogs.oracle.com/poonam/running-on-a-64bit-platform-and-still-running-out-of-memory,
    2. 方法: 在这里我将起始地址简单直接的设为4G即4294967296

在尝试过这两种方法后发现依然报同样的错误
这时我在想会不会是堆内存过大, 导致系统无法分配内存, 于是进行尝试: 把堆内存减少一半, 看看效果.

  1. 方法: 在在catalina.sh中JAVA_OPTS的值中把原来的-Xms1024m -Xmx2048m改为-Xms512m -Xmx1024m, 再重启tomcat

结果JVM启动成功, 问题解决.

后续思考: 为什么在可用内存充足的情况下系统无法分配给JVM更多内存? 一直没有想到完美的解释, 如果有明白的兄弟可以指教一下.

尝试对后续思考进行解答: 原因应该还是内存不足, 可能操作系统会预留一些内存, 而我的机器上默认的启动参数是-Xms1024m -Xmx2048m, 可能已经超过了系统允许分配的最高值, 因此无法分配内存. 当我使用java -Xms10m -Xmx20m可以启动成功, java -Xms500m -Xmx2000m会失败, 因此, 应该还是内存不足的问题

对后续思考的最终解答及该问题的完美解决方案:

这个问题是由于/proc/meminfo下的vm.overcommit_memory被设置成不允许overcommit造成的

首先了解一下overcommit的意思: 用户进程申请的是虚拟地址, 而这个虚拟地址是不允许任意申请的, 因为虚拟内存需要物理内存做支撑, 如果分配太多虚拟内存, 会对性能参数影响. overcommit就是对虚拟内存的过量分配

vm.overcommit_memory的用处: 控制过量分配的策略. 这个参数一共有3个可选值:

  1. 0: Heuristic overcommit handling. 就是由操作系统自己决定过量分配策略
  2. 1: Always overcommit. 一直允许过量分配
  3. 2: Don't overcommit. 不允许过量分配

在这个案例里面, 使用sysctl vm.overcommit_memory来查看, 发现vm.overcommit_memory = 2, 即采用的是不允许过量分配的设置. 而在错误日志中也证明了这一点:


  1. CommitLimit: 15951192 kB
  2. Committed_AS: 15837036 kB

Committed_AS: OS会预测启动这个程序时, 所有的进程可能会用到多少的内存, 如果超过了CommitLimit, 就会报错
解决方案是sudo sysctl vm.overcommit_memory=0, 即vm.overcommit_memory = 0, 允许系统自己决定过量分配策略

原文地址:https://www.jianshu.com/p/3f8692eb3660

转载于:https://www.cnblogs.com/jpfss/p/11052535.html

文章知识点与官方知识档案匹配,可进一步学习相关知识

[转帖]一次操作系统报错OutOfMemory Error的处理记录的更多相关文章

  1. 一次操作系统报错OutOfMemory Error的处理记录

    在启动公司内嵌的tomcat容器时出现报错, 如下: # There is insufficient memory for the Java Runtime Environment to contin ...

  2. thinkphp6安装报错,composer install tp6 报错 Parse error: syntax error

    composer install thinkphp6 报错 Parse error: syntax error, unexpected ':', expecting '{' in vendor\top ...

  3. JS function document.onclick(){}报错Syntax error on token "function", delete this token

    JS function document.onclick(){}报错Syntax error on token "function", delete this token func ...

  4. 一个参数大小写引发的uploadify报错 "Syntax error, unrecognized expression: #"

     上传控件uploadify 报错"Syntax error, unrecognized expression: #" 版本为 uploadify3.2  报错原因:参数ID[hi ...

  5. yum报错:Error: xz compression not available

    测试服务器(centos6.5)经过一段时间的折腾,有一天在上面进行yum操作时突然出现下面的报错: Error: xz compression not available 最后经过一番排查,发现原因 ...

  6. yum报错: Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

    在Centos 5.x或6.x上安装RHEL EPEL Repo repository,资源库,源的意思.RHEL EPEL(Extra Packages for Enterprise Linux)  ...

  7. redis报错Windows error 0x70(a large memory)

    redis报错Windows error 0x70 redis 嫌弃你内存不够了,就给你不开第二个实例. The Windows version of Redis allocates a large ...

  8. ASSERT报错:error C2664: “AfxAssertFailedLine”: 不能将参数 1 从“TCHAR []”转换为“LPCSTR”

    转载请注明来源:崨雁嫀筝 http://www.cnblogs.com/xuesongshu 这个错误是我在把tinyxml修改为宽字符(Unicode)版本时候遇到的问题,我首先按关键字把所有有ch ...

  9. 命令passwd报错因inode节点处理记录

    命令passwd报错因inode节点处理记录故障现象:1.修改密码时报错 passwd: Authentication token manipulation error2.添加用户报错:unable ...

  10. 启动安卓模拟器报错 emulator: ERROR: x86_64 emulation currently requires hardware acceleration! CPU acceleration status:HAXM must be updated(version 1.1.1<6.0.1) 解决办法

    启动安卓模拟器报错 emulator: ERROR: x86_64 emulation currently requires hardware acceleration!  CPU accelerat ...

随机推荐

  1. JavaScript异步编程1——Promise的初步使用

    目录 1. 概述 2. 详论 3. 参考 1. 概述 Promise对象是ES6提出的的异步编程的规范.说到异步编程,就不得不说说同步和异步这两个概念. 从字面意思理解同步编程的话,似乎指的是两个任务 ...

  2. 助力信创国产化,Solon v2.2.9 发布

    Solon 是一个高效的 Java 应用开发框架:更快.更小.更简单.它不是 Spring.没有使用 Servlet.JavaEE 接口,是一个有自己接口标准的开放生态.可以为应用软件国产化提供支持, ...

  3. QA: Solon 怎么输出下载文件流?

    Solon 的Mvc可以直接返回 DownloadedFile 或者 File 对象 @Mapping("/demo/down") @Controller public class ...

  4. 人人都会Kubernetes(一):告别手写K8s yaml,运维效率提升500%

    1. Kubernetes的普及和重要性 随着云计算的迅速发展,容器化技术已成为构建和运行分布式应用程序的关键.而Kubernetes作为容器编排领域的佼佼者,已经成为了云原生应用的标准.它不仅简化了 ...

  5. Axure RP 9 下载、破解激活教程、最新激活码,亲测可用

    本教程适用于 Axure RP 9 Enterprise/Pro/Team 的激活.破解,最新激活码,适用于 windows, mac系统,仅用于学习 简介 Axure RP 9.0 破解版是一款功能 ...

  6. umount.nfs4: /home/videorec/sharedir: device is busy

    用umount取消挂载时报错设备繁忙:device is busy.原因是还有进程在打开目录下的文件,可以先杀死进程,再卸载,或者强制卸载 umount 使用umount强制卸载,参数如下: -l  ...

  7. 容器卡在terminate状态无法删除

    1. pod卡在terminate状态无法删除.一般是lxcfx 卡住 或者 logcounter组件进程读容器数据盘分区导致的 2.  验证一下我们的猜测 cat /sys/fs/fuse/conn ...

  8. 【HZERO】数据导入

    #数据导入 ##文档整理 通用导入客户端 https://open.hand-china.com/hzero-docs/v1.3/zh/docs/service/import/import/ 开放平台 ...

  9. 遇到 Request header is too large,你是如何解决的?

    看到群里有小伙伴问,这个异常要怎么解决: java.lang.IllegalArgumentException: Request header is too large 异常原因 根据Exceptio ...

  10. 2、springboot创建多模块工程

    系列导航 springBoot项目打jar包 1.springboot工程新建(单模块) 2.springboot创建多模块工程 3.springboot连接数据库 4.SpringBoot连接数据库 ...