Skip to content

Commit

Permalink
core: release CPUs
Browse files Browse the repository at this point in the history
When we allocate CPUs we are basing upon the list we return back. This
is correct for the scheduling phase. But now we run the same logic on
canSchedule. There, when having a group of VMs, we are basing on the
cpuTopology list, not the list we selected to allocate. The overtaken
CPU wasn't released from the pinning itself and that harmed the
canSchedule logic for VM groups.

Also, when grouping the VMs, when the group is having an affinity set,
it is reordered. Therefore, it is required to sort them there as well.

Change-Id: Idcae90fed953c4798f2c4bf8893bff0a1b7086ea
Signed-off-by: Liran Rotenberg <lrotenbe@redhat.com>
  • Loading branch information
liranr23 committed Jun 19, 2022
1 parent 513d016 commit e4f2d2d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ private List<List<VM>> groupVms(List<VM> vms, SchedulingContext context) {
// Create individual VmGroups for the rest of VMs that are not in affinity groups
vmsById.values().forEach(vm -> vmGroups.add(Collections.singletonList(vm)));

vmGroups.forEach(vmGroup -> vmGroup.sort(new VmsCpuPinningPolicyComparator().reversed()));

return vmGroups;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public List<VdsCpuUnit> allocateManualCpus(List<VdsCpuUnit> cpuTopology, VM vm)
}

private List<VdsCpuUnit> allocateDedicatedCpus(List<VdsCpuUnit> cpuTopology, VM vm, Guid hostId) {
// We can assume that a valid pinning exists here (because the host was filtered beforehand).
List<VdsCpuUnit> cpusToBeAllocated = new ArrayList<>();
int socketsLeft = vm.getNumOfSockets();
int onlineSockets = getOnlineSockets(cpuTopology).size();
Expand Down Expand Up @@ -197,7 +196,8 @@ private List<VdsCpuUnit> allocateDedicatedCpus(List<VdsCpuUnit> cpuTopology, VM
int coresReminder = coreCount % vm.getCpuPerSocket();
for (int i = 0; i < coresReminder * vm.getThreadsPerCpu(); i++) {
if (!cpusToBeAllocated.isEmpty()) {
cpusToBeAllocated.remove(cpusToBeAllocated.size() - 1);
VdsCpuUnit releasedCpu = cpusToBeAllocated.remove(cpusToBeAllocated.size() - 1);
releasedCpu.unPinVm(vm.getId());
}
}

Expand Down

0 comments on commit e4f2d2d

Please sign in to comment.