为什么xmx和top之间存在内存使用差异? [英] Why there is memory usage difference between xmx and top?

查看:643
本文介绍了为什么xmx和top之间存在内存使用差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将jvm的xmx设置为4 G,但是在运行一段时间后,当我使用top来查看内存时,它显示了使用12 G内存的过程。

I set the xmx of jvm equals to 4 G, but after running for a time, when I use top to see the memory, it shows the process used 12 G memory.

那么xmx究竟意味着什么?如果我想将jvm内存限制为4G,我该怎么办?

So what the xmx actually mean? what should I do if I want to limit the jvm memory to 4 G ?

命令行:-server -Xms4g -Xmx4g

command line: -server -Xms4g -Xmx4g

另一个相关问题:)

如果gc发生了,JVM将不可避免地释放年轻一代中不再使用的对象的空间?或者其中一些留给下一个gc?

If the gc happens, will the space of the objects that not used any more in young generation be inevitably released by JVM ? or some of them left to the next gc ?

谢谢

推荐答案

JVM的-Xmx选项指定Java
垃圾回收堆的最大大小。它不限制JVM使用的内存大小。 ps或top报告的进程大小将包括
以及进程使用的任何其他内存。以下
是不属于垃圾收集堆
的部分示例,但它们是进程所需内存的一部分:

The -Xmx option to the JVM specifies the maximum size of the Java garbage collected heap. It does NOT limit the size of the memory used by the JVM. The size of the process reported by ps or top will include that, plus any other memory used by the process. The following are examples of things that are not part of the garbage collected heap and yet are part of the memory required by the process:


  • 实现JVM的代码

  • 实现JVM的数据结构的C手动堆

  • 所有线程的堆栈在系统中(app + JVM)

  • 缓存的Java字节码(用于库和应用程序)

  • JITed机器代码(用于库和应用程序)

  • 所有已加载类的静态变量

  • Code to implement the JVM
  • The C manual heap for data structures implementing the JVM
  • Stacks for all of the threads in the system (app + JVM)
  • Cached Java bytecode (for libraries and the application)
  • JITed machine code (for libraries and the application)
  • Static variables of all loaded classes

这篇关于为什么xmx和top之间存在内存使用差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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