Skip to content

Commit 4ef44c3

Browse files
committed
Subject: [PATCH] balloons: preserve requested exact reserved cpuset across allocation
In hard-exact reserved CPU mode, the code passed the requested cpuset by pointer into AllocateCpus() and then compared/logged using the same variable afterwards. AllocateCpus() may mutate the preferred/requested cpuset argument while performing allocation. As a result, startup could fail with an error like: failed to allocate exact reserved cpuset: requested "", got "0-7,..." even though the configured reserved cpuset was correct and the allocator returned exactly that cpuset. Fix this by keeping an immutable copy of the requested exact cpuset for: - comparison after allocation - error reporting This keeps hard-exact startup from falsely failing due to mutation of the temporary cpuset variable.
1 parent 8013fa4 commit 4ef44c3

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

cmd/plugins/balloons/policy/balloons-policy.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,19 +1104,23 @@ func (p *balloons) newBalloon(blnDef *BalloonDef, confCpus bool) (*Balloon, erro
11041104
}
11051105
}
11061106
if p.reservedExact && blnDef.Name == reservedBalloonDefName {
1107-
exact := p.reserved.Clone()
1108-
if exact.Size() == 0 {
1107+
requested := p.reserved.Clone()
1108+
if requested.Size() == 0 {
11091109
return nil, balloonsError("reservedCPUMode=hard-exact requires non-empty reserved cpuset")
11101110
}
1111-
if exact.Difference(p.freeCpus).Size() > 0 {
1112-
return nil, balloonsError("reserved exact cpuset %q is not fully free, missing %q", exact, exact.Difference(p.freeCpus))
1111+
if requested.Difference(p.freeCpus).Size() > 0 {
1112+
return nil, balloonsError("reserved exact cpuset %q is not fully free, missing %q", requested, requested.Difference(p.freeCpus))
11131113
}
1114-
newCpus, err := p.cpuAllocator.AllocateCpus(&exact, exact.Size(), blnDef.AllocatorPriority.Value().Option())
1114+
// AllocateCpus() may mutate the preferred/requested cpuset argument.
1115+
// Keep an immutable copy for post-allocation validation and logging.
1116+
exact := requested.Clone()
1117+
newCpus, err := p.cpuAllocator.AllocateCpus(&exact, requested.Size(), blnDef.AllocatorPriority.Value().Option())
11151118
if err != nil {
1116-
return nil, balloonsError("failed to allocate exact reserved cpuset %q: %w", exact, err)
1119+
return nil, balloonsError("failed to allocate exact reserved cpuset %q: %w", requested, err)
11171120
}
1118-
if !newCpus.Equals(exact) {
1119-
return nil, balloonsError("failed to allocate exact reserved cpuset: requested %q, got %q", exact, newCpus)
1121+
if !newCpus.Equals(requested) {
1122+
return nil, balloonsError("failed to allocate exact reserved cpuset: requested %q, got %q", requested, newCpus)
1123+
11201124
}
11211125
p.freeCpus = p.freeCpus.Difference(newCpus)
11221126
bln.Cpus = newCpus

0 commit comments

Comments
 (0)