Skip to content

Commit

Permalink
fix: cpu should be preferred if numa policy is restricted
Browse files Browse the repository at this point in the history
  • Loading branch information
KunWuLuan committed May 7, 2024
1 parent 038308b commit eab1fa5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pkg/scheduler/plugins/nodenumaresource/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
corehelper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/scheduler/framework"

apiext "github.com/koordinator-sh/koordinator/apis/extension"
schedulingconfig "github.com/koordinator-sh/koordinator/pkg/scheduler/apis/config"
"github.com/koordinator-sh/koordinator/pkg/scheduler/frameworkext/topologymanager"
"github.com/koordinator-sh/koordinator/pkg/util"
Expand All @@ -39,7 +40,7 @@ import (
)

type ResourceManager interface {
GetTopologyHints(node *corev1.Node, pod *corev1.Pod, options *ResourceOptions) (map[string][]topologymanager.NUMATopologyHint, error)
GetTopologyHints(node *corev1.Node, pod *corev1.Pod, options *ResourceOptions, policy apiext.NUMATopologyPolicy) (map[string][]topologymanager.NUMATopologyHint, error)
Allocate(node *corev1.Node, pod *corev1.Pod, options *ResourceOptions) (*PodAllocation, error)

Update(nodeName string, allocation *PodAllocation)
Expand Down Expand Up @@ -120,7 +121,7 @@ func (c *resourceManager) getOrCreateNodeAllocation(nodeName string) *NodeAlloca
return v
}

func (c *resourceManager) GetTopologyHints(node *corev1.Node, pod *corev1.Pod, options *ResourceOptions) (map[string][]topologymanager.NUMATopologyHint, error) {
func (c *resourceManager) GetTopologyHints(node *corev1.Node, pod *corev1.Pod, options *ResourceOptions, policy apiext.NUMATopologyPolicy) (map[string][]topologymanager.NUMATopologyHint, error) {
topologyOptions := options.topologyOptions
if len(topologyOptions.NUMANodeResources) == 0 {
return nil, fmt.Errorf("insufficient resources on NUMA Node")
Expand All @@ -134,7 +135,7 @@ func (c *resourceManager) GetTopologyHints(node *corev1.Node, pod *corev1.Pod, o
return nil, err
}

hints := generateResourceHints(topologyOptions.NUMANodeResources, options.requests, totalAvailable, options.numaScorer)
hints := generateResourceHints(topologyOptions.NUMANodeResources, options.requests, totalAvailable, options.numaScorer, policy)
return hints, nil
}

Expand Down Expand Up @@ -456,7 +457,7 @@ func (c *resourceManager) getAvailableNUMANodeResources(nodeName string, topolog
return totalAvailable, totalAllocated, nil
}

func generateResourceHints(numaNodeResources []NUMANodeResource, podRequests corev1.ResourceList, totalAvailable map[int]corev1.ResourceList, numaScorer *resourceAllocationScorer) map[string][]topologymanager.NUMATopologyHint {
func generateResourceHints(numaNodeResources []NUMANodeResource, podRequests corev1.ResourceList, totalAvailable map[int]corev1.ResourceList, numaScorer *resourceAllocationScorer, policy apiext.NUMATopologyPolicy) map[string][]topologymanager.NUMATopologyHint {
var resourceNamesByNUMA []corev1.ResourceName
for _, numaNodeResource := range numaNodeResources {
resourceNamesByNUMA = append(resourceNamesByNUMA, quotav1.ResourceNames(numaNodeResource.Resources)...)
Expand Down Expand Up @@ -528,7 +529,7 @@ func generateResourceHints(numaNodeResources []NUMANodeResource, podRequests cor
for resourceName := range podRequests {
minAffinitySize := generator.minAffinitySize[resourceName]
for i, hint := range generator.hints[string(resourceName)] {
generator.hints[string(resourceName)][i].Preferred = len(hint.NUMANodeAffinity.GetBits()) == minAffinitySize
generator.hints[string(resourceName)][i].Preferred = len(hint.NUMANodeAffinity.GetBits()) == minAffinitySize || policy == apiext.NUMATopologyPolicyRestricted
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/nodenumaresource/topology_hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *Plugin) GetPodTopologyHints(ctx context.Context, cycleState *framework.
return nil, framework.AsStatus(err)
}
resourceOptions.numaScorer = p.numaScorer
hints, err := p.resourceManager.GetTopologyHints(node, pod, resourceOptions)
hints, err := p.resourceManager.GetTopologyHints(node, pod, resourceOptions, topologyOptions.NUMATopologyPolicy)
if err != nil {
return nil, framework.NewStatus(framework.Unschedulable, "node(s) Insufficient NUMA Node resources")
}
Expand Down

0 comments on commit eab1fa5

Please sign in to comment.