Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 526
piontec Avatar asked Dec 04 '15 08:12

piontec


People also ask

How do I fix there is insufficient memory for the Java Runtime Environment to continue in Linux?

# There is insufficient memory for the Java Runtime Environment to continue. This is due to a known Java bug when process-limiting the virtual memory via ulimit (https://bugs.openjdk.java.net/browse/JDK-8071445). To resolve this, please set the max heap limits to a reasonable value.

Why my cached memory is so high Linux?

The reason Linux uses so much memory for disk cache is because the RAM is wasted if it isn't used. Keeping the cache means that if something needs the same data again, there's a good chance it will still be in the cache in memory.

What is cached memory Ubuntu?

The cache in Linux is called Page Cache. It is that certain amount of system memory that the kernel reserves for caching the file system disk accesses. This is to make overall performance faster.


1 Answers

you need to run something.

like

java -Xmx1024m -cp /path/to/jar/ com.project.Start
like image 169
mwe Avatar answered Oct 16 '22 05:10

mwe