Java“无法为对象堆预留足够的空间”,但大量的RAM是免费的

我在运行服务器上的Java应用程序时遇到问题。

root@dobby [/opt]# jdk1.7.0_09/jre/bin/java -version Error occurred during initialization of VM Could not reserve enough space for object heap Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 

…但免费的RAM大约4GB(其中3GB被Linuxcaching使用)。 如果我将Xmx添加到命令中:

 root@dobby [/opt]# jdk1.7.0_09/jre/bin/java -Xmx100m -version # # There is insufficient memory for the Java Runtime Environment to continue. # pthread_getattr_np # An error report file with more information is saved as: # /opt/hs_err_pid32241.log 

这是怎么回事?

细节:

  • 64位系统
  • Linux 2.6.32
  • CentOS 6.2
  • Oracle JDK 1.7.0更新9(在早期版本中也出现问题)

Java错误报告: http : //pastebin.com/uaxdSyh3

的ulimit:

 root@dobby [/home/bart]# ulimit -a -S core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 62763 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) 1048576 open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) 1048576 file locks (-x) unlimited root@dobby [/home/bart]# ulimit -a H core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 62763 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) 1048576 open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) 1048576 file locks (-x) unlimited 

简单的答案将是你的limits.conf的一个问题。 你可以发布的输出

 ulimit -a -S ulimit -a -H 

好吧,我继续检查这个。 问题在于“-v”设置,虚拟内存设置,而不是“-m”设置。 这是在Fedora 17机器上,但这应该很重要:

 $ ulimit -S -v unlimited $ java -version java version "1.7.0_09-icedtea" OpenJDK Runtime Environment (fedora-2.3.3.fc17.1-x86_64) OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode) $ ulimit -v 1048576 $ java -version Error occurred during initialization of VM Could not reserve enough space for object heap Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 

去修理! ;)