我有一个Java应用程序,该应用程序通过以下设置运行:
/usr/bin/java ... -XX:+UseG1GC -Xms18G -Xmx22G ...
与此同时,我看到Java二进制文件在服务器上使用了27617528的RSS(32453352 virt)。
为什么会这样,我如何确定限制Java内存?
答案 0 :(得分:0)
With -Xmx
you limit only java heap size - the memory available to a java application, but not to the JVM (running java binary). To limit the memory of a process you can use ulimit
command or, the more modern way to do it, create a cgroup
:
$ sudo cgcreate -g memory:/memlimited
$ sudo cgset -r memory.limit_in_bytes=22G memlimited
$ sudo cgexec -g memory:/memlimited /usr/bin/java ... -XX:+UseG1GC ...