April 17, 2013

Java Memory in open VZ machines

Hi,

I ran into troubles while trying to run a play application. The server is hosted in an openVZ container, which lead to problems during jvm memory initialization when I entered √† play start command :

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

After googling a while, this SO thread gave me the answer which I'll summarize here.

If you're in a hurry, here is the answer : edit the [JRE location]/lib/[Archi (ex : i386)]/jvm.cfg file and alter the first uncommented line.

Move from


-client IF_SERVER_CLASS -server
-server KNOWN
-hotspot ALIASED_TO -client
-classic WARN
-native ERROR
-green ERROR

to:
#-client IF_SERVER_CLASS -server
-client KNOWN
-server KNOWN
-hotspot ALIASED_TO -client
-classic WARN
-native ERROR
-green ERROR

From what I understand, with the initial configuration, when trying to launch a java process if the machine has 2G+ memory installed  it fires up the JVM in server mode.
Server mode means the JVM will ask for all the memory requested in contiguous memory blocks, and openVZ is not able to do that.

The -client KNOWN option will ask for memory on the fly, thus removing the problem meentionned above.

Hope this help.