libmem

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package libmem implements a simple memory accounting and allocation scheme for resource management policy plugins. The primary interface to libmem is the Allocator type.

Allocator, Nodes

Allocator is set up with one or more nodes. A node usually corresponds to an actual NUMA node in the system. It has some amount of associated memory. That memory has some known memory type, ordinary DRAM memory, high-capacity non-volatile/persistent PMEM memory, or high-bandwidth HBM memory. A node comes with a vector of distances which describe the cost of moving memory from the node to other nodes. A node also might have an associated set of CPU cores which are considered to be close topologically to the node's memory.

Memory Zones, Allocation Requests

Allocator divides memory into zones. A memory zone is simply a set of one or more memory nodes. Memory is allocated using requests. Each request has an affinity and a type preference. Affinity states which zone the allocated memory should be close to and in the simplest case it is the set of nodes from which memory is allocated from. The type preference indicates which type or types of memory should be allocated. A type preference can be strict, in which case failing to satisfy the preference results in a failed allocation. The request also has an Priority. This tells the allocator how eagerly it can / easily it should move the allocation to other memory zones later, if some zone runs out of memory due to subsequent allocations.

Allocation Algorithm, Initial Zone Selection

Allocation starts by finding an initial zone for the request. This zone is the closest zone that satisfies the type preferences of the request and has at least one node with normal memory (as opposed to movable memory). Note that for non-strict requests this zone might not have all the preferred types.

Allocation Algorithm, Overcommit Handling

Once the initial zone is found, Allocator checks if any memory zone is oversubscribed or IOW is in the danger of running out of memory. A zone is considered oversubscribed if the total size of allocations that fit into the zone exceeds the total amount of memory available in the nodes of the zone. An allocation is said to fit into a zone if it is assigned to (IOW satisfied using) the zone, or another zone with a subset of the nodes of the first zone. For instance, allocations with assigned zones {0}, {2}, and {0, 2}, fully fit into {0, 1, 2, 3}, while zones {0, 4}, {2, 5}, or {0, 2, 4, 5} do not.

If any zone is oversubscribed, an overcommit handling algorithm kicks in to reduce memory usage in overcommitted nodes. Memory usage is reduced by moving allocations from the zone to a new one with a superset of nodes of the original zone. An expansion algorithm using node affinity, types and distance vectors is used to determine the superset zone. Overcommit handling prefers moving allocations with lower priority first. Allocation fails if the overcommit handler cannot resolve all overcommit.

Customizing an Allocator

Allocator can be customized in multiple ways. The simplest but most limited is to set up the Allocator with a curated set of node distance vectors. Since node expansion looks at the distance vectors to decide how to expand a zone, by altering the distance vector one can change the the order and set of new nodes considered during zone expansion.

Another more involved but direct and more flexible way to customize an Allocator is to explicitly set it up with custom functions for node expansion and/or overcommit resolution. These custom functions are called whenever node expansion is necessary (initial zone selection, overcommit resolution), or when oversubscription has been detected. These custom functions get access to the built-in default implementations. Often this allows implementing exception style extra handling just for cases of special interest but otherwise rely on the default implementations.

Allocation Offers

It is sometimes necessary or desirable to compare multiple allocation alternatives, especially ones with different memory affinity, before making a final allocation decision. Often this decision is based on how well a possible allocation aligns with resources from other domains, for instance with CPU cores, GPUs, or other devices.

libmem provides memory offers for this. An offer captures all details necessary to make a memory allocation without actually updating the Allocators state with those details. Multiple parallel offers can be queried at any time. An offer, but only a single offer, can then be turned into an allocation by committing it, once the best allocation alternative has been determined.

Index

Constants

View Source
const (
	// ForeachDone as a return value terminates iteration by a Foreach* function.
	ForeachDone = false
	// ForeachMore as a return value continues iteration by a Foreach* function.
	ForeachMore = !ForeachDone
)
View Source
const (
	// MaxNodeID is the maximum node ID that can be stored in a NodeMask.
	MaxNodeID = 63
)

