在ubuntu上限制jvm进程内存 [英] Limit jvm process memory on ubuntu

查看:839
本文介绍了在ubuntu上限制jvm进程内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有同样的问题,例如这一个被问到并回答了。我对答案不满意所以让我在这里详细说明消息。

I know there are same questions like this one been asked and answered. I am not satisfied with the answers so let me put into more detail messages here.

我尝试使用JVM OPT启动我的应用程序: -Xmx128m -Xms32m -XX:MaxPermSize = 64m 。当应用程序启动时,我通过键入 cat / proc / 10413 / status 来检查内存使用情况,我发现vmsize超过600512 kB!这比我的设置大。我想知道如何限制进程的jvm内存使用量。

I try to start my application with JVM OPTs: -Xmx128m -Xms32m -XX:MaxPermSize=64m. When the app started and I check the memory usage by typing cat /proc/10413/status, and I found the vmsize is more than 600512 kB! which is way bigger than my settings. I'd like to know how to limit the jvm memory usage of the process.

Name:   java
State:  S (sleeping)
Tgid:   10413
Pid:    10413
PPid:   1
TracerPid:      0
Uid:    1001    1001    1001    1001
Gid:    1007    1007    1007    1007
FDSize: 128
Groups: 1001 1007
**VmPeak:   728472 kB**
**VmSize:   600512 kB**
VmLck:         0 kB
VmHWM:    298300 kB
VmRSS:    280912 kB
VmData:   647804 kB
VmStk:       140 kB
VmExe:        36 kB
VmLib:     13404 kB
VmPTE:       808 kB
VmSwap:        0 kB
Threads:        33
SigQ:   0/31522
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 2000000181005ccf
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: ffffffffffffffff
Cpus_allowed:   f
Cpus_allowed_list:      0-3
Mems_allowed:   00000000,00000001
Mems_allowed_list:      0
voluntary_ctxt_switches:        3
nonvoluntary_ctxt_switches:     2


推荐答案

您无法控制您想要控制的内容 -Xmx 仅控件在Java Heap中,它不控制JVM对本机内存的消耗,根据实现情况,它会完全不同地消耗。

You can't control what you want to control, -Xmx only controls the Java Heap, it doesn't control consumption of native memory by the JVM, which is consumed completely differently based on implementation.

来自以下文章感谢内存(了解JVM如何在Windows上使用本机内存)和Linux)

维护堆和垃圾收集器使用你无法控制的本机内存。

Maintaining the heap and garbage collector use native memory you can't control.

需要更多本机内存来维护维护Java堆的
内存管理系统的状态。
收集垃圾时,必须分配数据结构
来跟踪免费存储并记录进度。这些数据结构的确切大小和性质
因实现而异,但许多与堆中
的大小成比例。

More native memory is required to maintain the state of the memory-management system maintaining the Java heap. Data structures must be allocated to track free storage and record progress when collecting garbage. The exact size and nature of these data structures varies with implementation, but many are proportional to the size of the heap.

和JIT编译器使用本机内存,就像 javac

and the JIT compiler uses native memory just like javac would


字节码编译使用本机内存(与静态
编译器(如gcc)需要运行内存的方式相同),但输入(
字节码)和输出(可执行代码)来自JIT还必须将
存储在本机内存中。包含许多
JIT编译方法的Java应用程序使用比较小应用程序更多的本机内存。

Bytecode compilation uses native memory (in the same way that a static compiler such as gcc requires memory to run), but both the input (the bytecode) and the output (the executable code) from the JIT must also be stored in native memory. Java applications that contain many JIT-compiled methods use more native memory than smaller applications.

然后你有了类加载器(s)使用本机内存

and then you have the classloader(s) which use native memory


Java应用程序由定义对象结构
和方法逻辑的类组成。它们还使用Java运行时类
库(例如java.lang.String)中的类,并且可以使用第三方
库。这些类需要存储在内存中,只要它们被使用
。类的存储方式因实现而异。

Java applications are composed of classes that define object structure and method logic. They also use classes from the Java runtime class libraries (such as java.lang.String) and may use third-party libraries. These classes need to be stored in memory for as long as they are being used. How classes are stored varies by implementation.

我甚至不会开始引用Threads部分,我想你明白了
-Xmx 不控制你认为它控制的是什么,它控制JVM堆,而不是
进入JVM堆的所有东西,以及堆占用更多的本机内存,你指定的
管理和簿记。

I won't even start quoting the section on Threads, I think you get the idea that -Xmx doesn't control what you think it controls, it controls the JVM heap, not everything goes in the JVM heap, and the heap takes up way more native memory that what you specify for management and book keeping.

这篇关于在ubuntu上限制jvm进程内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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