Skip to content

Commit

Permalink
libmem: add ZoneAvailable.
Browse files Browse the repository at this point in the history
Add ZoneAvailable to return the amount of available/allocatable
memory in a zone, capped by the amount of free memory in any of
the ancestors of a zone.

Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Nov 11, 2024
1 parent f0856b2 commit 57708c8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/resmgr/lib/memory/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func (a *Allocator) ZoneFree(zone NodeMask) int64 {
return a.zoneFree(zone & a.masks.nodes.hasMemory)
}

// ZoneAvailable returns the amount of available memory in the zone.
func (a *Allocator) ZoneAvailable(zone NodeMask) int64 {
return a.zoneAvailable(zone & a.masks.nodes.hasMemory)
}

// ZoneNumUsers returns the number of requests assigned to the zone.
func (a *Allocator) ZoneNumUsers(zone NodeMask) int {
if z, ok := a.zones[zone]; ok {
Expand Down Expand Up @@ -154,6 +159,28 @@ func (a *Allocator) zoneFree(zone NodeMask) int64 {
return a.zoneCapacity(zone) - a.zoneUsage(zone)
}

func (a *Allocator) zoneAvailable(zone NodeMask) int64 {
available := a.zoneFree(zone)
if available <= 0 {
return 0
}

// Cap available amount to the smallest available free in any of our ancestors.
for _, z := range a.zones {
if z.nodes != zone && (z.nodes&zone) == zone {
if free := a.zoneFree(z.nodes); free < available {
available = free
}
}
if available <= 0 {
available = 0
break
}
}

return available
}

func (a *Allocator) zoneAssign(zone NodeMask, req *Request) {
z, ok := a.zones[zone]
if !ok {
Expand Down

0 comments on commit 57708c8

Please sign in to comment.