Variables

View Source
var (
	ErrFailedOption    = fmt.Errorf("libmem: failed to apply option")
	ErrInvalidType     = fmt.Errorf("libmem: invalid type")
	ErrInvalidNode     = fmt.Errorf("libmem: invalid node")
	ErrInvalidNodeMask = fmt.Errorf("libmem: invalid NodeMask")
	ErrInvalidQosClass = fmt.Errorf("libmem: invalid QoS class")
	ErrExpiredOffer    = fmt.Errorf("libmem: expired offer")
	ErrUnknownRequest  = fmt.Errorf("libmem: unknown allocation")
	ErrAlreadyExists   = fmt.Errorf("libmem: allocation already exists")
	ErrNoMem           = fmt.Errorf("libmem: insufficient available memory")
	ErrNoZone          = fmt.Errorf("libmem: failed to find zone")
	ErrInternalError   = fmt.Errorf("libmem: internal error")
)

Functions

func HumanReadableSize

func HumanReadableSize(size int64) string

HumanReadableSize returns the given size as a human-readable string.

func NewID

func NewID() string

NewID returns a new internally generated ID. It is used to give default IDs for memory reservations in case one is not provided by the caller.

func RequestsByAge

func RequestsByAge(r1, r2 *Request) int

RequestsByAge compares requests by increasing age.

func RequestsByPriority

func RequestsByPriority(r1, r2 *Request) int

RequestsByPriority compares requests by increasing priority.

func RequestsBySize

func RequestsBySize(r1, r2 *Request) int

RequestsBySize compares requests by increasing size.

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

Allocator implements a topology aware but largely policy agnostic scheme for memory accounting and allocation.

func NewAllocator

func NewAllocator(options ...AllocatorOption) (*Allocator, error)

NewAllocator creates a new allocator instance and configures it with the given options.

func (*Allocator) Allocate

func (a *Allocator) Allocate(req *Request) (NodeMask, map[string]NodeMask, error)

Allocate allocates memory for the given request. It is equivalent to committing an acquired offer for the request. Allocate returns the nodes used to satisfy the request, together with any updates made to other existing allocations to fulfill the request. The caller must ensure these updates are properly enforced.

func (*Allocator) AssignedZone

func (a *Allocator) AssignedZone(id string) (NodeMask, bool)

AssignedZone returns the assigned nodes for the given allocation and whether such an allocation was found.

func (*Allocator) CPUSetAffinity

func (a *Allocator) CPUSetAffinity(cpus cpuset.CPUSet) NodeMask

CPUSetAffinity returns the mask of closest nodes for the given cpuset.

func (*Allocator) DumpConfig

func (a *Allocator) DumpConfig(context ...interface{})

func (*Allocator) DumpNodes

func (a *Allocator) DumpNodes(context ...interface{})

func (*Allocator) DumpRequests

func (a *Allocator) DumpRequests(context ...interface{})

func (*Allocator) DumpState

func (a *Allocator) DumpState(context ...interface{})

func (*Allocator) DumpZones

func (a *Allocator) DumpZones(prefixFmt ...interface{})

func (*Allocator) ForeachNode

func (a *Allocator) ForeachNode(nodes NodeMask, fn func(*Node) bool)

ForeachNode calls the given function with each node present in the mask. It stops iterating early if the function returns false.

func (*Allocator) ForeachRequest

func (a *Allocator) ForeachRequest(req *Request, fn func(*Request) bool)

ForeachRequest calls the given function with each active allocation in the allocator. It stops iterating early if the functions returns false.

func (*Allocator) GetOffer

func (a *Allocator) GetOffer(req *Request) (*Offer, error)

GetOffer returns an offer for the given request. The offer can be turned into an actual allocation by Commit(). Multiple offers can coexist for a request. Committing any offer invalidates all other offers. Allocating or releasing memory likewise invalidates all offers.

