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

查看:19
本文介绍了限制 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 对本机内存的消耗,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 的输出(可执行代码)也必须存储在本机内存中.Java 应用程序包含许多JIT 编译的方法比较小的应用程序使用更多的本机内存.

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.

然后你有使用本机内存的类加载器

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.

我什至不会开始引用关于线程的部分,我想你明白了-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天全站免登陆