[英]Java process memory usage much more than what Runtime.totalMemory et al methods are telling
I have been stuck with this problem for long now without any hint whatsoever. 我一直坚持这个问题很久没有任何暗示。 Will really appreciate if someone can help.
如果有人能提供帮助,我们真的很感
I am running a Java application on device with ARM v7 processor.It has Ubuntu installed on it. 我正在使用ARM v7处理器在设备上运行Java应用程序。它上面安装了Ubuntu。 The memory usage of the process when seen using "top" or "free -m" commands is about 180 MB which is much more than what the Runtime.freeMemory et al methods are telling me.
使用“top”或“free -m”命令看到的进程的内存使用量大约为180 MB,远远超过Runtime.freeMemory等方法告诉我的内存。
This is how I am starting my application: 这就是我开始申请的方式:
java -Xcheck:jni -XX:MaxPermSize=25m -Xmx65m -XX:ReservedCodeCacheSize=10m -jar MyAPP.jar myconfig.xml
java -Xcheck:jni -XX:MaxPermSize = 25m -Xmx65m -XX:ReservedCodeCacheSize = 10m -jar MyAPP.jar myconfig.xml
As far as I understand, the total memory usage of this process should not cross 25 + 65 + 10 = 100 MB
. 据我了解,此进程的总内存使用量不应超过
25 + 65 + 10 = 100 MB
。 It may be a bit more (other non-heap spaces I am not aware of). 它可能会更多(我不知道的其他非堆空间)。 But even then I dont think the difference should be this much (80 MB).
但即便如此,我也不认为差异应该是这么多(80 MB)。
This is what "Runtime" commands seem to tell me in my logs (I use those commands to print usage info as part of my debug logs). 这就是“运行时”命令似乎在我的日志中告诉我的内容(我使用这些命令来打印使用信息作为我的调试日志的一部分)。
Usage Info: Avaialable processors: 2 Free memory available to JVM: 8474344, Current memory usage: 5943576, Maximum memory JVM is allowed to use: 66977792 使用信息:Avaialable处理器:2个可用于JVM的可用内存:8474344,当前内存使用量:5943576,允许使用的最大内存JVM:66977792
Output from "top": “顶部”输出:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3926 linaro 20 0 266m 188m 3636 S 1.0 21.1 0:37.81 java
Output from "free -m": “free -m”的输出:
When Java process is running: 当Java进程运行时:
total used free shared buffers cached
Mem: 893 842 51 0 40 216
-/+ buffers/cache: 585 308
Swap: 0 0 0
When the process has been stopped: 当进程停止时:
total used free shared buffers cached
Mem: 893 656 237 0 40 216
-/+ buffers/cache: 400 493
Swap: 0 0 0
As we can see, 493 - 308 = 185, is matching what "top" is saying about memory usage of this process (Earlier I thought maybe there is a bug with top installed on this machine). 正如我们所看到的,493 - 308 = 185,匹配“顶级”关于此进程的内存使用情况的说法(之前我认为可能在此计算机上安装了顶级错误)。
I did remote monitoring of this process too, it shows "committed" heap space of about 14M and non-heap of about 20M. 我也对这个进程进行了远程监控,它显示了大约14M的“已提交”堆空间和大约20M的非堆。 At least the heap space matches what I got from "Runtime" commands.
至少堆空间与我从“运行时”命令获得的空间相匹配。 So even remote monitoring tool seems to say that memory usage is much less than 180M.
因此,即使远程监控工具似乎也说内存使用量远低于180M。
The most strange part is that the same jar when I run on my laptop (MacBook Pro) or a standard Intel based Linux box (not ARM) everything seems in place. 最奇怪的部分是,当我在笔记本电脑(MacBook Pro)或基于标准Intel的Linux机箱(不是ARM)上运行时,同样的罐子似乎到位。 Process uses only about 60 MB of space which is what I expect.
进程只使用大约60 MB的空间,这是我所期望的。
Another point worth mentioning is that the Java VM I am using on ARM device is Java SE Embedded version by Oracle. 值得一提的另一点是我在ARM设备上使用的Java VM是Oracle的Java SE Embedded版本。
Anyone with an idea of this discrepancy in memory usage. 任何人都知道这种内存使用上的差异。 Sorry for asking such a long question :-).
很抱歉问这么长的问题:-)。
UPDATE: 更新:
After doing some research about the various parts of a Java process which can consume memory, I zeroed down on native code interaction (JNI). 在对可以消耗内存的Java进程的各个部分进行一些研究之后,我将本机代码交互(JNI)归结为一体。 That is the only guy whose memory consumption we can not limit from command live arguments.
这是唯一一个我们无法通过命令实时参数限制内存消耗的人。 In my program I am using sqlite-jdbc driver to access database.
在我的程序中,我使用sqlite-jdbc驱动程序来访问数据库。 I commented the database access part and memory usage came down to 24MB!!!
我评论了数据库访问部分和内存使用量降至24MB! So I am guessing that this memory discrepancy has something to do with this sqlite jdbc access, though not yet sure what it is.
所以我猜这个内存差异与这个sqlite jdbc访问有关,虽然还不确定它是什么。 Will keep updating as I make some progress.
随着我取得一些进展,将继续更新。
-Sandeep -Sandeep
What you observe is the difference between JVM vs Process Memory. 您观察到的是JVM与进程内存之间的区别。
Have a look at these answers: 看看这些答案:
Process Memory Vs Heap -- JVM 进程内存与堆 - JVM
JVM Process vs JVM Heap memory usage JVM进程与JVM堆内存使用情况
Since you are using different JVM implementations on each system you might have different memory behaviour. 由于您在每个系统上使用不同的JVM实现,因此可能具有不同的内存行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.