func (*Allocator) Masks

func (a *Allocator) Masks() *MaskCache

Masks returns the memory node and type mask cache for the allocator.

func (*Allocator) Realloc

func (a *Allocator) Realloc(id string, affinity NodeMask, types TypeMask) (NodeMask, map[string]NodeMask, error)

Realloc updates an existing allocation with the given extra affinity and memory types. Realloc is semantically either expansive or no-op. In particular, Realloc cannot be used to remove assigned nodes and types from an allocation, and it cannot be used to shrink the amount of memory assigned to an allocation. A non-zero affinity and 0 types cause the types implied by affinity to be used. A non-zero types is used to filter non-matching nodes from the affinity used. A call with 0 affinity and types is a no-op. A call with both affinity and types matching the existing allocation is also a no-op. Realloc returns the updated nodes for the allocation, together with any updates made to other existing allocations to fulfill the request. The caller must ensure these updates are properly enforced.

func (*Allocator) Release

func (a *Allocator) Release(id string) error

Release releases the allocation with the given ID.

func (*Allocator) Reset

func (a *Allocator) Reset()

Reset resets the state of the allocator, releasing all allocations and invalidating all offers.

func (*Allocator) SortZones

func (a *Allocator) SortZones(f ZoneFilter, s ...ZoneSorter) []NodeMask

SortZones filters zones by a filter function into a slice, then sorts the slice by chaining the given sorting functions. A nil filter function picks all zones.

func (*Allocator) ZoneAvailable

func (a *Allocator) ZoneAvailable(zone NodeMask) int64

ZoneAvailable returns the amount of available memory in the zone.

func (*Allocator) ZoneCapacity

func (a *Allocator) ZoneCapacity(zone NodeMask) int64

ZoneCapacity returns the amount of total memory in the zone.

func (*Allocator) ZoneFree

func (a *Allocator) ZoneFree(zone NodeMask) int64

ZoneFree returns the amount of free memory in the zone.

func (*Allocator) ZoneNumUsers

func (a *Allocator) ZoneNumUsers(zone NodeMask) int

ZoneNumUsers returns the number of requests assigned to the zone.

func (*Allocator) ZoneType

func (a *Allocator) ZoneType(zone NodeMask) TypeMask

ZoneType returns the types of memory available in this zone.

func (*Allocator) ZoneUsage

func (a *Allocator) ZoneUsage(zone NodeMask) int64

ZoneUsage returns the amount of allocated memory in the zone.

func (*Allocator) ZonesByUsersSubzonesFirst

func (a *Allocator) ZonesByUsersSubzonesFirst(zone1, zone2 NodeMask) int

ZonesByUsersSubzonesFirst compares zone by number of users.

type AllocatorOption

type AllocatorOption func(*Allocator) error

AllocatorOption is an opaque option for an Allocator.

func WithCustomFunctions

func WithCustomFunctions(c *CustomFunctions) AllocatorOption

WithCustomFunctions returns an option for overriding default algorithms in an Allocator.

func WithNodes

func WithNodes(nodes []*Node) AllocatorOption

WithNodes is an option to assign the given memory nodes to an allocator.

func WithSystemNodes

func WithSystemNodes(sys sysfs.System) AllocatorOption

WithSystemNodes is an option to request an allocator to perform automatic NUMA node discovery using the given sysfs instance.

type CustomAllocator

type CustomAllocator interface {
	// CheckOvercommit checks any zone overcommit, returning the amount of spill for each.
	CheckOvercommit() map[NodeMask]int64
	// GetRequests returns all allocations.
	GetRequests() []*Request
	// GetRequestsForZone returns all allocations for the given zone.
	GetRequestsForZone(NodeMask) []*Request
	// MoveRequest moves the given allocation to the given zone.
	MoveRequest(id string, zone NodeMask) error
	// GetZones returns all zones which have active allocations.
	GetZones() []NodeMask
	// GetNodes returns all nodes known to the allocator.
	GetNodes() []*Node

	// DefaultExpandZone is the default implementation for zone expansion.
	DefaultExpandZone(NodeMask, TypeMask) NodeMask
	// DefaultHandleOvercommit is the default implementation for overcommit handling.
	DefaultHandleOvercommit(overcommit map[NodeMask]int64) error

	// GetAllocator returns the underlying customized allocator.
	GetAllocator() *Allocator
}

