java如何绑核_pod绑核规则

pod绑核是按照container来绑定的,如果一个pod有多个container对于不同的container会区别对待。

// kubernetes/pkg/kubelet/cm/cpumanager/policy_static.go

func (p *staticPolicy) AddContainer(s state.State, pod *v1.Pod, container *v1.Container, containerID string) (rerr error) {

// So long as this function does not return an error,

// add (pod, container, containerID) to the containerMap.

defer func() {

if rerr == nil {

p.containerMap.Add(pod, container, containerID)

}

}()

if numCPUs := p.guaranteedCPUs(pod, container); numCPUs != 0 {

klog.Infof("[cpumanager] static policy: AddContainer (pod: %s, container: %s, container id: %s)", pod.Name, container.Name, containerID)

// container belongs in an exclusively allocated pool

if _, ok := s.GetCPUSet(containerID); ok {

klog.Infof("[cpumanager] static policy: container already present in state, skipping (container: %s, container id: %s)", container.Name, containerID)

return nil

}

// Proactively remove CPUs from init containers that have already run.

// They are guaranteed to have run to completion before any other

// container is run.

for _, initContainer := range pod.Spec.InitContainers {

if container.Name != initContainer.Name {

initContainerID, err := p.containerMap.Get(pod, &initContainer)

if err != nil {

continue

}

err = p.RemoveContainer(s, initContainerID)

if err != nil {

klog.Warningf("[cpumanager] unable to remove init container (container id: %s, error: %v)", initContainerID, err)

}

}

}

// Call Topology Manager to get the aligned socket affinity across all hint providers.

hint := p.affinity.GetAffinity(string(pod.UID), container.Name)

klog.Infof("[cpumanager] Pod %v, Container %v Topology Affinity is: %v", pod.UID, container.Name, hint)

// Allocate CPUs according to the NUMA affinity contained in the hint.

cpuset, err := p.allocateCPUs(s, numCPUs, hint.NUMANodeAffinity)

if err != nil {

klog.Errorf("[cpumanager] unable to allocate %d CPUs (container id: %s, error: %v)", numCPUs, containerID, err)

return err

}

s.SetCPUSet(containerID, cpuset)

}

// container belongs in the shared pool (nothing to do; use default cpuset)

return nil

}

func (p *staticPolicy) guaranteedCPUs(pod *v1.Pod, container *v1.Container) int {

if v1qos.GetPodQOS(pod) != v1.PodQOSGuaranteed {

return 0

}

cpuQuantity := container.Resources.Requests[v1.ResourceCPU]

if cpuQuantity.Value()*1000 != cpuQuantity.MilliValue() {

return 0

}

// Safe downcast to do for all systems with < 2.1 billion CPUs.

// Per the language spec, `int` is guaranteed to be at least 32 bits wide.

// https://golang.org/ref/spec#Numeric_types

return int(cpuQuantity.Value())

}

其中guaranteedCPUs代表了绑核规则的判断。

1.pod必须是Guaranteed级别的

2.container的cpu必须是整数核的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值