[ZGC]Why the memory used is much larger than the dump file?

807 Views Asked by At

Here is some information:

  1. Linux version 3.18.6-2.el7.centos.x86_64、openjdk-11.0.2
  2. using ZGC and -Xms16384M -Xmx16384M
  3. top command shows : 17.013t VIRT, 0.016t RES, 0.015t SHR, 35.2 %CPU, 13.0%MEM
  4. heap dump size is 83M(using jcmd command)
  5. VisualVM Summary shows heap size is 55M
  6. In most GC situations:Garbage Collection (Proactive) 1808M(11%)->166M(1%)

I have searched and read following answers, but still can't solve my doubts.

  1. The Java ZGC garbage collector USES a lot of memory
  2. ZGC maxheap size exceed physical memory
  3. Why is my Java heap dump size much smaller than used memory?
1

There are 1 best solutions below

1
On BEST ANSWER

I'm not sure what exactly the point 6 is, it would be more helpful if you showed a few lines from your garbage collector log file. I also don't use VisualVM, so can't comment on that.

So this answer is mostly a guess.

The memory used by the JVM is divided into different regions, most importantly you have a heap and a stack. But still you will see that the heap will be bigger than what you configured with -Xmx because there is an area called Metaspace (or Permanent Generation in older JVMs) that holds static information like classes or for example String literals from your source code. And the Metaspace is on top of the "normal" heap. My guess is that some tools count it towards heap and some don't. And that might be where you get the different numbers from.