JDK-8197589 : Update CPU count algorithm when both cpu shares and quotas are used
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 10
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2018-02-12
  • Updated: 2019-06-20
  • Resolved: 2018-02-23
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
11 b03Fixed
Related Reports
CSR :  
Relates :  
Description
JDK 10 included an enhancement (https://bugs.openjdk.java.net/browse/JDK-8146115) which allowed the JVM to determine the number of processors it should use based on information extracted from the Linux cgroup file system. The algorithm used to select the number of processors was:

min(cpu shares, cpu quota/cpu period, physical cpus) *

*if cpu shares or quotas were not specified or configured, they are not included in the calculation.

This algorithm assumed that developers would select either cpu shares or quotas and not both. There are popular use cases (Kubernetes) which use both cpu shares and cpu quotas in order to provide a minimum to maximum range of cpu resource limits. Since our formula always selects the minimum, we were potentially underutilizing the host system cpu resources.

The solution is to alter the formula to provide two modes when both cpu shares and quotas are set. If the flag PreferContainerQuotaForCPUCount is set to true, take the cpu quota value, if provided, without exceeding the number of physical cpus on the system. If the flag PreferContainerQuotaForCPUCount is false, use the minimum of cpu shares or cpu quotas, if set, without exceeding the number of physical cpus in the system. If only one of cpu shares or cpu quotas is provided, then use the specified value limited by the number of physical processors in the system.

Comments
Synopsis and proposed solution updated.
22-02-2018

I dispute that the count is "wrong". The algorithm allowed for both to be set and selects the minimum - which was perfectly reasonable given they are both a form of limit on expected CPU usage. If someone want this to instead select the maximum then that is not obviously more correct than what was initially done. If we need to account for both then we need a way for the user to determine how to interpret things when both shares and quotas are specified and are different.
13-02-2018