3

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

  • Architecture: x86_64
  • CPU op-mode(s): 32-bit, 64-bit
  • Byte Order: Little Endian
  • CPU(s): 16
  • Vendor ID: GenuineIntel
  • CPU family: 6
  • Model: 26
  • Stepping: 5
  • CPU MHz: 2266.802
  • BogoMIPS: 4533.60
  • Virtualization: VT-x
10
  • Can you run top and see what else is running? If there is anything else.. Commented Oct 9, 2015 at 13:55
  • Show us the output of running java -version; i.e. what Java release / build are you using? Commented Oct 9, 2015 at 14:06
  • If you're using 64-bit version of java, then can you check what kind of hardware (motherboard) your VPS uses? Commented Oct 9, 2015 at 15:03
  • check ulimits, check sysctl vm_overcommit, try -XX:-UseLargePages Commented Oct 9, 2015 at 15:57
  • I assume you are using the 64-bit version of java as the 32-bit version will fail for this heap size. Commented Oct 9, 2015 at 16:58

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Robin, I am using 64bit. What do you mean by "you don't have a contiguous block of RAM" ? Could you explain more about this? Is this explanation applicable for 64 bit ? Earlier I was having a dedicated machine with 32 GB and I had succesffully allocated 10 to 25 GB without any issues....But even if I have 16 GB guaranteed RAM, why I couldn't allocate even 8 to 10GB VM?
Your subsequent edits showing the actual resource usages are quite telling. Stephen C's answer pretty much sums it up; the JVM will use virtual memory (hard drive) when there is insufficient page file space (free RAM). How the JVM decides when to swap page files to/from virtual memory will be dependent on the running processes. This is why it is recommended to reserve hard drive swap space that is equivalent to system RAM, to ensure page files can be swapped.
I neglected to clarify "contiguous RAM". RAM is allocated as page files. These pages need to be a contiguous block of addressable space. So even if you have a lot of RAM, if it's fragmented to the point that there isn't one large enough to support the page file request, then you're effectively out of heap space. I don't know how the JVM allocates the initial request for heap space but if it tries to create a single contiguous block, so it can manage paging, then you need a block of addressable space that's large enough. 7GB is a big block.
1

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.

9 Comments

Why it's taking that much swap space ? What needs to be done in order to fix this ?
But why? I allocated the maximum size as 3G to glassfish 1st instance and 1GB to 2nd. Why it's taking this much space ? How to restrict? Do I have to change the configuration of vm.overcommit ratio and memory? I have attached screenshot for that too. Please let me know how to fix this issue?
Stephen, As you said, once I stopped nexus and hudson I managed to start the second instance of glassfish that occupies 3G. 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. This is true. But is this a normal behaviour? is this how memory allocation works? I am confused with Resident memory, virtual memory and physical memory now.
You can find in the first attachment that if you add red column, it wouldn't exceed more than 3G. why virtual memory is adding up to 40+G? if res memory is the real thing, why it wasn't allowing me to give more than 10G ?
I had a dedicated system, in that, free command always showed me the right amount memory used. But why VPS behaves like this ?
|
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.