Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions pkg/cache/tas_flavor_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,14 @@ func (s *TASFlavorSnapshot) findTopologyAssignment(
podSetNodeSelectors := info.NodeSelector
count := tasPodSetRequests.Count
required := isRequired(tasPodSetRequests.PodSet.TopologyRequest)
key := s.levelKeyWithImpliedFallback(&tasPodSetRequests)
topologyKey := s.levelKeyWithImpliedFallback(&tasPodSetRequests)
unconstrained := isUnconstrained(tasPodSetRequests.PodSet.TopologyRequest, &tasPodSetRequests)
if key == nil {
if topologyKey == nil {
return nil, "topology level not specified"
}
levelIdx, found := s.resolveLevelIdx(*key)
levelIdx, found := s.resolveLevelIdx(*topologyKey)
if !found {
return nil, fmt.Sprintf("no requested topology level: %s", *key)
return nil, fmt.Sprintf("no requested topology level: %s", *topologyKey)
}
var selector labels.Selector
if s.isLowestLevelNode() {
Expand Down Expand Up @@ -680,7 +680,7 @@ func isUnconstrained(tr *kueue.PodSetTopologyRequest, tasRequests *TASPodSetRequ
func findBestFitDomainIdx(domains []*domain, count int32) int {
bestFitIdx := 0
for i, domain := range domains {
if domain.state >= count && domain.state != domains[bestFitIdx].state {
if domain.state >= count && domain.state < domains[bestFitIdx].state {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous code relied on a fact that domains are in descending order, so "!=" works perfectly in finding the tightest fit. I'm just changing it to "<" to make it more explicit.

// choose the first occurrence of fitting domains
// to make it consecutive with other podSet's
bestFitIdx = i
Expand All @@ -689,38 +689,38 @@ func findBestFitDomainIdx(domains []*domain, count int32) int {
return bestFitIdx
}

func (s *TASFlavorSnapshot) findLevelWithFitDomains(levelIdx int, required bool, count int32, unconstrained bool) (int, []*domain, string) {
func (s *TASFlavorSnapshot) findLevelWithFitDomains(levelIdx int, required bool, podSetSize int32, unconstrained bool) (int, []*domain, string) {
domains := s.domainsPerLevel[levelIdx]
if len(domains) == 0 {
return 0, nil, fmt.Sprintf("no topology domains at level: %s", s.levelKeys[levelIdx])
}
levelDomains := slices.Collect(maps.Values(domains))
sortedDomain := s.sortedDomains(levelDomains, unconstrained)
topDomain := sortedDomain[0]
if useBestFitAlgorithm(unconstrained) && topDomain.state >= count {
if useBestFitAlgorithm(unconstrained) && topDomain.state >= podSetSize {
// optimize the potentially last domain
topDomain = sortedDomain[findBestFitDomainIdx(sortedDomain, count)]
topDomain = sortedDomain[findBestFitDomainIdx(sortedDomain, podSetSize)]
}
if topDomain.state < count {
if topDomain.state < podSetSize {
if required {
return 0, nil, s.notFitMessage(topDomain.state, count)
return 0, nil, s.notFitMessage(topDomain.state, podSetSize)
}
if levelIdx > 0 && !unconstrained {
return s.findLevelWithFitDomains(levelIdx-1, required, count, unconstrained)
return s.findLevelWithFitDomains(levelIdx-1, required, podSetSize, unconstrained)
}
results := []*domain{}
remainingCount := count
remainingCount := podSetSize
for idx := 0; remainingCount > 0 && idx < len(sortedDomain) && sortedDomain[idx].state > 0; idx++ {
offset := 0
if useBestFitAlgorithm(unconstrained) && sortedDomain[idx].state >= remainingCount {
// optimize the last domain
offset = findBestFitDomainIdx(sortedDomain[idx:], remainingCount)
}
results = append(results, sortedDomain[idx+offset])
remainingCount -= sortedDomain[idx].state
remainingCount -= sortedDomain[idx+offset].state
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code should subtract the chosen domain state from remainingCount. Old code subtracted not the chosen one, but next in line. It is the same for all domains, apart from the last one in BestFit. The old code worked ok, because remainingCount is a local variable, and we only care it is "not greater than 0" at the end of the function, so even if it was lower than 0 it was fine.

I'm fixing it to account for the optimized last domain correctly.

}
if remainingCount > 0 {
return 0, nil, s.notFitMessage(count-remainingCount, count)
return 0, nil, s.notFitMessage(podSetSize-remainingCount, podSetSize)
}
return levelIdx, results, ""
}
Expand Down