CustomAllocator is the interface custom functions use to interact with the Allocator they customize.

type CustomFunctions

type CustomFunctions struct {
	// ExpandZone returns the extra nodes to expand the given zone for the
	// given memory types. Zone expansion happens either when resolving
	// overcommit of the given zone to figure out where to move allocations,
	// or to satisfy the requested memory types for an allocation request,
	// if the preferred affinity is not enough to do so. DefaultExpandZone
	// in CustomAllocator provides a default implementation.
	ExpandZone func(zone NodeMask, types TypeMask, a CustomAllocator) NodeMask
	// HandleOvercommit takes care of reducing memory usage in overcommitted
	// zones. Such zones have less capacity than the total consumption by all
	// active allocations. The given CustomAllocator provides functions for
	// overcommit handling, for instance MoveRequest() for moving allocations
	// to other zones and CheckOvercommit() for re-checking overcommit after
	// moves. DefaultHandleOvercommit in CustomAllocator provides a default
	// implementation.
	HandleOvercommit func(overcommit map[NodeMask]int64, a CustomAllocator) error
}

CustomFunctions can be used to provide custom implementations which override default algorithms in an Allocator. Use the WithCustomFunctions option to pass custom functions to an Allocator.

type Distance

type Distance struct {
	// contains filtered or unexported fields
}

Distance represents distance of a memory node from other nodes.

func NewDistance

func NewDistance(id ID, vector []int) (Distance, error)

NewDistance creates a new Distance from the given distance vector.

func (*Distance) Clone

func (d *Distance) Clone() *Distance

Clone returns a copy of the distance info.

func (*Distance) NodesAt

func (d *Distance) NodesAt(dist int) NodeMask

NodesAt returns the set of nodes at the given distance.

func (*Distance) Sorted

func (d *Distance) Sorted() []int

Sorted returns the original distance vector sorted.

func (*Distance) Vector

func (d *Distance) Vector() []int

Vector returns the original distance vector for the distance info.

type ID

type ID = idset.ID

ID is the unique ID of a memory node, its NUMA node ID.

type MaskCache

type MaskCache struct {
	// contains filtered or unexported fields
}

MaskCache caches oft-used memory type and node masks for an Allocator.

func NewMaskCache

func NewMaskCache(nodes ...*Node) *MaskCache

NewMaskCache returns a new cache with the given nodes added.

func (*MaskCache) AvailableNodes

func (c *MaskCache) AvailableNodes() NodeMask

AvailableNodes returns all nodes added to the cache.

func (*MaskCache) AvailableTypes

func (c *MaskCache) AvailableTypes() TypeMask

AvailableTypes returns all available types from the cache. A type considered available if at least one node with non-zero amount of attached memory of the type was added to the cache.

func (*MaskCache) Clone

func (c *MaskCache) Clone() *MaskCache

Clone returns a copy of the cache.

func (*MaskCache) Dump

func (c *MaskCache) Dump(prefix, header string)

Log debug-dumps the contents of the cache.

func (*MaskCache) NodesByTypes

func (c *MaskCache) NodesByTypes(types TypeMask) NodeMask

NodesByTypes the nodes with given type of memory attached from the cache. Note that if any of the given types is unavailable NodesByTypes returns an empty NodeMask even if other types of memory in the TypeMask is available.

func (*MaskCache) NodesWithCloseCPUs

func (c *MaskCache) NodesWithCloseCPUs() NodeMask

