Skip to content

Commit

Permalink
scheduler: optimize numa affinity store
Browse files Browse the repository at this point in the history
Signed-off-by: wangjianyu.wjy <wangjianyu.wjy@alibaba-inc.com>
  • Loading branch information
wangjianyu.wjy committed Sep 19, 2024
1 parent cd6ce25 commit 27bc349
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
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
37 changes: 37 additions & 0 deletions pkg/scheduler/frameworkext/schedulingphase/scheduling_phase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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

0 comments on commit 27bc349

Please sign in to comment.