when is the jvm heap allocated by the OS

326 views Asked by At

One of our sap systems(PI ABAP+JAVA stack) was giving performance issue. The entire 64GB configured for the machine gets hogged up(and the 8 cores as well). Every one is suspecting the java part, but I think different.

The java server nodes where getting restarted with Out Of Memory error. Looking at the hprof files, I found that they where only 1.2G (avg of 3 server nodes) in size , when 3GB(both -Xms and Xmx) of heap is configured for the server nodes. This observation lead to the following doubt.

I have read that when Xms and Xmx are set to the same value, the jvm is allocated the entire heap when it starts. If its the case the server nodes would have 3GB of heap from the start. If so why does it doesn't reflect in the hprof file or if the hprof contains only the memory allocated to objects during runtime, the the size clearly indicates that the heap memory was free(more than 50%), so how OOM error...!!..??

I also know that linux does something called as memory over-commit. ie memory is not actually given when its requested but when its actually used. Is this contributing to the out of memory exception. Like when the JVM starts the OS says to it that you have been allocated 3GB of memory but actually defers it until its actually required. By the time the jvm actually tries to allocate the memory to objects , some other applications might have exhausted the memory. Is this possible...??

Even if the java nodes had memory leak issue, wouldn't it be confined to the 3GB of heap. How can it hog up the entire 64G of physical memory....???

One more thing I observed was the swap space was only 50% used.

Any light on this...!

1

There are 1 answers

0
pbespechnyi On

The hprof doesn't show actual heap size, and its size depends on many things, like enabled/disabled compressed references, field layouting (the object size isn't just sum of sizes of its fields, but also headers and some gaps between fields) and so on.

About memory reserving. The JVM does reserve memory for the heap, but OS doesn't allocate memory until it's needed.

I would recommend you to use memory profilers (I highly recommend YourKit profiler) to connect to running virtual machine and then analyze memory usage.