NodesWithCloseCPUs returns all nodes which have a non-empty set of close CPUs from the cache.

func (*MaskCache) NodesWithMem

func (c *MaskCache) NodesWithMem() NodeMask

NodesWithMem returns all nodes with any memory attached from the cache.

func (*MaskCache) NodesWithMovableMem

func (c *MaskCache) NodesWithMovableMem() NodeMask

NodesWithMovableMem returns all nodes with movable memory attached from the cache.

func (*MaskCache) NodesWithNormalMem

func (c *MaskCache) NodesWithNormalMem() NodeMask

NodesWithNormalMem returns all nodes with normal, non-movable memory attached from the cache.

func (*MaskCache) NodesWithoutCloseCPUs

func (c *MaskCache) NodesWithoutCloseCPUs() NodeMask

NodesWithoutCloseCPUs returns all nodes which have no close CPUs from the cache.

func (*MaskCache) NodesWithoutMem

func (c *MaskCache) NodesWithoutMem() NodeMask

NodesWithMem returns all nodes with no memory attached from the cache.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a memory node with some amount and type of attached memory.

func NewNode

func NewNode(id ID, t Type, capa int64, normal bool, cpus cpuset.CPUSet, d []int) (*Node, error)

NewNode creates a new node with the given parameters.

func (*Node) Capacity

func (n *Node) Capacity() int64

Capacity returns the amount of memory attached to the node.

func (*Node) CloseCPUs

func (n *Node) CloseCPUs() cpuset.CPUSet

CloseCPUs returns the set of CPUs closest to the node.

func (*Node) Distance

func (n *Node) Distance() *Distance

Distance returns distance information for the node.

func (*Node) DistanceTo

func (n *Node) DistanceTo(id ID) int

DistanceTo returns the distance of the node to the given node.

func (*Node) ForeachDistance

func (n *Node) ForeachDistance(fn func(int, NodeMask) bool)

ForeachDistance calls the given function for each distance in the distance vector in increasing order, skipping the first distance to the node itself, until the function returns false, or ForeachDone. Iteration continues if the returned value is true, or ForeachMore. At each iteration the function is called with the current distance and the set of nodes at that distance.

func (*Node) HasCPUs

func (n *Node) HasCPUs() bool

HasCPUs returns true if the node has a non-empty set of close CPUs.

func (*Node) HasMemory

func (n *Node) HasMemory() bool

HasMemory returns true if the node has some memory attached.

func (*Node) ID

func (n *Node) ID() ID

ID returns the node ID for the node.

func (*Node) IsMovable

func (n *Node) IsMovable() bool

IsMovable returns true if the memory attached to the node is movable.

func (*Node) IsNormal

func (n *Node) IsNormal() bool

IsNormal returns true if the memory attached to the node is not movable.

func (*Node) Mask

func (n *Node) Mask() NodeMask

Mask returns the node mask bit for the node.

func (*Node) Type

func (n *Node) Type() Type

Type returns the type of memory attached to the node.

type NodeMask

type NodeMask uint64

NodeMask represents a set of node IDs as a bit mask.

const (
	AnyZone NodeMask = 0
)

func MustParseNodeMask

func MustParseNodeMask(str string) NodeMask

MustParseNodeMask parses the given string representation of a NodeMask. It panicks on failure.

func NewNodeMask

func NewNodeMask(ids ...ID) NodeMask

NewNodeMask returns a NodeMask with the given ids.

func ParseNodeMask

func ParseNodeMask(str string) (NodeMask, error)

ParseNodeMask parses the given string representation of a NodeMask.

func (NodeMask) And

func (m NodeMask) And(o NodeMask) NodeMask

And returns a NodeMask with all IDs which are present in both NodeMasks.

func (NodeMask) AndNot

func (m NodeMask) AndNot(o NodeMask) NodeMask

AndNot returns a NodeMask with all IDs which are present in m but not in o.

func (NodeMask) Clear

func (m NodeMask) Clear(ids ...ID) NodeMask

Clear returns a NodeMask with the given IDs removed.

func (NodeMask) Contains

func (m NodeMask) Contains(ids ...ID) bool

Contains returns true if all the given IDs are present in the NodeMask.

func (NodeMask) ContainsAny

func (m NodeMask) ContainsAny(ids ...ID) bool

ContainsAny returns true if any of the given IDs are present in the NodeMask.

func (NodeMask) Foreach

func (m NodeMask) Foreach(fn func(ID) bool)

Foreach calls the given function for each ID set in the NodeMask until the function returns false, or ForeachDone. Iteration continues if the returned value is true, or ForeachMore.

func (NodeMask) MemsetString

func (m NodeMask) MemsetString() string

MemsetString returns a linux memory set-compatible string representation of the NodeMask. This string is suitable to be used with the cpuset cgroup controller for pinning processes to memory nodes.

func (NodeMask) Or

func (m NodeMask) Or(o NodeMask) NodeMask

Or returns a NodeMask with all IDs which are present at least in one of the NodeMasks.

func (NodeMask) Set

func (m NodeMask) Set(ids ...ID) NodeMask

Set returns a NodeMask with both the original and the given IDs added.

func (NodeMask) Size

func (m NodeMask) Size() int

Size returns the number of IDs present in the NodeMask.

func (NodeMask) Slice

func (m NodeMask) Slice() []ID

Slice returns the node IDs stored in the NodeMask as a slice in increasing order.

func (NodeMask) String

func (m NodeMask) String() string

String returns a string representation of the NodeMask.

type Offer

type Offer struct {
	// contains filtered or unexported fields
}

Offer represents a possible memory allocation for a request. Valid offers can be committed and turned into actual allocations. Allocating memory or releasing memory invalidates all uncommitted offers.

func (*Offer) Commit

func (o *Offer) Commit() (NodeMask, map[string]NodeMask, error)

Commit the given offer, turning it into an allocation. Any other offers are invalidated.

func (*Offer) IsValid

func (o *Offer) IsValid() bool

func (*Offer) NodeMask

func (o *Offer) NodeMask() NodeMask

func (*Offer) Updates

func (o *Offer) Updates() map[string]NodeMask

type Priority

type Priority int16

Priority describes the priority of a request. Its is used to choose which requests should be reassigned to another memory zone when a zone runs out of memory (is overcommitted) by affinity based assignments alone. Priority is always relative to other requests. Default priorities are provided for the well-known QoS classes (BestEffort, Burstable, Guaranteed).

const (
	NoPriority  Priority = 0             // moved around freely
	BestEffort  Priority = 0             // ditto, do your worst
	Burstable   Priority = (1 << 10)     // move if necessary
	Guaranteed  Priority = (1 << 14)     // try avoid moving this
	Preserved   Priority = (1 << 15) - 2 // try avoid moving this... harder
	Reservation Priority = (1 << 15) - 1 // immovable
)

func (Priority) String

func (p Priority) String() string

String returns a string representation of this priority.

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request represents a memory allocation request.

func Container

func Container(id, name string, qos string, limit int64, affin NodeMask) *Request

Container is a convenience function to create a request for a container of a particular QoS class. The QoS class is used to set the priority for the request.

func ContainerWithStrictTypes

func ContainerWithStrictTypes(id, name, qos string, limit int64, affin NodeMask, types TypeMask) *Request

ContainerWithStrictTypes is a convenience function to create a request with strict memory type preference for a container of a particular QoS class. The QoS class is used to set the priority for the request.

func ContainerWithTypes

func ContainerWithTypes(id, name, qos string, limit int64, affin NodeMask, types TypeMask) *Request

ContainerWithTypes is a convenience function to create a request with a memory type preference for a container of a particular QoS class. The QoS class is used to set the priority for the request.

func NewRequest

func NewRequest(id string, limit int64, affinity NodeMask, options ...RequestOption) *Request

NewRequest returns a new request with the given parameters and options.

func PreservedContainer

func PreservedContainer(id, name string, limit int64, affin NodeMask) *Request

PreserveContainer is a convenience function to create an allocation request for a container with 'preserved' memory. Such a request has higher priority than other, ordinary requests. The allocator tries to avoid moving such allocations later when trying to satisfy subsequent requests.

func ReservedMemory

func ReservedMemory(limit int64, nodes NodeMask, options ...RequestOption) *Request

ReservedMemory is a convenience function to create an allocation request for reserving memory from the allocator. Once memory has been successfully reserved, it is never moved by the allocator. ReservedMemory can be used to inform the allocator about external memory allocations which are beyond the control of the caller.

func SortRequests

func SortRequests(requests map[string]*Request, f RequestFilter, s ...RequestSorter) []*Request

SortRequests filters the requests by a filter function into a slice, then sorts the slice by chaining the given sorting functions. A nil filter function picks all requests.

func (*Request) Affinity

func (r *Request) Affinity() NodeMask

Affinity returns the node affinity of this request. The allocator will start with this set of nodes to fulfill the request.

func (*Request) Created

func (r *Request) Created() int64

Created returns the timestamp of creation for this request.

func (*Request) ID

func (r *Request) ID() string

ID returns the ID of this request.

func (*Request) IsStrict

func (r *Request) IsStrict() bool

IsStrict returns whether the type preference for this request is strict.

func (*Request) Name

func (r *Request) Name() string

Name returns the name of this request, using its ID if a name was not set.

func (*Request) Priority

func (r *Request) Priority() Priority

Priority returns the priority for this request.

func (*Request) Size

func (r *Request) Size() int64

Size returns the allocation size of this request.

func (*Request) String

func (r *Request) String() string

String returns a string representation of this request.

func (*Request) Types

func (r *Request) Types() TypeMask

Types returns the types of memory for this request.

func (*Request) Zone

func (r *Request) Zone() NodeMask

Zone returns the allocated memory zone for this request. It is the final set of nodes the allocator used to fulfill the request.

type RequestFilter

type RequestFilter func(*Request) bool

RequestFilter is a function to filter requests.

func RequestsWithMaxPriority

func RequestsWithMaxPriority(limit Priority) RequestFilter

RequestsWithMaxPriority filters requests by maximum allowed priority.

type RequestOption

type RequestOption func(*Request)

RequestOption is an opaque option which can be applied to a request.

func WithName

func WithName(name string) RequestOption

WithName returns an option for setting a verbose name for the request.

func WithPreferredTypes

func WithPreferredTypes(types TypeMask) RequestOption

WithPreferredTypes returns an option to set preferred memory types for a request.

func WithPriority

func WithPriority(p Priority) RequestOption

WithPriority returns an option to set the priority of a request.

func WithQosClass

func WithQosClass(qosClass string) RequestOption

WithQosClass returns an option to set the priority of a request based on a QoS class.

func WithStrictTypes

func WithStrictTypes(types TypeMask) RequestOption

WithStrictTypes returns an option to set strict memory types for a request.

type RequestSorter

type RequestSorter func(r1, r2 *Request) int

RequestSorter is a function to compare requests for sorting.

type Type

type Type int

Type represents known types of memory.

const (
	TypeDRAM Type = iota // ordinary DRAM
	TypePMEM             // 'persistent' memory, typically slower but higher capacity than DRAM
	TypeHBM              // high-bandwidth memory
)

func MustParseType

func MustParseType(str string) Type

MustParseType parses the given string into a memory type. It panicks on failure.

func ParseType

func ParseType(str string) (Type, error)

ParseType parses the given string into a memory type.

func TypeForSysfs

func TypeForSysfs(sysType sysfs.MemoryType) Type

TypeForSysfs returns the memory type for the given sysfs memory type.

func (Type) IsValid

func (t Type) IsValid() bool

IsValid returns true if the memory type is valid/known.

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

