Roger Zhang Roger Zhang -5 years ago 217
Java Question

java heap memory is larger than TOP

My program run with -Xms10240m -Xmx10240m. I use top to check the memory, the size is 3.5g, it is smaller than the xms valuse.
use top

However, when I use jmap -heap, I can see the heap size is about 10g.
use jmap

What's the reason?


Answer Source
  1. -Xms option is used for JVM min-heap size definition
  2. top shows the real memory(VIRT/RES/SHR) process used

use your example -Xms10g -Xmx10g, when jvm start, it will ask op-system allocation 10g memory which will be used for heap. And op-system will try to allocate the memory for the JVM (show as VIRT), but system did not promise u it will allocate physical memory, it maybe swap ;)

But u will find the VIRT is still not 10g, that reason is 10g is for heap size, a JVM include much more the heap, for example, stack, permgen(hotspot JDK8, openJDK seems has no permgen, fix me if i am wrong), native stack, code, files etc.

And RES is for real physical memory used, it includes new objects, method etc, still not only the heap too.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download