JDK-8282684 : Obsolete UseContainerCpuShares and PreferContainerQuotaForCPUCount flags
Type:Enhancement
Component:hotspot
Sub-Component:runtime
Affected Version:20
Priority:P4
Status:Open
Resolution:Unresolved
Submitted:2022-03-04
Updated:2022-08-19
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.
These flags are deprecated in JDK 19 for JDK-8281181. They should be removed in JDK 20.
Comments
A pull request was submitted for review.
URL: https://git.openjdk.org/jdk/pull/9948
Date: 2022-08-19 18:41:12 +0000
19-08-2022
There is some code in the JDK, most importantly OperatingSystemMXBean, that uses cpu shares for it's load calculation:
https://github.com/openjdk/jdk/blob/720e751f35150251cab05bc9fca3add39daf70af/src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java#L92..L97
It reads:
long hostTicks = getHostTotalCpuTicks0();
int totalCPUs = getHostOnlineCpuCount0();
int containerCPUs = getAvailableProcessors();
// scale the total host load to the actual container cpus
hostTicks = hostTicks * containerCPUs / totalCPUs;
return getUsageDividesTotal(cpuUsageSupplier().getAsLong(), hostTicks);
After CPU Shares are removed from calculating the CPU cores within containers, getHostOnlineCpuCount0() and getAvailableProcessors() will return the same values (in all cases). Currently it doesn't when -XX:+UseContainerCpuShares is being used, which is going to go away with this bug. Once it does, this cpu shares case should get reworked in OperatingSystemImpl.java
See also: JDK-8283903