JVM内存不足崩溃 [英] JVM insufficient memory crash

查看:2000
本文介绍了JVM内存不足崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用G1垃圾收集器遇到Java VM崩溃.我们获得具有以下签名的hs_err_pid.log文件:

I have been experiencing Java VM crashes using the G1 garbage collector. We get hs_err_pid.log files generated with the following signatures:

#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 32744 bytes for ChunkPool::allocate
# Possible reasons:
#   The system is out of physical RAM or swap space
#   In 32 bit mode, the process size limit was hit
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Use 64 bit Java on a 64 bit OS
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.

我们当前正在监视内存的可用性,并通过使用Runtime.maxMemory,freeMemory和totalMemory来避免出现内存不足错误.这个想法是我们可以暂停操作并警告用户他们需要分配更多的内存.但是,即使Runtime.freeMemory报告大量可用内存,我们也看到上述JVM崩溃.

We are currently monitoring the memory availability and preempting any out of memory errors by using Runtime.maxMemory, freeMemory and totalMemory. The idea is that we can pause operations and warn the user that they need to allocate more memory. But we are seeing the above JVM crashes even when the Runtime.freeMemory is reporting lots of free memory.

作为Java桌面应用程序,有什么方法可以避免这种情况发生,并使自己与系统上的内存负载隔离. 例如,是否可以提供我们提供的启动选项的任何组合,即将-Xms和-Xmx设置为相同的值对我们有帮助吗?目前,我们仅设置-Xmx.

Is there any way as a java desktop application we can avoid this happening and insulate ourselves from memory load on the system. For example is there any combination of start up options that we can provide i.e. would setting -Xms and -Xmx to the same value help us here? At the moment we only set -Xmx.

我渴望避免Jvm的用户体验糟糕而无声地崩溃.理想情况下,我们希望能够检测到JVM何时即将耗尽内存并采取适当的措施.

I am keen to avoid the poor user experience of the Jvm silently crashing. Ideally we would like to be able to detect when the JVM is getting close to getting out of memory and take appropriate action.

在这里,您可以从hs_err_pid.log中获取更多有关崩溃示例的信息.这是使用-Xmx4g,总物理内存为12gb,可用物理内存为1.79gb.

Here is a bit more information taken from the hs_err_pid.log for one example crash. This was using -Xmx4g, total physical memory 12gb, free physical memory 1.79gb.

Native memory allocation (malloc) failed to allocate 32744 bytes for ChunkPool::allocate

Heap:
 garbage-first heap   total 4194304K, used 3140260K [0x00000006c0000000, 0x00000006c0108000, 0x00000007c0000000)
  region size 1024K, 1526 young (1562624K), 26 survivors (26624K)
 Metaspace       used 78244K, capacity 95308K, committed 96328K, reserved 1122304K
  class space    used 11319K, capacity 22311K, committed 23112K, reserved 1048576K

Memory: 4k page, physical 12269248k(1790928k free), swap 37973052k(362096k free)

推荐答案

将-Xms和-Xmx设置为相同的值会在这里为我们提供帮助

would setting -Xms and -Xmx to the same value help us here

可能不是.请注意,JVM堆空间不是问题,如果您允许的堆空间超出了操作系统的能力,那么您将遇到问题.

Probably not. Your JVM heap space is not the issue, with the caveat that if you've allowed more heap space than the OS can provide then you're going to hit problems.

错误消息的关键部分是:

The key part of the error message is:

本机内存分配(malloc)无法为ChunkPool :: allocate分配32744字节

Native memory allocation (malloc) failed to allocate 32744 bytes for ChunkPool::allocate

当操作系统无法将内存分配给JVM进程时,

malloc()将失败.检查事项:

malloc() will fail when memory cannot be allocated to the JVM process by the OS. Things to check:

  1. 在应用运行时监视并记录计算机的总体内存使用情况,包括交换.

  1. Monitor and record the overall machine memory usage, including swap, while your app is running.

使用ulimit -m检查用户的进程大小是否存在管理员施加的限制.共享服务器通常具有限制,以阻止一个用户占用所有资源.

Check if there are admin-imposed limits on your user's process size using ulimit -m. Shared servers often have limits imposed to stop one user hogging all the resources.

如果在容器中运行,则以上两项均适用,但您还需要检查由容器管理技术(例如Kubernetes)施加的资源限制.

If running in a container then both the above apply but you'll also need to check resource limits imposed by the container management technology (e.g. Kubernetes).

这篇关于JVM内存不足崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