mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Make mergeProviderHints policy-specific:
- Remove need to pass policy and numaNodes as arguments - Remove PolicySingleNUMANode special case check in policy_best_effort - Add mergeProviderHints base to policy_single_numa_node for upcoming commit
This commit is contained in:
parent
dc36924c37
commit
eda1521562
@ -48,7 +48,7 @@ func (p *bestEffortPolicy) canAdmitPodResult(hint *TopologyHint) lifecycle.PodAd
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *bestEffortPolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
|
func (p *bestEffortPolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
|
||||||
hint := mergeProvidersHints(p, p.numaNodes, providersHints)
|
hint := p.mergeProvidersHints(providersHints)
|
||||||
admit := p.canAdmitPodResult(&hint)
|
admit := p.canAdmitPodResult(&hint)
|
||||||
return hint, admit
|
return hint, admit
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func (p *bestEffortPolicy) Merge(providersHints []map[string][]TopologyHint) (To
|
|||||||
// providerHints[-1][z]
|
// providerHints[-1][z]
|
||||||
// }
|
// }
|
||||||
// callback(permutation)
|
// callback(permutation)
|
||||||
func iterateAllProviderTopologyHints(allProviderHints [][]TopologyHint, callback func([]TopologyHint)) {
|
func (p *bestEffortPolicy) iterateAllProviderTopologyHints(allProviderHints [][]TopologyHint, callback func([]TopologyHint)) {
|
||||||
// Internal helper function to accumulate the permutation before calling the callback.
|
// Internal helper function to accumulate the permutation before calling the callback.
|
||||||
var iterate func(i int, accum []TopologyHint)
|
var iterate func(i int, accum []TopologyHint)
|
||||||
iterate = func(i int, accum []TopologyHint) {
|
iterate = func(i int, accum []TopologyHint) {
|
||||||
@ -94,10 +94,10 @@ func iterateAllProviderTopologyHints(allProviderHints [][]TopologyHint, callback
|
|||||||
// Merge a TopologyHints permutation to a single hint by performing a bitwise-AND
|
// Merge a TopologyHints permutation to a single hint by performing a bitwise-AND
|
||||||
// of their affinity masks. The hint shall be preferred if all hits in the permutation
|
// of their affinity masks. The hint shall be preferred if all hits in the permutation
|
||||||
// are preferred.
|
// are preferred.
|
||||||
func mergePermutation(policy Policy, numaNodes []int, permutation []TopologyHint) TopologyHint {
|
func (p *bestEffortPolicy) mergePermutation(permutation []TopologyHint) TopologyHint {
|
||||||
// Get the NUMANodeAffinity from each hint in the permutation and see if any
|
// Get the NUMANodeAffinity from each hint in the permutation and see if any
|
||||||
// of them encode unpreferred allocations.
|
// of them encode unpreferred allocations.
|
||||||
defaultAffinity, _ := bitmask.NewBitMask(numaNodes...)
|
defaultAffinity, _ := bitmask.NewBitMask(p.numaNodes...)
|
||||||
preferred := true
|
preferred := true
|
||||||
var numaAffinities []bitmask.BitMask
|
var numaAffinities []bitmask.BitMask
|
||||||
for _, hint := range permutation {
|
for _, hint := range permutation {
|
||||||
@ -111,17 +111,10 @@ func mergePermutation(policy Policy, numaNodes []int, permutation []TopologyHint
|
|||||||
if !hint.Preferred {
|
if !hint.Preferred {
|
||||||
preferred = false
|
preferred = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case PolicySingleNumaNode to only prefer hints where
|
|
||||||
// all providers have a single NUMA affinity set.
|
|
||||||
if policy != nil && policy.Name() == PolicySingleNumaNode && hint.NUMANodeAffinity != nil && hint.NUMANodeAffinity.Count() > 1 {
|
|
||||||
preferred = false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge the affinities using a bitwise-and operation.
|
// Merge the affinities using a bitwise-and operation.
|
||||||
mergedAffinity, _ := bitmask.NewBitMask(numaNodes...)
|
mergedAffinity, _ := bitmask.NewBitMask(p.numaNodes...)
|
||||||
mergedAffinity.And(numaAffinities...)
|
mergedAffinity.And(numaAffinities...)
|
||||||
// Build a mergedHint from the merged affinity mask, indicating if an
|
// Build a mergedHint from the merged affinity mask, indicating if an
|
||||||
// preferred allocation was used to generate the affinity mask or not.
|
// preferred allocation was used to generate the affinity mask or not.
|
||||||
@ -129,10 +122,10 @@ func mergePermutation(policy Policy, numaNodes []int, permutation []TopologyHint
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merge the hints from all hint providers to find the best one.
|
// Merge the hints from all hint providers to find the best one.
|
||||||
func mergeProvidersHints(policy Policy, numaNodes []int, providersHints []map[string][]TopologyHint) TopologyHint {
|
func (p *bestEffortPolicy) mergeProvidersHints(providersHints []map[string][]TopologyHint) TopologyHint {
|
||||||
// Set the default affinity as an any-numa affinity containing the list
|
// Set the default affinity as an any-numa affinity containing the list
|
||||||
// of NUMA Nodes available on this machine.
|
// of NUMA Nodes available on this machine.
|
||||||
defaultAffinity, _ := bitmask.NewBitMask(numaNodes...)
|
defaultAffinity, _ := bitmask.NewBitMask(p.numaNodes...)
|
||||||
|
|
||||||
// Loop through all hint providers and save an accumulated list of the
|
// Loop through all hint providers and save an accumulated list of the
|
||||||
// hints returned by each hint provider. If no hints are provided, assume
|
// hints returned by each hint provider. If no hints are provided, assume
|
||||||
@ -170,10 +163,10 @@ func mergeProvidersHints(policy Policy, numaNodes []int, providersHints []map[st
|
|||||||
// permutations that have at least one NUMA ID set. If no merged mask can be
|
// permutations that have at least one NUMA ID set. If no merged mask can be
|
||||||
// found that has at least one NUMA ID set, return the 'defaultAffinity'.
|
// found that has at least one NUMA ID set, return the 'defaultAffinity'.
|
||||||
bestHint := TopologyHint{defaultAffinity, false}
|
bestHint := TopologyHint{defaultAffinity, false}
|
||||||
iterateAllProviderTopologyHints(allProviderHints, func(permutation []TopologyHint) {
|
p.iterateAllProviderTopologyHints(allProviderHints, func(permutation []TopologyHint) {
|
||||||
// Get the NUMANodeAffinity from each hint in the permutation and see if any
|
// Get the NUMANodeAffinity from each hint in the permutation and see if any
|
||||||
// of them encode unpreferred allocations.
|
// of them encode unpreferred allocations.
|
||||||
mergedHint := mergePermutation(policy, numaNodes, permutation)
|
mergedHint := p.mergePermutation(permutation)
|
||||||
|
|
||||||
// Only consider mergedHints that result in a NUMANodeAffinity > 0 to
|
// Only consider mergedHints that result in a NUMANodeAffinity > 0 to
|
||||||
// replace the current bestHint.
|
// replace the current bestHint.
|
||||||
|
@ -52,7 +52,7 @@ func (p *restrictedPolicy) canAdmitPodResult(hint *TopologyHint) lifecycle.PodAd
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *restrictedPolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
|
func (p *restrictedPolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
|
||||||
hint := mergeProvidersHints(p, p.numaNodes, providersHints)
|
hint := p.mergeProvidersHints(providersHints)
|
||||||
admit := p.canAdmitPodResult(&hint)
|
admit := p.canAdmitPodResult(&hint)
|
||||||
return hint, admit
|
return hint, admit
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package topologymanager
|
package topologymanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,8 +53,17 @@ func (p *singleNumaNodePolicy) canAdmitPodResult(hint *TopologyHint) lifecycle.P
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *singleNumaNodePolicy) mergeProvidersHints(providersHints []map[string][]TopologyHint) TopologyHint {
|
||||||
|
// Set the default hint to return from this function as an any-NUMANode
|
||||||
|
// affinity with an unpreferred allocation. This will only be returned if
|
||||||
|
// no better hint can be found when merging hints from each hint provider.
|
||||||
|
defaultAffinity, _ := bitmask.NewBitMask(p.numaNodes...)
|
||||||
|
defaultHint := TopologyHint{defaultAffinity, false}
|
||||||
|
return defaultHint
|
||||||
|
}
|
||||||
|
|
||||||
func (p *singleNumaNodePolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
|
func (p *singleNumaNodePolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
|
||||||
hint := mergeProvidersHints(p, p.numaNodes, providersHints)
|
hint := p.mergeProvidersHints(providersHints)
|
||||||
admit := p.canAdmitPodResult(&hint)
|
admit := p.canAdmitPodResult(&hint)
|
||||||
return hint, admit
|
return hint, admit
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user