MarshalJSON is the json.Marshaller for Type.

func (Type) Mask

func (t Type) Mask() TypeMask

Mask returns the memory TypeMask for the memory type.

func (Type) String

func (t Type) String() string

String returns a string representation of the memory type.

func (Type) Sysfs

func (t Type) Sysfs() sysfs.MemoryType

Sysfs returns the sysfs memory type for the given memory type.

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(data []byte) error

UnmarshalJSON is the json.Unmarshaller for Type.

type TypeMask

type TypeMask int

TypeMask represents a set of memory types as a bit mask.

const (
	TypeMaskDRAM TypeMask = 1 << TypeDRAM          // ordinary DRAM
	TypeMaskPMEM TypeMask = 1 << TypePMEM          // 'persistent' memory
	TypeMaskHBM  TypeMask = 1 << TypeHBM           // high-bandwidth memory
	TypeMaskAll  TypeMask = (TypeMaskHBM << 1) - 1 // all types of memory
)

func MustParseTypeMask

func MustParseTypeMask(str string) TypeMask

MustParseTypeMask parses the given string into a TypeMask. It panicks on failure.

func NewTypeMask

func NewTypeMask(types ...Type) TypeMask

NewTypeMask returns a TypeMask containing the given memory types.

func NewTypeMaskForSysfs

func NewTypeMaskForSysfs(sysTypes ...sysfs.MemoryType) TypeMask

NewTypeMaskForSysfs returns a TypeMask containing th given sysfs memory types.

func ParseTypeMask

func ParseTypeMask(str string) (TypeMask, error)

ParseTypeMask parses the given string into a TypeMask.

func (TypeMask) And

func (m TypeMask) And(o TypeMask) TypeMask

And returns a TypeMask with all IDs which are present in both masks.

func (TypeMask) AndNot

func (m TypeMask) AndNot(o TypeMask) TypeMask

And returns a TypeMask with all IDs which are present in m but not in o.

func (TypeMask) Clear

func (m TypeMask) Clear(types ...Type) TypeMask

Clear returns a TypeMask with the given types removed.

func (TypeMask) Contains

func (m TypeMask) Contains(types ...Type) bool

Contains returns true if all the given types are present in the TypeMask.

func (TypeMask) ContainsAny

func (m TypeMask) ContainsAny(types ...Type) bool

ContainsAny returns true if any of the given types are present in the TypeMask.

func (TypeMask) Foreach

func (m TypeMask) Foreach(fn func(Type) bool)

Foreach calls the given function for each type present in the TypeMask until the function returns false, or ForeachDone. Iteration continues if the returned value is true, or ForeachMore.

func (TypeMask) MarshalJSON

func (m TypeMask) MarshalJSON() ([]byte, error)

MarshalJSON is the json.Marshaller for TypeMask.

func (TypeMask) Or

func (m TypeMask) Or(o TypeMask) TypeMask

And returns a TypeMask with all IDs which are present at least in one of the masks.

func (TypeMask) Set

func (m TypeMask) Set(types ...Type) TypeMask

Set returns a TypeMask with the original and the given types added.

func (TypeMask) Slice

func (m TypeMask) Slice() []Type

Slice returns the memory types present in the TypeMask.

func (TypeMask) String

func (m TypeMask) String() string

String returns a string representation of the TypeMask.

func (*TypeMask) UnmarshalJSON

func (m *TypeMask) UnmarshalJSON(data []byte) error

UnmarshalJSON is the json.Unmarshaller for TypeMask.

type Zone

type Zone struct {
	// contains filtered or unexported fields
}

Zone is a collection of Nodes which is collectively used to fulfill one or more allocation requests.

type ZoneFilter

type ZoneFilter func(NodeMask) bool

ZoneFilter is a function to filter zones.

type ZoneSorter

type ZoneSorter func(z1, z2 NodeMask) int

ZoneSorter is a function to compare zones for sorting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL