Skip to content

Commit

Permalink
scheduler: fix that cpu should be preferred if numa policy is restric…
Browse files Browse the repository at this point in the history
…ted (#2033)

Signed-off-by: KunWuLuan <kunwuluan@gmail.com>
  • Loading branch information
KunWuLuan committed May 8, 2024
1 parent 877d8fb commit fb33c30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ func TestResourceManagerGetTopologyHint(t *testing.T) {
}
assert.NoError(t, amplifyNUMANodeResources(node, &tt.options.topologyOptions))

got, err := resourceManager.GetTopologyHints(node, tt.pod, tt.options)
got, err := resourceManager.GetTopologyHints(node, tt.pod, tt.options, apiext.NUMATopologyPolicyBestEffort)
if tt.wantErr != (err != nil) {
t.Errorf("wantErr %v but got %v", tt.wantErr, err != nil)
}
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 fb33c30

Please sign in to comment.