Question

I'm hitting a strange memory limit with java. Below I execute "java -version" with different heap sizes. Once I set the heap to anything over 30M, java exits with error, complaining there is no free memory.

# /usr/java/default/bin/java -Xmx30m -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

# /usr/java/default/bin/java -Xmx40m -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:
# /root/hs_err_pid6689.log

# /usr/java/default/bin/java -Xmx50m -version
Error occurred during initialization of VM
java.lang.OutOfMemoryError: unable to create new native thread

# /usr/java/default/bin/java -Xmx60m -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:
# /root/hs_err_pid6703.log

According to "free" I have lots of free RAM:

# free -m
             total       used       free     shared    buffers     cached
Mem:          2909       1051       1858          0         17        618
-/+ buffers/cache:        415       2494
Swap:          511          0        511

But from what I see this clearly is a memory limit issue. When I kill some background processes, I can assign more heap to "java -version" command.

Does anyone know what's happening?

Was it helpful?

Solution

I'm answering my own question (just in case someone bumps into a similar issue).

On my system I had this in /etc/sysctl.conf

vm.overcommit_memory = 2

Setting it back to its default value (0) has resolved the issue:

vm.overcommit_memory = 0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top