1

I have a potentially problematic application that may have memory leak issues. However, in the process of investigating this, I've come across what seems to be conflicting information.

When I use free to get a summary of memory usage on the server, there appears to be plenty of available RAM:

[alice@myserver]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           9.8G        2.4G        131M        3.6G        7.2G        3.5G
Swap:            0B          0B          0B

However, if I use top to check the process of interest, it shows that single process using almost all of the available RAM:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
16907 alice     20   0  158.6g   9.1g   7.6g S  63.2 92.8   6476:48 my_task

Even if I count all of used(2.4G) and shared(3.6G), that is still only 6.0G, much less than the 9.1G top says this single process is using.

Which do I believe, top or free?

Some additional details, in case they are relevant:

  • OS is CentOS 7.7
  • my_task is a Java application running JDK 15 with ZGC
  • my_task uses JNI and does allocate a lot of memory off-heap (1-2GB is expected, not 4 or 5GB)
  • max heap size is 3GB, but VisualVM is showing the total heap to be ~2GB with only ~1GB allocated

1 Answer 1

2

I turns out top is the one that is wrong, and it's due to ZGC.

To avoid the overhead of masking pointers, ZGC involves multi-mapping technique. Multi-mapping is when multiple ranges of virtual memory are mapped to the same range of physical memory.

ZGC uses 3 views of Java heap ("marked0", "marked1", "remapped"), i.e. 3 different "colors" of heap pointers and 3 virtual memory mappings for the same heap.

As a consequence, the operating system may report 3x larger memory usage.

https://stackoverflow.com/questions/57899020/zgc-max-heap-size-exceed-physical-memory https://stackoverflow.com/questions/62926652/the-java-zgc-garbage-collector-uses-a-lot-of-memory

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .