1

Using jdk1.8.0_152 I am trying to track down what part of my java program is using the most memory (mainly in the heap)

Using top I see that the whole process is using around 1.109G of residual memory

Using jcmd {PID} VM.native_memory I see that the total reserved is 4704896 KB and the committed is around 1290820 KB. Committed is slightly more than residual memory but I've read that not all committed memory could have been paged to actual memory so I'm not so concerned about that difference

The main concern I have right now is the difference between the heap memory usage from VM.native_memory and total heap usage when I use jcmd {PID} GC.class_histogram

I've also tried to compare the heap usage using jstat -gc {PID} and got results similar to GC.class_histogram

According to GC.class_histogram and jstat -gc, heap usage is around 250MB but using VM.native_memory heap usage(committed in the Java Heap section) is around 1000000KB (so little less than 1GB) but the actual RSS memory seems to be closer to the total committed in VM.native_memory

My guess right now is VM.native_memory Java Heap contains memory that has not been garbage collected but even when I run garbage collection, I see that the result of jstat -gc decreasing dramatically while VM.native_memory isn't affected at all (although I've heard the user manually invoking garbage collection won't always lead to a full garbage collection but it seems at least that jstat -gc seems to match the result from GC.class_histogram.

Another thing I've heard is residual memory from top isn't always freed when the process using the memory frees it until that memory absolutely needs to be freed.

So to sum up

  1. Why is VM.native_memory showing a different heap memory usage from jstat and GC.class_histogram?
  2. Which metric should I use to make sure how much memory my java process is using? (given that residual memory in top might not always reflect the actual usage)
6
  • @Holger according to docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/… native memory seems to refer to all the memory Java Hotspot VM uses, including heap and also other memory such as thread (stack), class caches etc
    – markk
    Sep 30, 2019 at 10:52
  • I see, so you don’t understand that “committed” does not mean “used” in the sense of “filled with Java objects”?
    – Holger
    Sep 30, 2019 at 10:56
  • @Holger hmm.. yes if I understand you correctly? but according to the documentation it says "Note that only committed memory is actually used." so it seems like committed should be "used". According to how total committed is similar to what top says the process is using it seems like committed should be "used"? (although residual memory might refer to the total memory jvm has locked compared to the memory being actually "filled with objects". But according to the documentation "committed" seems to refer to objects actually filling that memory up")
    – markk
    Sep 30, 2019 at 11:17
  • 1
    Memory that has not been committed, obviously is not used. However, heap memory that has been used, but becomes free due to garbage collection still is committed and will be reused for subsequent allocations. Giving memory back to the system happens rarely, some garbage collectors will never give back.
    – Holger
    Sep 30, 2019 at 11:32
  • 1
    The committed RAM doesn’t have to be an upper bound, there might be attempts to commit more when necessary (though, usually there’s at least one garbage collection attempt before trying to commit more). See also this summary.
    – Holger
    Sep 30, 2019 at 15:02

1 Answer 1

0

i guess your jvm heap has been set with a range size.

native memory tracker displays memory size from os view (which is close to top command), while jstat displays at an inner perspective from jvm.

it means that jvm will request mem from os (check from top), but really use it or not depends on itself (check by jstat or jmap).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.