Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my JVM's total memory usage more than 30 times greater than its Xmx value?

Tags:

java

jvm

I am running a Java application with a maximum heap size of 128 MB (-Xmx128M). It is running to successful completion with no OutOfMemoryError, or any other unhandled exception. Therefore, I am assuming that its actual heap size did stay within the declared limit of 128 MB.

However, when observing the process for this Java application, I am seeing a peak total memory usage of 4,188,548 KB (~4 GB). This is a growth of more than 30 times the controlled maximum size of the heap. Although I understand that this value includes virtual memory allocated that may be significantly greater than the actual physical memory used, it affects hard limits such as those imposed by Sun Grid Engine, and therefore it is meaningful.

How exactly is this possible? I understand that the total memory consumed by the JVM includes quite a bit more than the size of the heap, but I do not understand how it could need several GB of extra memory beyond what the application actually needs to create its objects and perform its computation.

I am using Sun Java 1.6.0.31, on a 64-bit RHEL Linux distribution.

like image 857
jjcarver Avatar asked Mar 15 '12 18:03

jjcarver


1 Answers

There are several memory sinks besides the Java heap controlled by -Xmx:

  • Thread stacks
  • PermGen space
  • direct ByteBuffers and mapped ByteBuffer
  • memory allocated by native code / libraries

Without knowing details of your system I would guess, that something uses mapped ByteBuffers.

But you could dig into the issue by examing the output of the pmap command. It lists all memory regions of the process together with the filenames any region is mapped to (if the regions is mapped of course).

like image 84
A.H. Avatar answered Nov 08 '22 22:11

A.H.