MemoryMXBean.getHeapMemoryUsage()
I have a jvm process that ran with -Xms512m -Xmx512m, and below show the MemoryMXBean.getHeapMemoryUsage() of this process:
init = 512M
used = 105M
comitted = 491M
max = 491M
MemoryMXBean.getNonHeapMemoryUsage() MemoryMXBean.getNonHeapMemoryUsage() of this process:
init = 2M
used = 25M
comitted = 25M
max = 0M
-Xms
What does -Xms(The initial heap size) mean? I used to think that the initial heap size is how much memory jvm will actually allocate from os when the jvm start, but it turns out to be wrong. top shows that RES of this jvm is nearly 150m, but the jvm was ran with -Xms512M.
Is the below formula correct(or almost correct-_-)? If not, what should be considered too?
total memory a jvm used = used of MemoryMXBean.getHeapMemoryUsage()
+ used of MemoryMXBean.getNonHeapMemoryUsage()
+ the direct memory we used in application level
Anything would be appreciated!
Why max is 491M(I expect it to be 512M)?
One survivor space is not counted in max, because one of survivor spaces is always empty.
See also this answer.
What does the non-heap(who uses it) means?
MemoryMXBean counts the following JVM memory pools as "Non-heap":
See also this question.
What does -Xms(The initial heap size) mean?
Yes, it's the initial heap size. OS allocates pages in physical memory lazily (on the first access). That's why RSS can be smaller than total committed size.
See this answer for details.
Is the below formula correct
No. Things are much more complicated. I've explained this in detail in this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With