Java本机内存使用情况

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2756798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 12:29:58  来源:igfitidea点击:

Java native memory usage

javamemorynativeout-of-memory

提问by NoodleX

Is there any tool to know how many native memory has been used from my java application ? I've experienced outofmemory from my application : Current setting is : -Xmx900m

有什么工具可以知道我的 Java 应用程序使用了多少本机内存?我的应用程序内存不足:当前设置是:-Xmx900m

Computer, Windows 2003 Server 32bit, RAM 4GB.

计算机,Windows 2003 Server 32 位,RAM 4GB。

Also is changing boot.ini to /3GB on windows, will make any difference? If is set Xmx900m, how much max native memory can be allocated for this process ? is it 1100m ?

在 Windows 上也将 boot.ini 更改为 /3GB,会有什么不同吗?如果设置为 Xmx900m,则可以为该进程分配多少最大本机内存?是1100m吗?

采纳答案by Eugene To

(in my case I use java 8)

(在我的情况下,我使用 java 8)

add to command line: -XX:NativeMemoryTracking=summary

添加到命令行: -XX:NativeMemoryTracking=summary

then launch jcmd <PID> VM.native_memory

然后启动 jcmd <PID> VM.native_memory

You should get something like this:

你应该得到这样的东西:

Total: reserved=3863657KB, committed=1679977KB
-                 Java Heap (reserved=1843200KB, committed=824320KB)
                            (mmap: reserved=1843200KB, committed=824320KB) 

-                     Class (reserved=1311974KB, committed=298726KB)
                            (classes #52579)
                            (malloc=5350KB #76340) 
                            (mmap: reserved=1306624KB, committed=293376KB) 

-                    Thread (reserved=263278KB, committed=263278KB)
                            (thread #256)
                            (stack: reserved=262140KB, committed=262140KB)
                            (malloc=839KB #1280) 
                            (arena=299KB #510)

-                      Code (reserved=278521KB, committed=164773KB)
                            (malloc=28921KB #37983) 
                            (mmap: reserved=249600KB, committed=135852KB) 

-                        GC (reserved=114897KB, committed=77093KB)
                            (malloc=13729KB #67925) 
                            (mmap: reserved=101168KB, committed=63364KB) 

-                  Compiler (reserved=461KB, committed=461KB)
                            (malloc=330KB #1138) 
                            (arena=131KB #3)

-                  Internal (reserved=13877KB, committed=13877KB)
                            (malloc=13845KB #72978) 
                            (mmap: reserved=32KB, committed=32KB) 

-                    Symbol (reserved=28871KB, committed=28871KB)
                            (malloc=24740KB #275452) 
                            (arena=4131KB #1)

-    Native Memory Tracking (reserved=8393KB, committed=8393KB)
                            (malloc=45KB #523) 
                            (tracking overhead=8348KB)

-               Arena Chunk (reserved=184KB, committed=184KB)
                            (malloc=184KB) 

For more information see https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr007.html

有关更多信息,请参阅https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr007.html

回答by Mirek Pluta

If you use for example jvisualvm ( it's shipped with jdk ) you can see how much memory your application is using, you can also profile it more detailously.

例如,如果您使用 jvisualvm(它与 jdk 一起提供),您可以查看您的应用程序使用了多少内存,您还可以更详细地对其进行分析。

回答by Affe

The free process space is a bit smaller than 2GB - Xmx. (assuming Sun JVM) You have to add your permgen space to Xmx, and then subtract around 150-200MB or so for the OS's Kernel stuff. If the real problem is a genuine lack of memory, the 3GB switch or reducing your Xmx and PermGen space should alleviate it. Sometimes, at least on Windows, the OS just takes longer than the JVM is willing to wait to allocate a thread and the problem is more that you're spamming thread spawns than running out of memory. You should have memory space for a few thousand threads. How many do you have before it gives up?

可用进程空间略小于 2GB - Xmx。(假设 Sun JVM)您必须将 permgen 空间添加到 Xmx,然后为操作系统的内核内容减去大约 150-200MB 左右。如果真正的问题是内存不足,3GB 切换或减少 Xmx 和 PermGen 空间应该可以缓解它。有时,至少在 Windows 上,操作系统所花的时间比 JVM 愿意等待分配线程的时间长,问题更多的是您正在发送垃圾邮件而不是内存不足。你应该有几千个线程的内存空间。在它放弃之前你有多少?

There's also a -Xss switch to control how big a thread stack the JVM asks for. YMMV if changing it actually does anything on Windows or not.

还有一个 -Xss 开关来控制 JVM 要求的线程堆栈有多大。YMMV 如果更改它实际上是否在 Windows 上执行任何操作。

回答by dmalechek

For those that come after, VMMap will give you your answer. It will show native memory allocations. In my experience, the -Xss is ignored at minimum amount of 124K I believe within the OS allocation chunks. The OS allocations come in ever doubling chunks until it gets to 1GB(and then you're done.) If you can't reduce your threads, then try reducing your max heap and max permgen settings or try the /3GB switch.

对于后来者,VMMap 会给你答案。它将显示本机内存分配。根据我的经验,-Xss 在操作系统分配块内的最小 124K 时被忽略。操作系统分配以不断加倍的块进行,直到达到 1GB(然后您就完成了)。如果您无法减少线程,请尝试减少最大堆和最大 permgen 设置或尝试 /3GB 开关。

回答by 11101101b

This articlegives some good information about hunting down native memory issues and explains how you run out of native memory.

本文提供了一些有关查找本机内存问题的好信息,并解释了本机内存不足的情况。

回答by user2173387

Native Memory is an area which is usually used by the JVM for it's internal operations and to execute the JNI codes. The JVM Uses Native Memory for Code Optimization and for loading the classes and libraries along with the intermediate code generation. The Size of the Native Memory depends on the Architecture of the Operating System and the amount of memory which is already commited to the Java Heap. Native memory is an Process Area where the JNI codes gets loaded or JVM Libraries gets loaded or the native Performance packs and the Proxy Modules gets loaded. There is no JVM Option available to size the Native Area. but we can calculate it approximately using the following formula:

本机内存是 JVM 通常用于其内部操作和执行 JNI 代码的区域。JVM 使用本机内存进行代码优化以及加载类和库以及中间代码生成。本机内存的大小取决于操作系统的体系结构和已提交给 Java 堆的内存量。本机内存是一个进程区,在其中加载 JNI 代码或加载 JVM 库或加载本机性能包和代理模块。没有可用于调整本机区域大小的 JVM 选项。但我们可以使用以下公式大致计算它:

NativeMemory = (ProcessSize – MaxHeapSize – MaxPermSize)

NativeMemory = (ProcessSize – MaxHeapSize – MaxPermSize)

Found this at devopsconsole

devopsconsole 上找到了这个