【问题标题】:How much memory Java needs to start?Java 需要多少内存才能启动?
【发布时间】:2013-07-11 09:52:01
【问题描述】:

这是我的脚本(我只是在尝试解决一个更大的问题):

#!/bin/bash
JAVA_OPTS="-Xms64m -Xmx64m"
for i in 1 2 3 4 5 6 7 8 9 10
do
  /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -version &
done

简而言之,我试图同时启动 10 个 java 进程。服务器有 512Mb 的 RAM 和 4Gb 的交换空间。对于每个 64Mb 的十个进程来说,这应该绰绰有余了。但是,这是我在其中两个的输出中看到的:

Error occurred during initialization of VM
Could not reserve enough space for the card marking array
Error occurred during initialization of VM
Could not reserve enough space for code cache

为什么会这样?如何解决?

崩溃的进程以此开始创建文件:

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 160088 bytes for HashtableBucket in /build/buildd/openjdk-7-7u21-2.3.9/build/openjdk/hotspot/src/share/vm/utilities/hashtable.inline.hpp
# 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=

以下哪项是我的情况?

【问题讨论】:

  • 我不确定,但我认为当您启动 JVM 时,它会占用启动时 args 中提供的所有内存。因此,您需要 640M...
  • 你的意思是4Gb的swap不被视为JVM的内存?
  • -Xmx 定义了最大堆大小——整个 Java 进程使用的内存比这更多。
  • 仍然应该远远小于 4Gb 可用,你不觉得吗?

标签: java ubuntu memory-management


【解决方案1】:

Java 在启动时保留一些必须是物理内存(而不是交换)的内存,用于 VM 的内部管理。如果您没有足够的物理内存,JVM 将无法启动。

【讨论】:

  • 是可配置参数吗?你能给出一些解释这个的链接吗?
  • @yegor256 不,没有参数,我没有找到任何参考。但是有一些结构需要在内存中,但正如我所说,我没有找到参考。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多