mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(region,host,scheduler): scheduler support allocate cpu numa pin (#20932)
This commit is contained in:
@@ -62,6 +62,10 @@ func (p *ClassMetadataPredicate) Clone() core.FitPredicate {
|
||||
|
||||
func (p *ClassMetadataPredicate) PreExecute(ctx context.Context, u *core.Unit, cs []core.Candidater) (bool, error) {
|
||||
info := u.SchedData()
|
||||
if info.ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
tenant, err := db.TenantCacheManager.FetchTenantById(ctx, info.Project)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "unable to fetch tenant %s", info.Project)
|
||||
|
||||
@@ -48,6 +48,9 @@ func (p *CloudproviderSchedtagPredicate) PreExecute(ctx context.Context, u *core
|
||||
if driver == nil || !driver.DoScheduleCloudproviderTagFilter() {
|
||||
return false, nil
|
||||
}
|
||||
if u.SchedData().ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
return p.ServerBaseSchedtagPredicate.PreExecute(ctx, u, cs)
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ func (f *ImagePredicate) Clone() core.FitPredicate {
|
||||
}
|
||||
|
||||
func (f *ImagePredicate) PreExecute(ctx context.Context, u *core.Unit, cs []core.Candidater) (bool, error) {
|
||||
if u.SchedData().ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
disks := u.SchedData().Disks
|
||||
if len(disks) == 0 {
|
||||
return false, nil
|
||||
|
||||
@@ -16,7 +16,11 @@ package guest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/scheduler"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/algorithm/predicates"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core"
|
||||
)
|
||||
@@ -64,6 +68,40 @@ func (p *MemoryPredicate) Execute(ctx context.Context, u *core.Unit, c core.Cand
|
||||
h.AppendInsufficientResourceError(reqMemSize, totalMemSize, freeMemSize)
|
||||
}
|
||||
|
||||
if cpuNumaFree := getter.GetFreeCpuNuma(); cpuNumaFree != nil {
|
||||
allcateEnough := false
|
||||
reqCpuCount := d.Ncpu
|
||||
if d.CpuNumaPin != nil {
|
||||
nodeCount := len(d.CpuNumaPin)
|
||||
if scheduler.NodesFreeCpuEnough(nodeCount, d.Ncpu, cpuNumaFree) &&
|
||||
scheduler.NodesFreeMemSizeEnough(nodeCount, int(reqMemSize), cpuNumaFree) {
|
||||
allcateEnough = true
|
||||
}
|
||||
} else {
|
||||
for nodeCount := 1; nodeCount <= len(cpuNumaFree); nodeCount *= 2 {
|
||||
if nodeCount > reqCpuCount {
|
||||
break
|
||||
}
|
||||
|
||||
if !scheduler.NodesFreeCpuEnough(nodeCount, d.Ncpu, cpuNumaFree) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !scheduler.NodesFreeMemSizeEnough(nodeCount, int(reqMemSize), cpuNumaFree) {
|
||||
continue
|
||||
}
|
||||
allcateEnough = true
|
||||
}
|
||||
}
|
||||
|
||||
if !allcateEnough {
|
||||
h.AppendPredicateFailMsg(
|
||||
fmt.Sprintf("cpu numa free %s can't alloc with req mem %v req cpu %v ",
|
||||
jsonutils.Marshal(cpuNumaFree).String(), d.Memory, d.Ncpu),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
h.SetCapacity(freeMemSize / reqMemSize)
|
||||
return h.GetResult()
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ func (p *MigratePredicate) Clone() core.FitPredicate {
|
||||
}
|
||||
|
||||
func (p *MigratePredicate) PreExecute(ctx context.Context, u *core.Unit, cs []core.Candidater) (bool, error) {
|
||||
if u.SchedData().ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return len(u.SchedData().HostId) > 0, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,10 @@ func (p *StoragePredicate) PreExecute(ctx context.Context, u *core.Unit, cs []co
|
||||
if driver != nil && !driver.DoScheduleStorageFilter() {
|
||||
return false, nil
|
||||
}
|
||||
if u.SchedData().ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,11 @@ func (f *IsolatedDevicePredicate) Clone() core.FitPredicate {
|
||||
|
||||
func (f *IsolatedDevicePredicate) PreExecute(ctx context.Context, u *core.Unit, cs []core.Candidater) (bool, error) {
|
||||
data := u.SchedData()
|
||||
|
||||
if data.ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if len(data.IsolatedDevices) > 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -75,6 +75,11 @@ type INetworkNicCountGetter interface {
|
||||
|
||||
func (p *NetworkPredicate) PreExecute(ctx context.Context, u *core.Unit, cs []core.Candidater) (bool, error) {
|
||||
data := u.SchedData()
|
||||
|
||||
if data.ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if len(data.Networks) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -417,6 +417,10 @@ func (p *BaseSchedtagPredicate) PreExecute(ctx context.Context, sp ISchedtagPred
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if u.SchedData().ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
p.Hypervisor = u.GetHypervisor()
|
||||
p.Provider = u.SchedInfo.Provider
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ func (p *InstanceTypePredicate) Clone() core.FitPredicate {
|
||||
|
||||
func (p *InstanceTypePredicate) PreExecute(ctx context.Context, u *core.Unit, cs []core.Candidater) (bool, error) {
|
||||
driver := u.GetHypervisorDriver()
|
||||
if u.SchedData().ResetCpuNumaPin {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if u.SchedData().InstanceType == "" || (driver == nil || !driver.DoScheduleSKUFilter()) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user