Incorrect Memory Usage Reported When Using ZGC + sun.misc.Unsafe

Erik Österlund erik.osterlund at
Fri Jan 4 09:13:34 UTC 2019

Hi Alex,

Unfortunately, attachments to the mailing list get eaten by the evil 
mail server monster. So I can't see any of the attachments you mentioned.

Having said that, the kernel is known to be pretty bad at accounting 
resident memory when using multi-mapping. ZGC multi-maps the Java heap, 
so that there are multiple virtual addresses for the same physical 
memory. Unfortunately, the kernel doesn't get that it is indeed the same 
physical memory, and messes up in the accounting. That is most likely 
why you are seeing weird numbers for resident memory used.

If you are curious about how much memory is actually being used, I think 
you are better off checking that using NMT. For more information, please 
consult the following documentation:

Hope this helps.


On 2019-01-04 02:22, Alex Elent wrote:
> Hello,
> Looking for some help on an issue we are experiencing exclusively with ZGC.
> I'm unsure if the problem lies with ZGC or the kernel or where. Looking for
> your experienced guidance if possible.
> We experienced this in our actual application but I managed to create a
> simpler reproducible case.
> I've attached the example Java file (
> I've attached a screenshot of top reporting 108% resident memory used.
> This is running on an EC2 t2.medium instance (2 vCPU / 4GB RAM).
> I compile with:
> javac -cp .
> I run with:
> java -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xms3500M -Xmx3500M -cp .
> TestUnsafe
> Thank you so much for your help!

More information about the zgc-dev mailing list