Kenshin
Kenshin

Reputation: 1030

Java OutofMemory Error in Ubuntu Even if enough memory available

I have a VPS with 20GB RAM, Ubuntu OS. I am trying to allocate 10GB RAM as the maximum heap to java using JAVA_TOOL_OPTIONS but I couldn't. Please see the attached screenshot. It shows available memory as 17GB. Its working when I try to set to 7GB. But heap error occurs only when it is > 7GB. I have already installed glassfish and allocated 3Gb to its cluster. Its working fine. But why I am not able to allocate greater than 7GB when I have 17GB RAM free.

enter image description here

enter image description here

TOP enter image description here

ULIMITS

enter image description here

Java -version enter image description here

OverCommit memory

enter image description here

My Hardware is Virtual Hosted. Below is the configuration

Upvotes: 3

Views: 1866

Answers (3)

Kenshin
Kenshin

Reputation: 1030

The reason why I wasn't able to allocate more than 5G is because of the fact that privvmpages is set to 5G.

We can get that information in linux by this command "cat /proc/user_beancounters"

Also, in VPS, hosting provider will not allow us to customize this value. We have to either go for large virtual or dedicated server to increase this limit.

This was the root cause. However, Stephen and Robin's explanations on the Virtual Memory and RES memory were spot on. Thanks Guys

Upvotes: 0

Stephen C
Stephen C

Reputation: 718796

I think you may be out of swap space. When I add up the memory in the "virt" column, it comes to 40+ Gb.


Why it's taking that much swap space ? What needs to be done in order to fix this ?

Well, according to top you are running:

  • Glassfish - 9.1G
  • MySQL daemon - 5.4G
  • Hudson - 8.9G
  • Nexus - 6G
  • Glassfish - 6.9G (2nd instance)

and sundry other stuff. The "virt" is their total virtual memory footprint, and some of that will be code segments which may be shared.

They mostly seem to have a small "res" (resident memory) at the moment which is why there is so much free RAM. However, if a few of them sprang into life at the same time the system the demand for RAM would skyrocket, and the system might start to thrash.

My recommendation would be to move the Hudson and Nexus services to a separate VM. Or if that is not possible, increase the size of your swap space ... and hope that you don't thrash.


This is true. But is this a normal behaviour?

Yes.

is this how memory allocation works?

Yes. This is indeed how virtual memory works.

I am confused with Resident memory, virtual memory and physical memory now.

Rather than explain it in detail, I suggest you start by reading the Wikipedia page on virtual memory.

Upvotes: 1

Robin Coe
Robin Coe

Reputation: 750

If I had to guess, you don't have a contiguous block of RAM that's 7GB, which does seem weird, but without knowing more about your VM's allocation it's hard to say.

Here's what Oracle has to say on the matter (http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#gc_oom):

The VM prints "OutOfMemoryError" and exits. Increasing max heap size doesn't help. What's going on?

The Java HotSpot VM cannot expand its heap size if memory is completely allocated and no swap space is available. This can occur, for example, when several applications are running simultaneously. When this happens, the VM will exit after printing a message similar to the following.

Exception java.lang.OutOfMemoryError: requested bytes

-Xmx-Xms-Xmx

For more information, see the evaluation section of bug 4697804.

Upvotes: 2

Related Questions