piontec
piontec

Reputation: 143

Java on ubuntu is out of memory, but plenty of cached memory present

I got an ubuntu 14.04 system with 4GB RAM,x86_64 3.13.0-48-generic kernel and openjdk-7.

My memory is used as below:

# free -h
             total       used       free     shared    buffers     cached
Mem:          3.7G       3.6G       127M       988M        44M       3.3G
-/+ buffers/cache:       232M       3.4G
Swap:           0B         0B         0B

So, there is plenty of memory used as a disk cache, which should be flushed and freed (AFAIK) when any app needs it.

So, i try to run java:

# java -Xms32m -Xmx512m -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.

Running just java -version returns the same result. Why can't java run when there's 3GB of cached memory? I have PostreSQL running on the same machine, but it's shared_buffers is set to 940MB.

edit:

I force-flushed the disk cache - still the same result:

# free -h
             total       used       free     shared    buffers     cached
Mem:          3.7G       1.9G       1.8G       988M        35M       1.7G
-/+ buffers/cache:       196M       3.5G
Swap:           0B         0B         0B
# java -Xms32m -Xmx512m -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

edit2:

Here is ulimit -a:

# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 30034
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
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) 32000
cpu time               (seconds, -t) unlimited
max user processes              (-u) 30034
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

edit3:

I completely don't get it: I tried to add 4GB swap and the result is that it works, although the swap is not used:

# free -h
             total       used       free     shared    buffers     cached
Mem:          3.7G       3.5G       196M       988M        44M       3.2G
-/+ buffers/cache:       239M       3.4G
Swap:         4.0G         0B       4.0G
# java -version
java version "1.6.0_36"
OpenJDK Runtime Environment (IcedTea6 1.13.8) (6b36-1.13.8-0ubuntu1~14.04)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

Upvotes: 6

Views: 2146

Answers (2)

Funzi
Funzi

Reputation: 36

Java provides the right answer: You don't have enough free memory on that machine for this heap size.

Did you try a top followed by Shift+M on this machine? There is a lot of buffered stuff on your machine, that's true.

Any reason why you don't add a swap partition?

Also, you can check here: http://javahowto.blogspot.de/2006/06/6-common-errors-in-setting-java-heap.html

Upvotes: 1

mwe
mwe

Reputation: 3263

you need to run something.

like

java -Xmx1024m -cp /path/to/jar/ com.project.Start

Upvotes: 2

Related Questions