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: optimize numa affinity store #2209

Merged
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
6 changes: 6 additions & 0 deletions pkg/scheduler/frameworkext/framework_extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
koordinatorclientset "github.com/koordinator-sh/koordinator/pkg/client/clientset/versioned"
koordinatorinformers "github.com/koordinator-sh/koordinator/pkg/client/informers/externalversions"
"github.com/koordinator-sh/koordinator/pkg/features"
"github.com/koordinator-sh/koordinator/pkg/scheduler/frameworkext/schedulingphase"
"github.com/koordinator-sh/koordinator/pkg/scheduler/frameworkext/topologymanager"
reservationutil "github.com/koordinator-sh/koordinator/pkg/util/reservation"
)
Expand Down Expand Up @@ -249,6 +250,11 @@ func (ext *frameworkExtenderImpl) RunScorePlugins(ctx context.Context, state *fr
return pluginToNodeScores, status
}

func (ext *frameworkExtenderImpl) RunPostFilterPlugins(ctx context.Context, state *framework.CycleState, pod *corev1.Pod, filteredNodeStatusMap framework.NodeToStatusMap) (_ *framework.PostFilterResult, status *framework.Status) {
schedulingphase.RecordPhase(state, schedulingphase.PostFilter)
return ext.Framework.RunPostFilterPlugins(ctx, state, pod, filteredNodeStatusMap)
}

// RunPreBindPlugins supports PreBindReservation for Reservation
func (ext *frameworkExtenderImpl) RunPreBindPlugins(ctx context.Context, state *framework.CycleState, pod *corev1.Pod, nodeName string) *framework.Status {
if !reservationutil.IsReservePod(pod) {
Expand Down
53 changes: 53 additions & 0 deletions pkg/scheduler/frameworkext/schedulingphase/scheduling_phase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2022 The Koordinator Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package schedulingphase

import (
"k8s.io/kubernetes/pkg/scheduler/framework"

"github.com/koordinator-sh/koordinator/apis/extension"
)

const (
phaseStateKey = extension.SchedulingDomainPrefix + "/scheduling-phase"
)

const (
PostFilter = "PostFilter"
)

type SchedulingPhase struct {
extensionPoint string
}

func (s *SchedulingPhase) Clone() framework.StateData {
return s
}

func RecordPhase(cycleState *framework.CycleState, extensionPoint string) {
cycleState.Write(phaseStateKey, &SchedulingPhase{
extensionPoint: PostFilter,
})
}

func GetExtensionPointBeingExecuted(cycleState *framework.CycleState) string {
s, err := cycleState.Read(phaseStateKey)
if err != nil || s == nil {
return ""
}
return s.(*SchedulingPhase).extensionPoint
}
18 changes: 13 additions & 5 deletions pkg/scheduler/frameworkext/topologymanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework"

apiext "github.com/koordinator-sh/koordinator/apis/extension"
"github.com/koordinator-sh/koordinator/pkg/scheduler/frameworkext/schedulingphase"
)

type Interface interface {
Expand Down Expand Up @@ -64,18 +65,25 @@ func (m *topologyManager) Admit(ctx context.Context, cycleState *framework.Cycle

policy := createNUMATopologyPolicy(policyType, numaNodes)
bestHint, ok := store.GetAffinity(nodeName)
if !ok {
extensionPointBeingExecuted := schedulingphase.GetExtensionPointBeingExecuted(cycleState)
klog.V(5).Infof("extensionPointBeingExecuted: %v, bestHint: %v, nodeName: %v, pod: %v", extensionPointBeingExecuted, bestHint, nodeName, pod.Name)
if !ok || extensionPointBeingExecuted == schedulingphase.PostFilter {
var admit bool
bestHint, admit = m.calculateAffinity(ctx, cycleState, policy, pod, nodeName, exclusivePolicy, allNUMANodeStatus)
klog.V(5).Infof("Best TopologyHint for (pod: %v): %v on node: %v", klog.KObj(pod), bestHint, nodeName)
if !admit {
return framework.NewStatus(framework.Unschedulable, "node(s) NUMA Topology affinity error")
}
status := m.allocateResources(ctx, cycleState, bestHint, pod, nodeName)
if !status.IsSuccess() {
return status
}
store.SetAffinity(nodeName, bestHint)
}
status := m.allocateResources(ctx, cycleState, bestHint, pod, nodeName)
if !status.IsSuccess() {
return status
} else {
status := m.allocateResources(ctx, cycleState, bestHint, pod, nodeName)
if !status.IsSuccess() {
return status
}
}
return nil
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/scheduler/frameworkext/topologymanager/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ func GetStore(cycleState *framework.CycleState) *Store {
}

func (s *Store) Clone() framework.StateData {
ss := &Store{}
s.affinityMap.Range(func(key, value any) bool {
ss.affinityMap.Store(key, value)
return true
})
return ss
return s
}

func (s *Store) SetAffinity(nodeName string, affinity NUMATopologyHint) {
Expand Down