简体   繁体   English

本机 memory 消耗的 JVM vs java 进程总 ZCD69B4957F06CD818D7BF3DD618

[英]Native memory consumed by JVM vs java process total memory usage

I have a tiny java console application which I would like to optimize in terms of memory usage.我有一个很小的 java 控制台应用程序,我想在 memory 使用方面进行优化。 It is being run with Xmx set to only 64MB.它在 Xmx 设置为仅 64MB 的情况下运行。 The overall memory usage of the process according to different monitoring tools (htop, ps, pmap, Dynatrace) shows values above 250MB. memory根据不同的监控工具(htop、ps、pmap、Dynatrace)显示的进程使用率在250MB以上。 I run it mostly on Ubuntu 18 (tested on other OS-es as well).我主要在 Ubuntu 18 上运行它(也在其他操作系统上测试过)。

I've used -XX:NativeMemoryTracking java param and Native Memory Tracking with jcmd to find out why so much more memory is used outside of the heap.我使用了 -XX:NativeMemoryTracking java 参数和 Native Memory Tracking with jcmd 来找出为什么更多的 ZCD69B4957F06CD818D7ZBF3D61980E291 在外部使用。

The values displayed by NMT when summarized were more or less the same as the ones shown by htop as Resident Memory.汇总时 NMT 显示的值与 htop 显示的值大致相同,即 Resident Memory。

NMT :神经网络

Total: reserved=1518873KB, committed=255877KB

htop :顶部

在此处输入图像描述

I've used several JVM parameters to reduce native memory consumption (reduced stack size, changed GC to serial, Class Data Sharing etc).我使用了几个 JVM 参数来减少原生 memory 消耗(减少堆栈大小,将 GC 更改为串行,Class 数据共享等)。 Both reserved and committed memory metrics went down according to NMT (both malloced and mmaped) by let's say ~50MB in total.根据 NMT(malloced 和 mmaped),保留和提交的 memory 指标下降了约 50MB。

NMT :神经网络

Total: reserved=1475110KB, committed=209218KB

All the tools that I'm using (htop, ps, pmap, Dynatrace) show no difference at all.我使用的所有工具(htop、ps、pmap、Dynatrace)完全没有区别。 Total memory used by the process is still 250MB.进程使用的总 memory 仍然是 250MB。

  1. The question is, why is that?问题是,为什么会这样? Why reducing native memory usage by JVM does not make any effect on the resident memory used by the java process?为什么通过 JVM 减少本机 memory 使用不会对 Z93F7264A07B33D2C1 进程使用的常驻 memory 产生任何影响? Is it reserved somehow upfront and not released?它是否以某种方式预先保留而不是发布?
  2. Is there any other way to effectively reduce memory consumption by the whole java process (outside of the heap which is already optimized and set to only 64MB)?有没有其他方法可以有效地减少整个 java 进程的 memory 消耗(在已经优化并设置为仅 64MB 的堆之外)?

NativeMemoryTracking may report less committed memory than the actual Resident Set Size (RSS) of a process for multiple reasons.由于多种原因,NativeMemoryTracking 报告的提交 memory 可能比进程的实际驻留集大小 (RSS) 少。

  • NMT counts only certain JVM structures. NMT 仅计算某些 JVM 结构。 It does not count memory mapped files (including loaded.jar files), nor memory allocated by libraries other than libjvm .它不计算 memory 映射文件(包括加载的.jar 文件),也不计算由 libjvm 以外的库分配的libjvm Even native memory allocated by the standard class library (ie libjava ) is not shown in NMT report.甚至由标准 class 库(即libjava )分配的本机 memory 也没有显示在 NMT 报告中。

  • When something allocates memory with a standard system allocator ( malloc ) and then releases it, this memory isn't always returned back to the OS.当某些东西使用标准系统分配器( malloc )分配 memory 然后释放它时,这个 memory 并不总是返回给操作系统。 The system allocator may keep released memory in a pool for future reuse, but from the OS perspective this memory is considered used (and thus included in RSS).系统分配器可能会在池中保留释放的 memory 以供将来重用,但从操作系统的角度来看,此 memory 被认为已使用(因此包含在 RSS 中)。

This answer and this video may give an idea what else takes memory, and how to analyze footprint of a Java process. 这个答案这个视频可能会让你知道 memory 还需要什么,以及如何分析 Java 进程的足迹。

This post describes some ideas (both reasonable and extreme) on reducing footprint. 这篇文章描述了一些关于减少足迹的想法(合理的和极端的)。

  A typical memory representation of C program consists of following sections.

  1. Text segment
  2. Initialized data segment
  3. Uninitialized data segment
  4. Stack
  5. Heap
  • JVM memory includes: JVM heap, JVM Stack, JVM native stack, The pc Register, and so on. JVM memory includes: JVM heap, JVM Stack, JVM native stack, The pc Register, and so on.

( https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.5 ) https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.5

and the JVM heap just a part of Java Heap section (in c program memory representation).和 JVM 堆只是 Java 堆部分的一部分(在 c 程序 ZCD299B49576198CD 表示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM