Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java does not properly reserve huge initial heap size

I'm working on a single machine with 512GB RAM (addressed by several AMD Opteron 6212 CPUs). There is currently about 300GB RAM free. Running a large java computation by running

java path/to/myApp -Xms280g -Xmx280g > output.txt

should make Java reserve 280GB immediately, and error if that fails. Strangely, no error occurs but top only shows a memory usage of 30.4GB but it doesn't crash. How can this happen? Isn't java supposed to crash if the initial heap size cannot be allocated?

And effectively, I get OutOfMemory/Java heap space/GC overhead limit errors once the 30.4GB are full, well before the 280GB is ever reached. Running with 250GB or 300GB yields a similar 30.3GB ~ 30.4GB limit. I'm running OpenJDK 64-bit server VM with OpenJDK Runtime Environment (IcedTea6) on Gentoo Linux, and there is plenty of free RAM (over 300GB).

like image 993
user1111929 Avatar asked May 25 '14 21:05

user1111929


People also ask

How do you fix initial heap size set to a larger value than the maximum heap size?

To get rid of this error, the value of Xmx(maximum heap size) should always be greater than or equal to Xms(minimum heap size). Run the HelloWorld program with the value of Xms(minimum heap size) set to 1 gigabyte and Xmx(maximum heap size) set to 2 gigabytes.

How do I fix invalid max heap size?

64 bit JVM installed on Solaris machines runs with a 32-bit model if you don't specify either -d32 or -d64, which won't accept a Maximum heap size of 4GB, hence "invalid heap size". You can resolve this issue by running Solaris JVM with option -d64.

How do you resolve Error occurred during initialization of VM Could not reserve enough space for object heap?

To fix the error "Could not reserve enough space for object heap", add the options "-Xmx<size>m" to set the maximum size for the object heap memory allocation. This must be set large enough to accommodate loading your application into memory, but smaller than your requested total memory allocation by 2GB.


Video Answer


2 Answers

The order of the parameters is incorrect. You are passing -Xms280g -Xmx280g as arguments to your own program and not to the JVM. The correct is:

java -Xms280g -Xmx280g path/to/myApp

like image 133
Diego Giagio Avatar answered Sep 17 '22 04:09

Diego Giagio


If you want the memory specified in -Xms to be grabbed during the initialization of your application then use

java -XX:+AlwaysPreTouch -Xms2G -Xmx2G ......

AlwaysPreTouch will demand every memory page during the initialization of the JVM rather than just keeping what is not needed as “virtual”. However, note that this will have some latency in the starting of the JVM.

Use the aforementioned switch and then check with top. You will get full 2G (in fact a little more) for your JVM.

like image 28
Muhammed Shakir Misarwala Avatar answered Sep 21 '22 04:09

Muhammed Shakir Misarwala