Java 中内存主机和内存参数 xms 和 xmx 之间的关系 [英] Relation between memory host and memory arguments xms and xmx from Java

查看:38
本文介绍了Java 中内存主机和内存参数 xms 和 xmx 之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下包含内存详细信息的主机:

$free -m缓存的已用空闲共享缓冲区总数电话:7872 7579 292 17 483 3983-/+ 缓冲区/缓存:3112 4759掉期:2047 14 2033

我有一个运行参数 -Xms200m -Xmx200m 的 java 应用程序,谁能解释一下为什么 VCZ 是 3800076 而 RSS 是 241304(更多的是 Java 参数)>

来自 ps -aux 命令:

66345 6773 0.2 2.9 3800076 241304 ?Sl Apr1 12:06/apps/myapps/myapp1/java/bin/java -Xms200m -Xmx200m

解决方案

Java 进程使用的内存(如操作系统所见)不仅限于 Java 堆.还有更多的内存区域需要计算:

  • 元空间(类元数据所在的位置);
  • 代码缓存(存储 JIT 编译的方法和所有生成的代码);
  • 直接字节缓冲区;
  • 内存映射文件,包括JVM映射的文件,例如类路径上的所有 JAR 文件;
  • 线程栈;
  • JVM 代码本身以及 Java Runtime 加载的所有动态库;
  • 其他内部 JVM 结构.

使用 NativeMemoryTracking JDK 功能获取内存的详细细分JVM 使用的区域:

java -XX:NativeMemoryTracking=detail -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics

I have the following host with the memory details:

$free -m
             total       used       free     shared    buffers     cached
Mem:          7872       7579        292         17        483       3983
-/+ buffers/cache:       3112       4759 
Swap:         2047         14       2033

I have a java app running with the params -Xms200m -Xmx200m, could someone please explain me why the VCZ is 3800076 and the RSS is 241304 (which is more of the Java params)

from the ps -aux command:

66345     6773  0.2  2.9 3800076 241304 ?      Sl   Apr1  12:06 /apps/myapps/myapp1/java/bin/java -Xms200m -Xmx200m

解决方案

Memory used by Java process (as seen by the OS) is not only limited to Java Heap. There are a lot more memory areas that should be also counted:

  • Metaspace (where class metadata resides);
  • Code Cache (storage for JIT-compiled methods and all the generated code);
  • Direct ByteBuffers;
  • Memory-mapped files, including files mapped by JVM, e.g. all JAR files on the classpath;
  • Thread stacks;
  • JVM code itself and all the dynamic libraries loaded by Java Runtime;
  • Other internal JVM structures.

Use NativeMemoryTracking JDK feature to get the detailed breakdown of memory areas used by JVM:

java -XX:NativeMemoryTracking=detail -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics

这篇关于Java 中内存主机和内存参数 xms 和 xmx 之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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