hughw
hughw

Reputation: 695

Java -Xmx option on Linux not limiting memory consumption

Using Oracle Java 1.7.0_05 on Ubuntu Linux 3.2.0-25-virtual, on an amazon EC2 instance having 7.5 GB of memory, we start three instances of java, each using the switch -Xmx 2000m.

We use the default Ubuntu EC2 AMI configuration of no swap space.

After running these instances for some weeks, one of them freezes -- possibly out of memory. But my question isn't about finding our memory leak.

When we try to restart the app, java gives us a message that it cannot allocate the 2000 mb of memory. We solved the problem by rebooting the server.

In other words, 2000 + 2000 + 2000 > 7500?

We have seen this issue twice, and I'm sorry to report we don't have good diagnostics. How could we run out of space with only two remaining java processes each using a max of 2000 mb? How should we proceed to diagnose this problem the next time it occurs? I wish I had a "free -h" output, taken while we cannot start the program, to show here.

TIA.

Upvotes: 0

Views: 1563

Answers (2)

km1
km1

Reputation: 2443

There may be other processes using memory therefore the JVM cannot be started with 2G. If you really need that much memory for 3 Java processes each and you only have 7.5 total you might want to change your EC2 configuration to have more memory. Your just leaving 1.5 for everything else include the kernal, Oracle etc.

Upvotes: 1

Frank Pavageau
Frank Pavageau

Reputation: 11705

-Xmx sets the maximum size of the JVM heap, not the maximum size of the java process, which allocates more memory besides the heap available to the application: its own memory, the Permanent generation, what's allocated inside JNI libraries, etc.

Upvotes: 3

Related Questions