Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does setting the -Xmx too high sometimes cause the JVM to fail, even if there's available RAM?

Basically we've noticed that on some computers setting the JVM option -Xmx (max heap size) sometimes cause the JVM to fail to initialize, even if there's more than adequate RAM on the system.

So for example, on a 4gb machine, we have -Xmx1024m which fails but -Xmx800m works. I could understand on a 1gb machine, even a 2gb machine, but on a 4gb machine, especially considering that Windows, Linux, etc. can swap the RAM out, why does this fail?

I've seen a lot of threads and questions saying to reduce your max heap size, but no one can explain why it fails which is what I'm really looking for.

As well, how do you say consume as much memory as you want up to a certain size then?

like image 423
Stephane Grenier Avatar asked Jan 05 '12 23:01

Stephane Grenier


People also ask

Why JVM heap utilization is too high?

This is because the JVM steadily increases heap usage percentage until the garbage collection process frees up memory again. High heap usage occurs when the garbage collection process cannot keep up. An indicator of high heap usage is when the garbage collection is incapable of reducing the heap usage to around 30%.

How much RAM does JVM need?

This resource memory used by the JVM is often called overhead. The recommended minimum starting memory point for 64-bit Maximo 7.5 JVMs systems is 3584 MB. Therefore we recommended that physical memory availability for each JVM be 4096 MB;0.5 GB is for JVM allocation and 512 MB is for overhead.

How do I allow JVM to use more memory?

Under the Java tab, select JVM Options. Edit the -Xmx256m option. This option sets the JVM heap size. Set the -Xmx256m option to a higher value, such as Xmx1024m.

Why is my JVM using more memory than XMX?

But in 99% of the cases it is completely normal behaviour by the JVM. What you have specified via the -Xmx switches is limiting the memory consumed by your application heap. But besides the memory consumed by your application, the JVM itself also needs some elbow room.


2 Answers

It's possible that this is due to virtual address space fragmentation. It may not be possible to reserve a contiguous 1024MB address range for the maximum potential size of the heap, depending on the load addresses of DLLs, threads' stack locations, immovable native memory allocations, kernel reserved addresses and so forth, especially in a 32-bit process.

like image 58
Jeffrey Hantin Avatar answered Sep 30 '22 14:09

Jeffrey Hantin


I came across this issue a while ago with Windows XP. On most XP machines I could allocate 1400MB, while others were only 1200MB. The consensus was fragmentation as Jeffrey Hantin says in the other answer.

like image 42
Steve Kuo Avatar answered Sep 30 '22 13:09

Steve Kuo