[lxc-users] java11 vs memory.limit_in_bytes

Harald Dunkel harald.dunkel at aixigo.com
Fri Feb 28 08:36:38 UTC 2020


Hi folks,

according to some notes on the net (e.g. [1]) openjdk11 is aware of
the container limits for calculating default heap size and some
other internal parameters. Apparently this works very well for
Docker. Sample:

# docker run -ti --rm --cpus 2 -m 4G debian
root at c526096eb86e:/# apt update; apt install -y default-jdk
:
:
done.
done.
Processing triggers for libgdk-pixbuf2.0-0:amd64 (2.38.1+dfsg-1) ...
root at c526096eb86e:/# cat /sys/fs/cgroup/memory/memory.limit_in_bytes
4294967296
root at c526096eb86e:/# cat /sys/fs/cgroup/memory/memory.memsw.limit_in_bytes
8589934592
root at c526096eb86e:/# java -XX:MaxRAMPercentage=20.0 -XX:MinRAMPercentage=10.0 -XX:+PrintFlagsFinal -version | egrep MaxHeap\|RAMPercentage\|Container
    double InitialRAMPercentage                     = 1.562500                                  {product} {default}
     uintx MaxHeapFreeRatio                         = 70                                     {manageable} {default}
    size_t MaxHeapSize                              = 859832320                                 {product} {ergonomic}
    double MaxRAMPercentage                         = 20.000000                                 {product} {command line}
    double MinRAMPercentage                         = 10.000000                                 {product} {command line}
      bool PreferContainerQuotaForCPUCount          = true                                      {product} {default}
      bool UseContainerSupport                      = true                                      {product} {default}
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Debian-1deb10u1, mixed mode, sharing)


Check the MaxHeapSize. 20% of 4 GByte, as requested.

For an LXC container running Debian and the same OpenJDK I get:


root at debian10:~# cat /sys/fs/cgroup/memory/memory.limit_in_bytes
4294967296
root at debian10:~# cat /sys/fs/cgroup/memory/memory.memsw.limit_in_bytes
4294967296
root at debian10:~# java -XX:MaxRAMPercentage=20.0 -XX:MinRAMPercentage=10.0 -XX:+PrintFlagsFinal -version | egrep MaxHeap\|RAMPercentage\|Container
    double InitialRAMPercentage                     = 1.562500                                  {product} {default}
     uintx MaxHeapFreeRatio                         = 70                                     {manageable} {default}
    size_t MaxHeapSize                              = 13511950336                               {product} {ergonomic}
    double MaxRAMPercentage                         = 20.000000                                 {product} {command line}
    double MinRAMPercentage                         = 10.000000                                 {product} {command line}
      bool PreferContainerQuotaForCPUCount          = true                                      {product} {default}
      bool UseContainerSupport                      = true                                      {product} {default}
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Debian-1deb10u1, mixed mode, sharing)


memory.limit_in_bytes is 4 GByte, but Java gives me a MaxHeapSize of
0.20 * 64GByte.

Of course I don't want to blame you for bugs in OpenJDK, but I wonder
how comes? Are there some mysterious params set in a Docker container,
but missing in LXC?


Every insightful comment is highly appreciated
Harri


1: https://stackoverflow.com/questions/54292282/clarification-of-meaning-new-jvm-memory-parameters-initialrampercentage-and-minr/54297753#54297753


More information about the lxc-users mailing list