Skip to content

Commit a5a70b4

Browse files
authored
Merge pull request kubernetes#74859 from ahadas/static_policy
kubelet/cm: code optimization for the static policy
2 parents 0230664 + 4a47148 commit a5a70b4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkg/kubelet/cm/cpumanager/cpu_assignment.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,31 @@ func takeByTopology(topo *topology.CPUTopology, availableCPUs cpuset.CPUSet, num
158158
// Algorithm: topology-aware best-fit
159159
// 1. Acquire whole sockets, if available and the container requires at
160160
// least a socket's-worth of CPUs.
161-
for _, s := range acc.freeSockets() {
162-
if acc.needs(acc.topo.CPUsPerSocket()) {
161+
if acc.needs(acc.topo.CPUsPerSocket()) {
162+
for _, s := range acc.freeSockets() {
163163
klog.V(4).Infof("[cpumanager] takeByTopology: claiming socket [%d]", s)
164164
acc.take(acc.details.CPUsInSocket(s))
165165
if acc.isSatisfied() {
166166
return acc.result, nil
167167
}
168+
if !acc.needs(acc.topo.CPUsPerSocket()) {
169+
break
170+
}
168171
}
169172
}
170173

171174
// 2. Acquire whole cores, if available and the container requires at least
172175
// a core's-worth of CPUs.
173-
for _, c := range acc.freeCores() {
174-
if acc.needs(acc.topo.CPUsPerCore()) {
176+
if acc.needs(acc.topo.CPUsPerCore()) {
177+
for _, c := range acc.freeCores() {
175178
klog.V(4).Infof("[cpumanager] takeByTopology: claiming core [%d]", c)
176179
acc.take(acc.details.CPUsInCore(c))
177180
if acc.isSatisfied() {
178181
return acc.result, nil
179182
}
183+
if !acc.needs(acc.topo.CPUsPerCore()) {
184+
break
185+
}
180186
}
181187
}
182188

pkg/kubelet/cm/cpumanager/cpu_assignment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func TestTakeByTopology(t *testing.T) {
356356
cpuset.NewCPUSet(2, 6),
357357
},
358358
{
359-
"take three cpus from dual socket with HT - core from Socket 0",
359+
"take one cpu from dual socket with HT - core from Socket 0",
360360
topoDualSocketHT,
361361
cpuset.NewCPUSet(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
362362
1,

0 commit comments

Comments
 (0)