简体   繁体   English

找不到足够的连续内存会导致OOM吗?

[英]can a OOM be caused by not finding enough contiguous memory?

I start some java code with -Xmx1024m, and at some point I get an hprof due to OOM. 我从-Xmx1024m开始一些Java代码,由于OOM,有时我会得到一个hprof。 The hprof shows just 320mb, and give me a stack trace: hprof仅显示320mb,并给我一个堆栈跟踪:

 at java.util.Arrays.copyOfRange([CII)[C (Arrays.java:3209)
  at java.lang.String.<init>([CII)V (String.java:215)
  at java.lang.StringBuilder.toString()Ljava/lang/String; (StringBuilder.java:430)
  ...

This comes from a large string I am copying. 这来自我要复制的大字符串。

I remember reading somewhere (cannot find where) what happened is these cases is: 我记得读过某处(找不到位置)这些情况是:

  • process still has not consumed 1gb of memory, is way below 进程仍未消耗1gb的内存,方法如下
  • even if heap still below 1gb, it needs some amount of memory, and for copyOfRange() it has to be continuous memory, so even if it is not over the limit yet, it cannot find a large enough piece of memory on the host, it fails with an OOM. 即使堆仍低于1gb,它也需要一定数量的内存,而对于copyOfRange()它必须是连续的内存,因此,即使尚未超过限制,它也无法在主机上找到足够大的内存,它因OOM而失败。

I have tried to look for doc on this ( copyOfRange() needs a block of continuous memory), but could not find any. 我试图在此上寻找doc( copyOfRange()需要一块连续的内存),但是找不到任何文件。

The other possible culprit would be not enough permgen memory. 另一个可能的罪魁祸首是permgen内存不足。

Can someone confirm or refute the continuous memory hypothesis? 有人可以确认或驳斥连续记忆假设吗? Any pointer to some doc would help too. 任何指向某些文档的指针也将有所帮助。

If you are using the concurrent mark sweep collector you can get fragmentation. 如果使用并发标记清除收集器,则可能会出现碎片。 however for new objects, provided there is a enough young generation space you don't need to worry about fragmentation as the free Eden space is always continuous. 但是对于新物体,只要有足够的年轻一代空间,您就不必担心碎片化,因为自由的伊甸园空间始终是连续的。

In many applications, only a small portion of the heap is given to the young generation so if you have a fragmented tenured space and you create a relatively small object (as small as 5% of the maximum memory size) you can get an OutOfMemoryError. 在许多应用程序中,只有一小部分堆被分配给年轻一代,因此,如果您拥有零散的使用期限空间,并且创建了一个相对较小的对象(最小为最大内存大小的5%),则可能会收到OutOfMemoryError。

Given you will have very poor performance if you run close to the maximum memory, I would suggest you either make you application use less memory or increase the maximum. 如果在接近最大内存的情况下性能会很差,我建议您要么让应用程序使用更少的内存,要么增加最大内存。 This increases the your generation size as well. 这也增加了您的世代大小。 Alternatively you could set -XX:NewSize=512m 或者,您可以设置-XX:NewSize=512m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM