mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #60263 from tossmilestone/reuse-minNodes
Automatic merge from submit-queue (batch tested with PRs 60106, 59510, 60263, 60063, 59088). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Reuse the `min*Nodes` slices in order to save GC time **What this PR does / why we need it**: Reuse the `min*Nodes` slices to save GC time when executing `pickOneNodeForPreemption`. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #59748 **Special notes for your reviewer**: **Release note**: ```release-note None ```
This commit is contained in:
commit
49a1478839
@ -675,13 +675,15 @@ func EqualPriorityMap(_ *v1.Pod, _ interface{}, nodeInfo *schedulercache.NodeInf
|
|||||||
// 3. Ties are broken by sum of priorities of all victims.
|
// 3. Ties are broken by sum of priorities of all victims.
|
||||||
// 4. If there are still ties, node with the minimum number of victims is picked.
|
// 4. If there are still ties, node with the minimum number of victims is picked.
|
||||||
// 5. If there are still ties, the first such node is picked (sort of randomly).
|
// 5. If there are still ties, the first such node is picked (sort of randomly).
|
||||||
//TODO(bsalamat): Try to reuse the "min*Nodes" slices in order to save GC time.
|
// The 'minNodes1' and 'minNodes2' are being reused here to save the memory
|
||||||
|
// allocation and garbage collection time.
|
||||||
func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*Victims) *v1.Node {
|
func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*Victims) *v1.Node {
|
||||||
if len(nodesToVictims) == 0 {
|
if len(nodesToVictims) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
minNumPDBViolatingPods := math.MaxInt32
|
minNumPDBViolatingPods := math.MaxInt32
|
||||||
var minPDBViolatingNodes []*v1.Node
|
var minNodes1 []*v1.Node
|
||||||
|
lenNodes1 := 0
|
||||||
for node, victims := range nodesToVictims {
|
for node, victims := range nodesToVictims {
|
||||||
if len(victims.pods) == 0 {
|
if len(victims.pods) == 0 {
|
||||||
// We found a node that doesn't need any preemption. Return it!
|
// We found a node that doesn't need any preemption. Return it!
|
||||||
@ -693,42 +695,48 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*Victims) *v1.Node {
|
|||||||
numPDBViolatingPods := victims.numPDBViolations
|
numPDBViolatingPods := victims.numPDBViolations
|
||||||
if numPDBViolatingPods < minNumPDBViolatingPods {
|
if numPDBViolatingPods < minNumPDBViolatingPods {
|
||||||
minNumPDBViolatingPods = numPDBViolatingPods
|
minNumPDBViolatingPods = numPDBViolatingPods
|
||||||
minPDBViolatingNodes = nil
|
minNodes1 = nil
|
||||||
|
lenNodes1 = 0
|
||||||
}
|
}
|
||||||
if numPDBViolatingPods == minNumPDBViolatingPods {
|
if numPDBViolatingPods == minNumPDBViolatingPods {
|
||||||
minPDBViolatingNodes = append(minPDBViolatingNodes, node)
|
minNodes1 = append(minNodes1, node)
|
||||||
|
lenNodes1++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(minPDBViolatingNodes) == 1 {
|
if lenNodes1 == 1 {
|
||||||
return minPDBViolatingNodes[0]
|
return minNodes1[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// There are more than one node with minimum number PDB violating pods. Find
|
// There are more than one node with minimum number PDB violating pods. Find
|
||||||
// the one with minimum highest priority victim.
|
// the one with minimum highest priority victim.
|
||||||
minHighestPriority := int32(math.MaxInt32)
|
minHighestPriority := int32(math.MaxInt32)
|
||||||
var minPriorityNodes []*v1.Node
|
var minNodes2 = make([]*v1.Node, lenNodes1)
|
||||||
for _, node := range minPDBViolatingNodes {
|
lenNodes2 := 0
|
||||||
|
for i := 0; i < lenNodes1; i++ {
|
||||||
|
node := minNodes1[i]
|
||||||
victims := nodesToVictims[node]
|
victims := nodesToVictims[node]
|
||||||
// highestPodPriority is the highest priority among the victims on this node.
|
// highestPodPriority is the highest priority among the victims on this node.
|
||||||
highestPodPriority := util.GetPodPriority(victims.pods[0])
|
highestPodPriority := util.GetPodPriority(victims.pods[0])
|
||||||
if highestPodPriority < minHighestPriority {
|
if highestPodPriority < minHighestPriority {
|
||||||
minHighestPriority = highestPodPriority
|
minHighestPriority = highestPodPriority
|
||||||
minPriorityNodes = nil
|
lenNodes2 = 0
|
||||||
}
|
}
|
||||||
if highestPodPriority == minHighestPriority {
|
if highestPodPriority == minHighestPriority {
|
||||||
minPriorityNodes = append(minPriorityNodes, node)
|
minNodes2[lenNodes2] = node
|
||||||
|
lenNodes2++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(minPriorityNodes) == 1 {
|
if lenNodes2 == 1 {
|
||||||
return minPriorityNodes[0]
|
return minNodes2[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// There are a few nodes with minimum highest priority victim. Find the
|
// There are a few nodes with minimum highest priority victim. Find the
|
||||||
// smallest sum of priorities.
|
// smallest sum of priorities.
|
||||||
minSumPriorities := int64(math.MaxInt64)
|
minSumPriorities := int64(math.MaxInt64)
|
||||||
var minSumPriorityNodes []*v1.Node
|
lenNodes1 = 0
|
||||||
for _, node := range minPriorityNodes {
|
for i := 0; i < lenNodes2; i++ {
|
||||||
var sumPriorities int64
|
var sumPriorities int64
|
||||||
|
node := minNodes2[i]
|
||||||
for _, pod := range nodesToVictims[node].pods {
|
for _, pod := range nodesToVictims[node].pods {
|
||||||
// We add MaxInt32+1 to all priorities to make all of them >= 0. This is
|
// We add MaxInt32+1 to all priorities to make all of them >= 0. This is
|
||||||
// needed so that a node with a few pods with negative priority is not
|
// needed so that a node with a few pods with negative priority is not
|
||||||
@ -738,34 +746,37 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*Victims) *v1.Node {
|
|||||||
}
|
}
|
||||||
if sumPriorities < minSumPriorities {
|
if sumPriorities < minSumPriorities {
|
||||||
minSumPriorities = sumPriorities
|
minSumPriorities = sumPriorities
|
||||||
minSumPriorityNodes = nil
|
lenNodes1 = 0
|
||||||
}
|
}
|
||||||
if sumPriorities == minSumPriorities {
|
if sumPriorities == minSumPriorities {
|
||||||
minSumPriorityNodes = append(minSumPriorityNodes, node)
|
minNodes1[lenNodes1] = node
|
||||||
|
lenNodes1++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(minSumPriorityNodes) == 1 {
|
if lenNodes1 == 1 {
|
||||||
return minSumPriorityNodes[0]
|
return minNodes1[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// There are a few nodes with minimum highest priority victim and sum of priorities.
|
// There are a few nodes with minimum highest priority victim and sum of priorities.
|
||||||
// Find one with the minimum number of pods.
|
// Find one with the minimum number of pods.
|
||||||
minNumPods := math.MaxInt32
|
minNumPods := math.MaxInt32
|
||||||
var minNumPodNodes []*v1.Node
|
lenNodes2 = 0
|
||||||
for _, node := range minSumPriorityNodes {
|
for i := 0; i < lenNodes1; i++ {
|
||||||
|
node := minNodes1[i]
|
||||||
numPods := len(nodesToVictims[node].pods)
|
numPods := len(nodesToVictims[node].pods)
|
||||||
if numPods < minNumPods {
|
if numPods < minNumPods {
|
||||||
minNumPods = numPods
|
minNumPods = numPods
|
||||||
minNumPodNodes = nil
|
lenNodes2 = 0
|
||||||
}
|
}
|
||||||
if numPods == minNumPods {
|
if numPods == minNumPods {
|
||||||
minNumPodNodes = append(minNumPodNodes, node)
|
minNodes2[lenNodes2] = node
|
||||||
|
lenNodes2++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// At this point, even if there are more than one node with the same score,
|
// At this point, even if there are more than one node with the same score,
|
||||||
// return the first one.
|
// return the first one.
|
||||||
if len(minNumPodNodes) > 0 {
|
if lenNodes2 > 0 {
|
||||||
return minNumPodNodes[0]
|
return minNodes2[0]
|
||||||
}
|
}
|
||||||
glog.Errorf("Error in logic of node scoring for preemption. We should never reach here!")
|
glog.Errorf("Error in logic of node scoring for preemption. We should never reach here!")
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user