Skip to content

Commit

Permalink
Merge pull request kubernetes#29 from qbox/fix_overcommit_1.8
Browse files Browse the repository at this point in the history
Min shares of cpu is 2.
  • Loading branch information
cofyc authored May 21, 2018
2 parents b2441ce + 9bcb1cc commit bd39d07
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pkg/kubelet/cm/helpers_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ func HugePageLimits(resourceList v1.ResourceList) map[int64]int64 {
return hugePageLimits
}

func CPUSharesAfterCPUOvercommited(shares int64, ratio float64) int64 {
shares = int64(float64(shares) / ratio)
if shares < MinShares {
return MinShares
}
return shares
}

// ResourceConfigForPod takes the input pod and outputs the cgroup resource config.
func ResourceConfigForPod(pod *v1.Pod, cpuOvercommitRatio float64) *ResourceConfig {
// sum requests and limits.
Expand All @@ -121,7 +129,7 @@ func ResourceConfigForPod(pod *v1.Pod, cpuOvercommitRatio float64) *ResourceConf

// convert to CFS values
cpuShares := MilliCPUToShares(cpuRequests)
cpuShares = uint64(float64(cpuShares) / cpuOvercommitRatio)
cpuShares = CPUSharesAfterCPUOvercommited(cpuShares, cpuOvercommitRatio)
cpuQuota, cpuPeriod := MilliCPUToQuota(cpuLimits)

// track if limits were applied for each resource.
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/cm/qos_container_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (m *qosContainerManagerImpl) setCPUCgroupConfig(configs map[v1.PodQOSClass]
if burstableCPUShares < uint64(MinShares) {
burstableCPUShares = uint64(MinShares)
}
burstableCPUShares = uint64(float64(burstableCPUShares) / cpuOvercommitRatio)
burstableCPUShares = CPUSharesAfterCPUOvercommited(burstableCPUShares, cpuOvercommitRatio)
glog.V(4).Infof("[k8s.qiniu.com/cpu_overcommit_ratio]: burstableCPUShares: %v, ratio: %v", burstableCPUShares, cpuOvercommitRatio)
configs[v1.PodQOSBurstable].ResourceParameters.CpuShares = &burstableCPUShares
return nil
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubelet/kuberuntime/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ func milliCPUToShares(milliCPU int64) int64 {
return shares
}

func cpuSharesAfterCPUOvercommited(shares int64, ratio float64) int64 {
shares = int64(float64(shares) / ratio)
if shares < minShares {
return minShares
}
return shares
}

// milliCPUToQuota converts milliCPU to CFS quota and period values
func milliCPUToQuota(milliCPU int64) (quota int64, period int64) {
// CFS quota is measured in two values:
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/kuberuntime/kuberuntime_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (m *kubeGenericRuntimeManager) generateLinuxContainerConfig(container *v1.C
qosClass := v1qos.GetPodQOS(pod)
if qosClass == v1.PodQOSGuaranteed || qosClass == v1.PodQOSBurstable {
cpuOvercommitRatio := m.cpuOvercommitRatioGetter()
lc.Resources.CpuShares = int64(float64(cpuShares) / cpuOvercommitRatio)
lc.Resources.CpuShares = cpuSharesAfterCPUOvercommited(cpuShares, cpuOvercommitRatio)
glog.V(4).Infof("[k8s.qiniu.com/cpu_overcommit_ratio]: container %s/%s/%s cpu.shares old: %v, actual: %v, ratio: %v", pod.Namespace, pod.Name, container.Name, cpuShares, lc.Resources.CpuShares, cpuOvercommitRatio)
} else {
glog.V(4).Infof("[k8s.qiniu.com/cpu_overcommit_ratio]: container %s/%s/%s we only adjust cpu.shares for qos Guaranteed or Burstable", pod.Namespace, pod.Name, container.Name)
Expand Down

0 comments on commit bd39d07

Please sign in to comment.