1

I am trying to understand some system memory concepts.

If I have a Java program and its Max heap size is 5657m

And its heap used size as below: (around between 954M ~ 2.3G)

jvm_memory_bytes_used{area='heap'}

As far as I understand, if its heap size once reached 2.3G, the memory allocation would be at this level even though it went down to 954M internally within the JVM.

From system TOP command, this process current has RES of 2.7G.

  *PID USER      PR  NI    VIRT    **RES**    SHR S  %CPU **%MEM**     TIME+ COMMAND*

*13523 cloud-u+  20   0   13.8g   **2.7g**   7000 S   5.6  **8.7***

So can I conclude that:

  1. RES 2.7G = This Java process "Max of Heap size currently ever reached" + "non-Heap part" size?

  2. Since Heap ever reached 2.3G, the RES would never less than 2.3G ?

  3. Since the max heap is 5657m, the max of RES = 5657m + "non-Heap part" ?

1 Answer 1

2

Your conclusions are roughly correct.

There is however one mistake in #2: The JVM can return memory back to the OS and thus the RES value can shrink. But by default the JVM is very reluctant to do that (to a point where it's rare to see it unless you explicitly configured).

This SO question has a detailed answer showing when exactly various versions of OpenJDK release memory back to the OS and how to tweak that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.