mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Make mergePermutation generic:
- Remove policy parameters to make function generic - Move function into top level policy.go
This commit is contained in:
parent
5487941485
commit
2d1a535a35
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package topologymanager
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask"
|
||||
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
||||
)
|
||||
|
||||
@ -29,6 +30,36 @@ type Policy interface {
|
||||
Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult)
|
||||
}
|
||||
|
||||
// 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
|
||||
// are preferred.
|
||||
func mergePermutation(numaNodes []int, permutation []TopologyHint) TopologyHint {
|
||||
// Get the NUMANodeAffinity from each hint in the permutation and see if any
|
||||
// of them encode unpreferred allocations.
|
||||
defaultAffinity, _ := bitmask.NewBitMask(numaNodes...)
|
||||
preferred := true
|
||||
var numaAffinities []bitmask.BitMask
|
||||
for _, hint := range permutation {
|
||||
// Only consider hints that have an actual NUMANodeAffinity set.
|
||||
if hint.NUMANodeAffinity == nil {
|
||||
numaAffinities = append(numaAffinities, defaultAffinity)
|
||||
} else {
|
||||
numaAffinities = append(numaAffinities, hint.NUMANodeAffinity)
|
||||
}
|
||||
|
||||
if !hint.Preferred {
|
||||
preferred = false
|
||||
}
|
||||
}
|
||||
|
||||
// Merge the affinities using a bitwise-and operation.
|
||||
mergedAffinity, _ := bitmask.NewBitMask(numaNodes...)
|
||||
mergedAffinity.And(numaAffinities...)
|
||||
// Build a mergedHint from the merged affinity mask, indicating if an
|
||||
// preferred allocation was used to generate the affinity mask or not.
|
||||
return TopologyHint{mergedAffinity, preferred}
|
||||
}
|
||||
|
||||
// Iterate over all permutations of hints in 'allProviderHints [][]TopologyHint'.
|
||||
//
|
||||
// This procedure is implemented as a recursive function over the set of hints
|
||||
|
@ -53,36 +53,6 @@ func (p *bestEffortPolicy) Merge(providersHints []map[string][]TopologyHint) (To
|
||||
return hint, admit
|
||||
}
|
||||
|
||||
// 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
|
||||
// are preferred.
|
||||
func (p *bestEffortPolicy) mergePermutation(permutation []TopologyHint) TopologyHint {
|
||||
// Get the NUMANodeAffinity from each hint in the permutation and see if any
|
||||
// of them encode unpreferred allocations.
|
||||
defaultAffinity, _ := bitmask.NewBitMask(p.numaNodes...)
|
||||
preferred := true
|
||||
var numaAffinities []bitmask.BitMask
|
||||
for _, hint := range permutation {
|
||||
// Only consider hints that have an actual NUMANodeAffinity set.
|
||||
if hint.NUMANodeAffinity == nil {
|
||||
numaAffinities = append(numaAffinities, defaultAffinity)
|
||||
} else {
|
||||
numaAffinities = append(numaAffinities, hint.NUMANodeAffinity)
|
||||
}
|
||||
|
||||
if !hint.Preferred {
|
||||
preferred = false
|
||||
}
|
||||
}
|
||||
|
||||
// Merge the affinities using a bitwise-and operation.
|
||||
mergedAffinity, _ := bitmask.NewBitMask(p.numaNodes...)
|
||||
mergedAffinity.And(numaAffinities...)
|
||||
// Build a mergedHint from the merged affinity mask, indicating if an
|
||||
// preferred allocation was used to generate the affinity mask or not.
|
||||
return TopologyHint{mergedAffinity, preferred}
|
||||
}
|
||||
|
||||
// Merge the hints from all hint providers to find the best one.
|
||||
func (p *bestEffortPolicy) mergeProvidersHints(providersHints []map[string][]TopologyHint) TopologyHint {
|
||||
// Set the default affinity as an any-numa affinity containing the list
|
||||
@ -128,7 +98,7 @@ func (p *bestEffortPolicy) mergeProvidersHints(providersHints []map[string][]Top
|
||||
iterateAllProviderTopologyHints(allProviderHints, func(permutation []TopologyHint) {
|
||||
// Get the NUMANodeAffinity from each hint in the permutation and see if any
|
||||
// of them encode unpreferred allocations.
|
||||
mergedHint := p.mergePermutation(permutation)
|
||||
mergedHint := mergePermutation(p.numaNodes, permutation)
|
||||
|
||||
// Only consider mergedHints that result in a NUMANodeAffinity > 0 to
|
||||
// replace the current bestHint.
|
||||
|
@ -54,23 +54,6 @@ func (p *singleNumaNodePolicy) canAdmitPodResult(hint *TopologyHint) lifecycle.P
|
||||
}
|
||||
}
|
||||
|
||||
// Merge a TopologyHints permutation to a single hint by performing a bitwise-AND
|
||||
// of their affinity masks. At this point, all hints have single numa node affinity
|
||||
// and preferred-true.
|
||||
func (p *singleNumaNodePolicy) mergePermutation(permutation []TopologyHint) TopologyHint {
|
||||
preferred := true
|
||||
var numaAffinities []bitmask.BitMask
|
||||
for _, hint := range permutation {
|
||||
numaAffinities = append(numaAffinities, hint.NUMANodeAffinity)
|
||||
}
|
||||
|
||||
// Merge the affinities using a bitwise-and operation.
|
||||
mergedAffinity, _ := bitmask.NewBitMask(p.numaNodes...)
|
||||
mergedAffinity.And(numaAffinities...)
|
||||
// Build a mergedHint from the merged affinity mask.
|
||||
return TopologyHint{mergedAffinity, preferred}
|
||||
}
|
||||
|
||||
// Return hints that have valid bitmasks with exactly one bit set.
|
||||
func (p *singleNumaNodePolicy) filterHints(allResourcesHints [][]TopologyHint) [][]TopologyHint {
|
||||
var filteredResourcesHints [][]TopologyHint
|
||||
@ -145,7 +128,7 @@ func (p *singleNumaNodePolicy) mergeProvidersHints(providersHints []map[string][
|
||||
defaultAffinity, _ := bitmask.NewBitMask(p.numaNodes...)
|
||||
bestHint := TopologyHint{defaultAffinity, false}
|
||||
iterateAllProviderTopologyHints(allResourcesHints, func(permutation []TopologyHint) {
|
||||
mergedHint := p.mergePermutation(permutation)
|
||||
mergedHint := mergePermutation(p.numaNodes, permutation)
|
||||
// Only consider mergedHints that result in a NUMANodeAffinity == 1 to
|
||||
// replace the current defaultHint.
|
||||
if mergedHint.NUMANodeAffinity.Count() != 1 {
|
||||
|
Loading…
Reference in New Issue
Block a user