JDK-8250627 : Use -XX:+/-UseContainerSupport for enabling/disabling Java container metrics
  • Type: Enhancement
  • Component: core-libs
  • Affected Version: 8,11,15,16
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: generic
  • Submitted: 2020-07-27
  • Updated: 2021-05-11
  • Resolved: 2020-07-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13 JDK 15 JDK 16 JDK 8 Other
11.0.10-oracleFixed 13.0.6Fixed 15.0.4Fixed 16 b09Fixed 8u271Fixed openjdk8u272Fixed
Related Reports
Relates :  
Relates :  
Description
For hotspot one can disable container detection with a simple switch:

$ java -XX:-UseContainerSupport -Xlog:os+container=trace -version
[0.000s][trace][os,container] OSContainer::init: Initializing Container Support
[0.000s][trace][os,container] Container Support not enabled
openjdk version "15-internal" 2020-09-15
OpenJDK Runtime Environment (build 15-internal+0-adhoc.sgehwolf.openjdk-head-2)
OpenJDK 64-Bit Server VM (build 15-internal+0-adhoc.sgehwolf.openjdk-head-2, mixed mode, sharing)

The same cannot be achieved with the Java code,
jdk.internal.platform.Metrics.java and friends in the JDK. At the time
Metrics were added the only consumer of them was the Java Launcher via
-XshowSettings:system. This has changed with JDK-8226575:
OperatingSystemMXBean should be made container aware.

It is known that in certain cases the container detection code will
detect for a system to be supposedly in a container where it actually
isn't:
https://bugs.openjdk.java.net/browse/JDK-8227006?focusedCommentId=14275604&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14275604

For hotspot there is a flag, to turn auto-detection off for exactly the
case when heuristics are wrong: -XX:-UseContainerSupport. However, this
flag has no effect on the Java metrics code. There is a risk that on
some systems the auto-detection will be wrong and might cause
regressions.

I propose to make the Java metrics code adhere to -XX:+/-
UseContainerSupport flag.
Comments
Fix request (15u) Requesting backport to 15u for parity with 11u. The patch applies cleanly. Tested with container tests, including new one and tier1.
07-05-2021

Fix request (13u) Requesting backport to 13u for parity with 11u. Minor adjustments needed to apply the patch. Tested with container tests, including new one and tier1. RFR: http://mail.openjdk.java.net/pipermail/jdk-updates-dev/2020-November/004275.html
27-11-2020

Fix Request (OpenJDK 8u): Please approve backporting this to OpenJDK 8u now that JDK-8203357 is in. The JDK 11u fix didn't apply cleanly mostly because in JDK 8u repositories are split between jdk and hotspot. Code has been reviewed by Aleksey Shipilev. I'd like this to go into JDK 8u since there won't be an option to disable container detection for the Java code otherwise. It's possible for the native code already with -XX:-UseContainerSupport. This should be helpful as a work-around when auto container detection goes wrong for some reason. Also in light of JDK-8226575 being in process of getting backported. Risk should be low as this code only adds a turn-off knob. Testing: added regression test. Existing container tests. webrev: https://cr.openjdk.java.net/~sgehwolf/webrevs/JDK-8250627/jdk8/01/ RFR (approved): http://mail.openjdk.java.net/pipermail/jdk8u-dev/2020-August/012437.html
13-08-2020

Fix Request (OpenJDK 11u): Please approve getting this disable switch into JDK 11u as there is currently no way to disable container detection on the Java side. With JDK-8226575 having been backported to 11.0.9 there is a risk of container detection getting it wrong with no way to disable it. The JDK 16 patch doesn't apply cleanly since the code in 11u is cgroups v1 only, thus natives are moved a bit. Changed code has been reviewed by Aleksey Shipilev. Testing: new test, existing container tests and tier1. Risk should be low as it's only a turn off knob which gets added. RFR: http://mail.openjdk.java.net/pipermail/jdk-updates-dev/2020-July/003569.html webrev: http://cr.openjdk.java.net/~sgehwolf/webrevs/JDK-8250627/jdk11/01/webrev/
31-07-2020

URL: https://hg.openjdk.java.net/jdk/jdk/rev/c9ad4de69c32 User: sgehwolf Date: 2020-07-29 14:31:39 +0000
29-07-2020

RFR: http://mail.openjdk.java.net/pipermail/core-libs-dev/2020-July/067943.html
28-07-2020

Candidate webrev: http://cr.openjdk.java.net/~sgehwolf/webrevs/JDK-8250627/01/webrev/ Example usage: $ java -XX:+UseContainerSupport -XshowSettings:system -version Operating System Metrics: Provider: cgroupv1 Effective CPU Count: 8 CPU Period: 100000us CPU Quota: -1 CPU Shares: -1 List of Processors, 8 total: 0 1 2 3 4 5 6 7 List of Effective Processors, 8 total: 0 1 2 3 4 5 6 7 List of Memory Nodes, 1 total: 0 List of Available Memory Nodes, 1 total: 0 Memory Limit: Unlimited Memory Soft Limit: Unlimited Memory & Swap Limit: Unlimited openjdk version "16-internal" 2021-03-16 OpenJDK Runtime Environment (build 16-internal+0-adhoc.sgehwolf.openjdk-head-2) OpenJDK 64-Bit Server VM (build 16-internal+0-adhoc.sgehwolf.openjdk-head-2, mixed mode, sharing) $ java -XX:-UseContainerSupport -XshowSettings:system -version Operating System Metrics: No metrics available for this platform openjdk version "16-internal" 2021-03-16 OpenJDK Runtime Environment (build 16-internal+0-adhoc.sgehwolf.openjdk-head-2) OpenJDK 64-Bit Server VM (build 16-internal+0-adhoc.sgehwolf.openjdk-head-2, mixed mode, sharing)
27-07-2020

See: http://mail.openjdk.java.net/pipermail/core-libs-dev/2020-July/067906.html
27-07-2020