美文网首页
koordinator 资源限制源码

koordinator 资源限制源码

作者: wwq2020 | 来源:发表于2022-04-07 12:46 被阅读0次

    资源限制入口pkg/koordlet/resmanager/cpu_suppress.go中

    func (r *CPUSuppress) suppressBECPU() {
      ...
        if nodeSLO.Spec.ResourceUsedThresholdWithBE.CPUSuppressPolicy == slov1alpha1.CPUCfsQuotaPolicy {
            adjustByCfsQuota(suppressCPUQuantity, node)
            r.suppressPolicyStatuses[string(slov1alpha1.CPUCfsQuotaPolicy)] = policyUsing
            r.recoverCPUSetIfNeed()
        } else {
            adjustByCPUSet(suppressCPUQuantity, nodeCPUInfo)
            r.suppressPolicyStatuses[string(slov1alpha1.CPUSetPolicy)] = policyUsing
            r.recoverCFSQuotaIfNeed()
        }
      ...
    }
    

    拿cfsquota举例pkg/koordlet/resmanager/cpu_suppress.go中

    func adjustByCfsQuota(cpuQuantity *resource.Quantity, node *corev1.Node) {
      ...
        if err := sysutil.CgroupFileWrite(beCgroupPath, sysutil.CPUCFSQuota, strconv.FormatInt(newBeQuota, 10)); err != nil {
            klog.Errorf("suppressBECPU: failed to write cfs_quota_us for offline pods, error: %v", err)
            return
        }
      ...
    }
    

    其实最终的操作就是写入相应的值到/sys/fs/cgroup/cpu/kubepods.slice/kubepods-besteffort.slice/cpu.cfs_quota_us这个文件中
    由于
    1cgroup是层级的,子cgroup会继承父cgroup
    2 所有的best effort pod都在此目录下
    因此可以限制best effort pod的总cpu开销

    相关文章

      网友评论

          本文标题:koordinator 资源限制源码

          本文链接:https://www.haomeiwen.com/subject/qxnjsrtx.html