0

I have a java application, which is run with following settings:

/usr/bin/java ... -XX:+UseG1GC -Xms18G -Xmx22G ...

At the same time I can see that java binary uses 27617528 of RSS (32453352 virt) on server.

Why it's so and how can I limit java memory for sure?

George Shuklin
  • 6,952
  • 10
  • 39
  • 80
  • 1
    `32453352k`? 32TB? – BackSlash Dec 19 '18 at 10:50
  • 2
    because memory settings you pass are different comparing to native memory. What you set there, affects JVM's memory, available to Java processes. But JVM itself can consume memory (system's) for it's own purposes. You can also have situation where native code (called by your JVM) - e.g. via JNI - will allocate memory way beyond your limits (via malloc). – Oo.oO Dec 19 '18 at 10:51
  • Sign... Thanks. Java is one big WTF for operators. – George Shuklin Dec 19 '18 at 13:20

1 Answers1

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 ...
kofemann
  • 4,217
  • 1
  • 34
  • 39