如何理解java.lang.management.MemoryMXBean和-Xms? [英] How to understand java.lang.management.MemoryMXBean and -Xms?

查看:55
本文介绍了如何理解java.lang.management.MemoryMXBean和-Xms?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MemoryMXBean.getHeapMemoryUsage()

我有一个运行-Xms512m -Xmx512m的jvm进程,下面显示了该进程的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

  1. 为什么最大为491M(我希望是512M)?

MemoryMXBean.getNonHeapMemoryUsage() 此过程的MemoryMXBean.getNonHeapMemoryUsage():

MemoryMXBean.getNonHeapMemoryUsage() MemoryMXBean.getNonHeapMemoryUsage() of this process:

    init     = 2M
    used     = 25M
    comitted = 25M
    max      = 0M

  1. 非堆(谁使用它)是什么意思?什么样的内存将计入此非堆中?我只知道我们在Java代码中使用的直接内存不会(对吗?)

-Xms

  1. -Xms(初始堆大小)是什么意思? 我曾经认为初始堆大小是jvm启动时jvm实际上将从操作系统分配多少内存,但事实证明这是错误的. 顶部显示该jvm的RES接近150m,但是jvm是使用-Xms512M运行的.

  1. 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!

推荐答案

为什么最大为491M(我希望是512M)?

Why max is 491M(I expect it to be 512M)?

max中不计入一个幸存者空间,因为其中一个幸存者空间始终为空.
另请参见此答案.

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将以下JVM内存池计为非堆":

MemoryMXBean counts the following JVM memory pools as "Non-heap":

  • 代码缓存(或代码堆)-编译方法和其他动态生成的代码的区域;
  • 元空间和压缩的类空间-类元数据的区域.

另请参见此问题.

-Xms(初始堆大小)是什么意思?

What does -Xms(The initial heap size) mean?

是的,它是初始堆大小.操作系统延迟(在第一次访问时)在物理内存中分配页面.这就是RSS可以小于总提交大小的原因.

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.

这篇关于如何理解java.lang.management.MemoryMXBean和-Xms?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