Skip to content

Commit

Permalink
cpuallocator: add PreferPartialSharedGroups flag.
Browse files Browse the repository at this point in the history
Add a PreferPartialSharedGroups flag to indicate the preference
to always try allocating partial cache groups from already used
ones, instead of partially using an idle group.
  • Loading branch information
klihub committed Dec 4, 2024
1 parent 331b1ec commit 1d8d968
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/cpuallocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const (
// AllocIdleCores requests allocation of full idle cores (all threads in core).
AllocIdleCores

// PreferPartialSharedGroups prefers using shared groups over splitting up idle
// groups for partial allocation.
PreferPartialSharedGroups

// AllocDefault is the default allocation preferences.
AllocDefault = AllocIdlePackages | AllocIdleClusters | AllocCacheGroups | AllocIdleCores

Expand Down Expand Up @@ -762,6 +766,11 @@ func (a *allocatorHelper) takeCacheGroups() {
continue
}

// if we have usable/non-idle groups and they are preferred, move on to them instead
if a.flags&PreferPartialSharedGroups != 0 && sorter.usableCPUCount() >= cnt {
break
}

// partially allocate the rest from this group
ta := newAllocatorHelper(a.sys, a.topology)
ta.prefer = a.prefer
Expand Down Expand Up @@ -1251,6 +1260,14 @@ func (s *cacheGroupSorter) usableDieCPUCount(pkg, die idset.ID) int {
return s.usableDie[pkg][die]
}

func (s *cacheGroupSorter) usableCPUCount() int {
cnt := 0
for _, g := range s.usable {
cnt += s.cpus[g].Size()
}
return cnt
}

func (s *cacheGroupSorter) CPUSet(g *cacheGroup) cpuset.CPUSet {
return s.cpus[g]
}
Expand Down

0 comments on commit 1d8d968

Please sign in to comment.