mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region,scheduler): allow req cpu count zero on allocate cpunumapin (#21345)
This commit is contained in:
@@ -1476,7 +1476,10 @@ func (self *SGuest) StartGueststartTask(
|
||||
|
||||
if self.CpuNumaPin != nil {
|
||||
// clean cpu numa pin
|
||||
self.SetCpuNumaPin(ctx, userCred, nil, nil)
|
||||
err := self.SetCpuNumaPin(ctx, userCred, nil, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "clean cpu numa pin")
|
||||
}
|
||||
}
|
||||
|
||||
if schedStart {
|
||||
@@ -1509,6 +1512,18 @@ func (self *SGuest) GuestNonSchedStartTask(
|
||||
if self.BackupHostId != "" {
|
||||
taskName = "HAGuestStartTask"
|
||||
}
|
||||
if self.CpuNumaPin != nil {
|
||||
srcSchedCpuNumaPin := make([]schedapi.SCpuNumaPin, 0)
|
||||
err := self.CpuNumaPin.Unmarshal(&srcSchedCpuNumaPin)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unmarshal cpu_numa_pin")
|
||||
}
|
||||
// set cpu numa pin
|
||||
err = self.SetCpuNumaPin(ctx, userCred, srcSchedCpuNumaPin, nil)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, taskName, self, userCred, data, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1295,11 +1295,14 @@ func (guest *SGuest) SetCpuNumaPin(
|
||||
SizeMB: schedCpuNumaPin[i].MemSizeMB,
|
||||
NodeId: schedCpuNumaPin[i].NodeId,
|
||||
}
|
||||
cpuNumaPin[i].VcpuPin = make([]api.SVCpuPin, len(schedCpuNumaPin[i].CpuPin))
|
||||
for j := range schedCpuNumaPin[i].CpuPin {
|
||||
cpuNumaPin[i].VcpuPin[j].Pcpu = schedCpuNumaPin[i].CpuPin[j]
|
||||
cpuNumaPin[i].VcpuPin[j].Vcpu = vcpuId
|
||||
vcpuId += 1
|
||||
|
||||
if len(schedCpuNumaPin[i].CpuPin) > 0 {
|
||||
cpuNumaPin[i].VcpuPin = make([]api.SVCpuPin, len(schedCpuNumaPin[i].CpuPin))
|
||||
for j := range schedCpuNumaPin[i].CpuPin {
|
||||
cpuNumaPin[i].VcpuPin[j].Pcpu = schedCpuNumaPin[i].CpuPin[j]
|
||||
cpuNumaPin[i].VcpuPin[j].Vcpu = vcpuId
|
||||
vcpuId += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +263,10 @@ func (task *GuestChangeConfigTask) OnGuestChangeCpuMemSpecComplete(ctx context.C
|
||||
cpuNumaPinSched := make([]schedapi.SCpuNumaPin, 0)
|
||||
task.Params.Unmarshal(&cpuNumaPinSched, "cpu_numa_pin")
|
||||
cpuNumaPinTarget := make([]api.SCpuNumaPin, 0)
|
||||
data.Unmarshal(&cpuNumaPinTarget, "cpu_numa_pin")
|
||||
if data.Contains("cpu_numa_pin") {
|
||||
data.Unmarshal(&cpuNumaPinTarget, "cpu_numa_pin")
|
||||
}
|
||||
|
||||
err = guest.UpdateCpuNumaPin(ctx, task.UserCred, cpuNumaPinSched, cpuNumaPinTarget)
|
||||
if err != nil {
|
||||
task.markStageFailed(ctx, guest, jsonutils.NewString(fmt.Sprintf("Update cpu numa pin fail %s", err)))
|
||||
|
||||
@@ -69,7 +69,6 @@ func (p *MemoryPredicate) Execute(ctx context.Context, u *core.Unit, c core.Cand
|
||||
|
||||
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) &&
|
||||
@@ -78,10 +77,6 @@ func (p *MemoryPredicate) Execute(ctx context.Context, u *core.Unit, c core.Cand
|
||||
}
|
||||
} else {
|
||||
for nodeCount := 1; nodeCount <= len(cpuNumaFree); nodeCount *= 2 {
|
||||
if nodeCount > reqCpuCount {
|
||||
break
|
||||
}
|
||||
|
||||
if !scheduler.NodesFreeCpuEnough(nodeCount, d.Ncpu, cpuNumaFree) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -43,11 +43,6 @@ func (p *CpuNumaPinPriority) Map(u *core.Unit, c core.Candidater) (core.HostPrio
|
||||
reqMemSize := u.SchedInfo.Memory
|
||||
nodeCount := 1
|
||||
for ; nodeCount <= len(cpuNumaFree); nodeCount *= 2 {
|
||||
if nodeCount > reqCpuCount {
|
||||
nodeCount = 0
|
||||
break
|
||||
}
|
||||
|
||||
if scheduler.NodesFreeCpuEnough(nodeCount, reqCpuCount, cpuNumaFree) &&
|
||||
scheduler.NodesFreeMemSizeEnough(nodeCount, int(reqMemSize), cpuNumaFree) {
|
||||
break
|
||||
|
||||
+4
-3
@@ -324,6 +324,10 @@ func (n *NumaNode) allocCpuset(vcpuCount int, usedCpu map[int]int) {
|
||||
}
|
||||
|
||||
func (n *NumaNode) AllocCpuset(vcpuCount int) []int {
|
||||
if vcpuCount <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var usedCpuCount = make(map[int]int)
|
||||
n.allocCpuset(vcpuCount, usedCpuCount)
|
||||
|
||||
@@ -472,9 +476,6 @@ func (h *SHostTopo) nodesEnough(nodeCount, vcpuCount int, memSizeKB int) bool {
|
||||
func (h *SHostTopo) AllocCpuNumaNodes(vcpuCount, memSizeKB int) []scheduler.SCpuNumaPin {
|
||||
res := make([]scheduler.SCpuNumaPin, 0)
|
||||
for nodeCount := 1; nodeCount <= len(h.Nodes); nodeCount *= 2 {
|
||||
if nodeCount > vcpuCount {
|
||||
break
|
||||
}
|
||||
if ok := h.nodesEnough(nodeCount, vcpuCount, memSizeKB); !ok {
|
||||
log.Infof("node count %d not enough", nodeCount)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user