Fix cpu share issues on systems with large amounts of cpu
On systems where the calculated cpu shares results in a value above the max value in linux, containers getting that value are unable to start. This occur on systems with 300+ cpu cores, and where containers are given such a value. This issue was fixed for the pod and qos control groups in the similar cm.MilliCPUToShares that also has tests verifying the behavior. Since this code already has an dependency on kubelet/cm, lets reuse that code instead.
This commit is contained in:
parent
e4c795168b
commit
de0ece541c
@ -20,9 +20,6 @@ limitations under the License.
|
|||||||
package kuberuntime
|
package kuberuntime
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc
|
|
||||||
minShares = 2
|
|
||||||
sharesPerCPU = 1024
|
|
||||||
milliCPUToCPU = 1000
|
milliCPUToCPU = 1000
|
||||||
|
|
||||||
// 100000 is equivalent to 100ms
|
// 100000 is equivalent to 100ms
|
||||||
@ -30,20 +27,6 @@ const (
|
|||||||
minQuotaPeriod = 1000
|
minQuotaPeriod = 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
// milliCPUToShares converts milliCPU to CPU shares
|
|
||||||
func milliCPUToShares(milliCPU int64) int64 {
|
|
||||||
if milliCPU == 0 {
|
|
||||||
// Return 2 here to really match kernel default for zero milliCPU.
|
|
||||||
return minShares
|
|
||||||
}
|
|
||||||
// Conceptually (milliCPU / milliCPUToCPU) * sharesPerCPU, but factored to improve rounding.
|
|
||||||
shares := (milliCPU * sharesPerCPU) / milliCPUToCPU
|
|
||||||
if shares < minShares {
|
|
||||||
return minShares
|
|
||||||
}
|
|
||||||
return shares
|
|
||||||
}
|
|
||||||
|
|
||||||
// milliCPUToQuota converts milliCPU to CFS quota and period values
|
// milliCPUToQuota converts milliCPU to CFS quota and period values
|
||||||
func milliCPUToQuota(milliCPU int64, period int64) (quota int64) {
|
func milliCPUToQuota(milliCPU int64, period int64) (quota int64) {
|
||||||
// CFS quota is measured in two values:
|
// CFS quota is measured in two values:
|
||||||
|
@ -18,8 +18,3 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package kuberuntime
|
package kuberuntime
|
||||||
|
|
||||||
// milliCPUToShares converts milliCPU to CPU shares
|
|
||||||
func milliCPUToShares(milliCPU int64) int64 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
@ -139,11 +139,11 @@ func (m *kubeGenericRuntimeManager) calculateLinuxResources(cpuRequest, cpuLimit
|
|||||||
// API server does this for new containers, but we repeat this logic in Kubelet
|
// API server does this for new containers, but we repeat this logic in Kubelet
|
||||||
// for containers running on existing Kubernetes clusters.
|
// for containers running on existing Kubernetes clusters.
|
||||||
if cpuRequest.IsZero() && !cpuLimit.IsZero() {
|
if cpuRequest.IsZero() && !cpuLimit.IsZero() {
|
||||||
cpuShares = milliCPUToShares(cpuLimit.MilliValue())
|
cpuShares = int64(cm.MilliCPUToShares(cpuLimit.MilliValue()))
|
||||||
} else {
|
} else {
|
||||||
// if cpuRequest.Amount is nil, then milliCPUToShares will return the minimal number
|
// if cpuRequest.Amount is nil, then MilliCPUToShares will return the minimal number
|
||||||
// of CPU shares.
|
// of CPU shares.
|
||||||
cpuShares = milliCPUToShares(cpuRequest.MilliValue())
|
cpuShares = int64(cm.MilliCPUToShares(cpuRequest.MilliValue()))
|
||||||
}
|
}
|
||||||
resources.CpuShares = cpuShares
|
resources.CpuShares = cpuShares
|
||||||
if memLimit != 0 {
|
if memLimit != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user