From 26e1c1cee7de030d229a9bb67f2e1e045b2964b9 Mon Sep 17 00:00:00 2001 From: Arik Hadas Date: Thu, 28 Feb 2019 18:48:07 +0200 Subject: [PATCH 1/2] kubelet/cm: code optimization for the static policy Minor optimization in the code that attempts to assign whole sockets/cores in case the number of CPUs requested is higher than CPUs-per-socket/core: check if the number of requested CPUs is higher than CPUs-per-socket/core before retrieving and iterating the free sockets/cores, and break the loops when that is no longer the case. Signed-off-by: Arik Hadas --- pkg/kubelet/cm/cpumanager/cpu_assignment.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/cm/cpumanager/cpu_assignment.go b/pkg/kubelet/cm/cpumanager/cpu_assignment.go index be6babab14..09d2a5c72f 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_assignment.go +++ b/pkg/kubelet/cm/cpumanager/cpu_assignment.go @@ -158,25 +158,31 @@ func takeByTopology(topo *topology.CPUTopology, availableCPUs cpuset.CPUSet, num // Algorithm: topology-aware best-fit // 1. Acquire whole sockets, if available and the container requires at // least a socket's-worth of CPUs. - for _, s := range acc.freeSockets() { - if acc.needs(acc.topo.CPUsPerSocket()) { + if acc.needs(acc.topo.CPUsPerSocket()) { + for _, s := range acc.freeSockets() { klog.V(4).Infof("[cpumanager] takeByTopology: claiming socket [%d]", s) acc.take(acc.details.CPUsInSocket(s)) if acc.isSatisfied() { return acc.result, nil } + if !acc.needs(acc.topo.CPUsPerSocket()) { + break + } } } // 2. Acquire whole cores, if available and the container requires at least // a core's-worth of CPUs. - for _, c := range acc.freeCores() { - if acc.needs(acc.topo.CPUsPerCore()) { + if acc.needs(acc.topo.CPUsPerCore()) { + for _, c := range acc.freeCores() { klog.V(4).Infof("[cpumanager] takeByTopology: claiming core [%d]", c) acc.take(acc.details.CPUsInCore(c)) if acc.isSatisfied() { return acc.result, nil } + if !acc.needs(acc.topo.CPUsPerCore()) { + break + } } } From 4a47148afe58ec5d0eed9a2b8870a5ba22613e30 Mon Sep 17 00:00:00 2001 From: Arik Hadas Date: Thu, 7 Mar 2019 21:22:34 +0200 Subject: [PATCH 2/2] kubelet/cm: fix test description Signed-off-by: Arik Hadas --- pkg/kubelet/cm/cpumanager/cpu_assignment_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go b/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go index cf2a972c0a..2b2b04e7b2 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go +++ b/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go @@ -356,7 +356,7 @@ func TestTakeByTopology(t *testing.T) { cpuset.NewCPUSet(2, 6), }, { - "take three cpus from dual socket with HT - core from Socket 0", + "take one cpu from dual socket with HT - core from Socket 0", topoDualSocketHT, cpuset.NewCPUSet(1, 2, 3, 4, 5, 7, 8, 9, 10, 11), 1,