Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler: fix that cpu should be preferred if numa policy is restricted #2033

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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