The hotspot implementation for this is done as part of JDK-8322420. However, we will need a similar fix to the Java implementation of the jdk.internal.platform classes on Linux to appropriately report the limits when they're not set on the leaf nodes:
# cat /sys/fs/cgroup/user.slice/user-cg.slice/user-cg-cpu.slice/run-rd82109f39ab843ff828c868d54a063f5.scope/memory.max
max
# cat /sys/fs/cgroup/user.slice/user-cg.slice/user-cg-cpu.slice/memory.max
max
# cat /sys/fs/cgroup/user.slice/user-cg.slice/memory.max
2097152000
# ./bin/java -XshowSettings:system --version
Operating System Metrics:
Provider: cgroupv2
Effective CPU Count: 2
CPU Period: -1
CPU Quota: -1
CPU Shares: -1
List of Processors: N/A
List of Effective Processors: N/A
List of Memory Nodes: N/A
List of Available Memory Nodes: N/A
Memory Limit: Unlimited
Memory Soft Limit: 0.00K
Memory & Swap Limit: Unlimited
Maximum Processes Limit: 31000
That is, the memory limit is set two levels up the hierarchy instead of the leaf node (/sys/fs/cgroup/user.slice/user-cg.slice/user-cg-cpu.slice/run-rd82109f39ab843ff828c868d54a063f5.scope/memory.max) and the system metrics don't list the limit correctly.
Expected:
Memory Limit: 2GB
Actual:
Memory Limit: Unlimited
This fix will depend on the hotspot fix, since the "-XshowSettings:system" output will (wrongly) show "System not containerized", since it thinks no limits are set. The fix in JDK-8322420 will alleviate this.
A real-world test will likely depend on the framework added in JDK-8333446 since container frameworks like docker/podman have the limits at the leaf node.