topologyaware

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PolicyName is the name of this policy.
	PolicyName = "topology-aware"
	// PolicyDescription is a short description of this policy.
	PolicyDescription = "A policy for prototyping memory tiering."

	// ColdStartDone is the event generated for the end of a container cold start period.
	ColdStartDone = "cold-start-done"
)
View Source
const (
	IndentDepth = 4
)

indent produces an indentation string for the given level.

View Source
const (
	// OverfitPenalty is the per layer penalty for overfitting in the node tree.
	OverfitPenalty = 0.9
)

Variables

This section is empty.

Functions

func New added in v0.3.0

func New() policyapi.Backend

New creates a new uninitialized topology-aware policy instance.

Types

type ColdStartPreference

type ColdStartPreference struct {
	Duration metav1.Duration // `json:"duration,omitempty"`
}

ColdStartPreference lists the various ways the container can be configured to trigger cold start. Currently, only timer is supported. If the "duration" is set to a duration greater than 0, cold start is enabled and the DRAM controller is added to the container after the duration has passed.

type Grant

type Grant interface {
	// SetCPUPortion sets the fraction CPU portion for the grant.
	SetCPUPortion(fraction int)
	// Clone creates a copy of this grant.
	Clone() Grant
	// RefetchNodes updates the stored cpu and memory nodes of this grant by name.
	RefetchNodes() error
	// GetContainer returns the container CPU capacity is granted to.
	GetContainer() cache.Container
	// GetCPUNode returns the node that granted CPU capacity to the container.
	GetCPUNode() Node
	// GetMemorySize returns the amount of memory allocated to this grant.
	GetMemorySize() int64
	// GetMemoryZone returns the memory zone allocated granted to the container.
	GetMemoryZone() libmem.NodeMask
	// CPUType returns the type of granted CPUs
	CPUType() cpuClass
	// CPUPortion returns granted milli-CPUs of non-full CPUs of CPUType().
	// CPUPortion() == ReservedPortion() + SharedPortion().
	CPUPortion() int
	// ExclusiveCPUs returns the exclusively granted non-isolated cpuset.
	ExclusiveCPUs() cpuset.CPUSet
	// ReservedCPUs returns the reserved granted cpuset.
	ReservedCPUs() cpuset.CPUSet
	// ReservedPortion() returns the amount of CPUs in milli-CPU granted.
	ReservedPortion() int
	// SharedCPUs returns the shared granted cpuset.
	SharedCPUs() cpuset.CPUSet
	// SharedPortion returns the amount of CPUs in milli-CPU granted.
	SharedPortion() int
	// IsolatedCpus returns the exclusively granted isolated cpuset.
	IsolatedCPUs() cpuset.CPUSet
	// MemoryType returns the type(s) of granted memory.
	MemoryType() memoryType
	// SetMemoryType sets the memory type for this grant.
	SetMemoryType(memoryType)
	// SetMemoryZone sets the memory zone for this grant.
	SetMemoryZone(libmem.NodeMask)
	// SetMemorySize sets the amount of memory to allocate.
	SetMemorySize(int64)
	// SetColdstart sets coldstart period for the grant.
	SetColdstart(time.Duration)

	// String returns a printable representation of this grant.
	String() string
	// Release releases the grant from all the Supplys it uses.
	Release()
	// Reallocate memory with the given types.
	ReallocMemory(types libmem.TypeMask) error
	// AccountAllocateCPU accounts for (removes) allocated exclusive capacity for this grant.
	AccountAllocateCPU()
	// AccountReleaseCPU accounts for (reinserts) released exclusive capacity for this grant.
	AccountReleaseCPU()
	// ColdStart returns the cold start timeout.
	ColdStart() time.Duration
	// AddTimer adds a cold start timer.
	AddTimer(*time.Timer)
	// StopTimer stops a cold start timer.
	StopTimer()
	// ClearTimer clears the cold start timer pointer.
	ClearTimer()
}

Grant represents CPU and memory capacity allocated to a container from a node.

type Node

type Node interface {
	// IsNil tests if this node is nil.
	IsNil() bool
	// Name returns the name of this node.
	Name() string
	// Kind returns the type of this node.
	Kind() NodeKind
	// NodeID returns the (enumerated) node id of this node.
	NodeID() int
	// Parent returns the parent node of this node.
	Parent() Node
	// Children returns the child nodes of this node.
	Children() []Node
	// LinkParent sets the given node as the parent node, and appends this node as a its child.
	LinkParent(Node)
	// AddChildren appends the nodes to the children, *WITHOUT* updating their parents.
	AddChildren([]Node)
	// IsSameNode returns true if the given node is the same as this one.
	IsSameNode(Node) bool
	// IsRootNode returns true if this node has no parent.
	IsRootNode() bool
	// IsLeafNode returns true if this node has no children.
	IsLeafNode() bool
	// Get the distance of this node from the root node.
	RootDistance() int
	// Get the height of this node (inverse of depth: tree depth - node depth).
	NodeHeight() int
	// System returns the policy sysfs instance.
	System() system.System
	// Policy returns the policy back pointer.
	Policy() *policy
	// GetSupply returns the full CPU at this node.
	GetSupply() Supply
	// FreeSupply returns the available CPU supply of this node.
	FreeSupply() Supply
	// GrantedReservedCPU returns the amount of granted reserved CPU of this node and its children.
	GrantedReservedCPU() int
	// GrantedSharedCPU returns the amount of granted shared CPU of this node and its children.
	GrantedSharedCPU() int
	// GetMemset
	GetMemset(mtype memoryType) idset.IDSet
	// DepthFirst traverse the tree@node calling the function at each node.
	DepthFirst(func(Node))
	// BreadthFirst traverse the tree@node calling the function at each node.
	BreadthFirst(func(Node))
	// Dump state of the node.
	Dump(string, ...int)

	GetMemoryType() memoryType
	HasMemoryType(memoryType) bool
	GetPhysicalNodeIDs() []idset.ID

	GetScore(Request) Score
	HintScore(topology.Hint) float64
	// contains filtered or unexported methods
}

Node is the abstract interface our partition tree nodes implement.

type NodeKind

type NodeKind string

NodeKind represents a unique node type.

const (
	// NilNode is the type of a nil node.
	NilNode NodeKind = ""
	// UnknownNode is the type of unknown node type.
	UnknownNode NodeKind = "unknown"
	// SocketNode represents a physical CPU package/socket in the system.
	SocketNode NodeKind = "socket"
	// DieNode represents a die within a physical CPU package/socket in the system.
	DieNode NodeKind = "die"
	// NumaNode represents a NUMA node in the system.
	NumaNode NodeKind = "numa node"
	// L3CacheNode represents an L3 cache grouping of CPUs in the system.
	L3CacheNode NodeKind = "L3 cache"
	// VirtualNode represents a virtual node, currently the root multi-socket setups.
	VirtualNode NodeKind = "virtual node"
)

func NodeKindForTopologyLevel added in v0.11.0

func NodeKindForTopologyLevel(level cfgapi.CPUTopologyLevel) NodeKind

func (NodeKind) TopologyLevel added in v0.11.0

func (k NodeKind) TopologyLevel() cfgapi.CPUTopologyLevel

TopologyLevel returns the topology level for this node.

type Request

type Request interface {
	// GetContainer returns the container requesting CPU capacity.
	GetContainer() cache.Container
	// String returns a printable representation of this request.
	String() string
	// CPUType returns the type of requested CPU.
	CPUType() cpuClass
	// CPUPrio returns the preferred priority of requested CPU.
	CPUPrio() cpuPrio
	// SetCPUType sets the type of requested CPU.
	SetCPUType(cpuType cpuClass)
	// FullCPUs return the number of full CPUs requested.
	FullCPUs() int
	// CPUFraction returns the amount of fractional milli-CPU requested.
	CPUFraction() int
	// CPULimit returns the amount of fractional CPU limit.
	CPULimit() int
	// Isolate returns whether isolated CPUs are preferred for this request.
	Isolate() bool
	// MemoryType returns the type(s) of requested memory.
	MemoryType() memoryType
	// MemAmountToAllocate retuns how much memory we need to reserve for a request.
	MemAmountToAllocate() int64
	// MemoryLimit returns the memory limit for the request.
	MemoryLimit() int64
	// PickByHints returns if picking resources by hints is preferred for this request.
	PickByHints() bool
	// ColdStart returns the cold start timeout.
	ColdStart() time.Duration
}

Request represents CPU and memory resources requested by a container.

type Score

type Score interface {
	// Calculate the actual score from the collected parameters.
	Eval() float64
	// Supply returns the supply associated with this score.
	Supply() Supply
	// Request returns the request associated with this score.
	Request() Request

	IsolatedCapacity() int
	ReservedCapacity() int
	SharedCapacity() int
	Colocated() int
	HintScores() map[string]float64
	PrioCapacity(cpuPrio) int

	Offer() *libmem.Offer

	String() string
}

Score represents how well a supply can satisfy a request.

type Supply

type Supply interface {
	// GetNode returns the node supplying this capacity.
	GetNode() Node
	// Clone creates a copy of this supply.
	Clone() Supply
	// IsolatedCPUs returns the isolated cpuset in this supply.
	IsolatedCPUs() cpuset.CPUSet
	// ReservedCPUs returns the reserved cpuset in this supply.
	ReservedCPUs() cpuset.CPUSet
	// SharableCPUs returns the sharable cpuset in this supply.
	SharableCPUs() cpuset.CPUSet
	// GrantedReserved returns the locally granted reserved CPU capacity in this supply.
	GrantedReserved() int
	// GrantedShared returns the locally granted shared CPU capacity in this supply.
	GrantedShared() int
	// Cumulate cumulates the given supply into this one.
	Cumulate(Supply)
	// AccountAllocateCPU accounts for (removes) allocated exclusive capacity from the supply.
	AccountAllocateCPU(Grant)
	// AccountReleaseCPU accounts for (reinserts) released exclusive capacity into the supply.
	AccountReleaseCPU(Grant)
	// GetScore calculates how well this supply fits/fulfills the given request.
	GetScore(Request) Score
	// AllocatableSharedCPU calculates the allocatable amount of shared CPU of this supply.
	AllocatableSharedCPU(...bool) int
	// SliceableCPUs calculates the shared cpuset we can slice exclusive CPUs off of.
	SliceableCPUs() (cpuset.CPUSet, error)
	// Allocate allocates a grant from the supply.
	Allocate(Request, *libmem.Offer) (Grant, map[string]libmem.NodeMask, error)
	// ReleaseCPU releases a previously allocated CPU grant from this supply.
	ReleaseCPU(Grant)

	// Reserve accounts for CPU grants after reloading cached allocations.
	Reserve(Grant, *libmem.Offer) (map[string]libmem.NodeMask, error)
	// DumpCapacity returns a printable representation of the supply's resource capacity.
	DumpCapacity() string
	// DumpAllocatable returns a printable representation of the supply's alloctable resources.
	DumpAllocatable() string
}

Supply represents avaialbe CPU and memory capacity of a node.

type TopologyAwareMetrics added in v0.8.0

type TopologyAwareMetrics struct {
	ZoneNames []string
	Zones     map[string]*Zone
	// contains filtered or unexported fields
}

func (*TopologyAwareMetrics) Update added in v0.8.0

func (m *TopologyAwareMetrics) Update()

Update updates our metrics.

type Zone added in v0.8.0

type Zone struct {
	Name                 string
	Cpus                 cpuset.CPUSet
	Mems                 libmem.NodeMask
	SharedPool           cpuset.CPUSet
	SharedAssigned       int
	SharedAvailable      int
	MemCapacity          int64
	MemAssigned          int64
	MemAvailable         int64
	ContainerCount       int
	SharedContainerCount int
}

Jump to

Keyboard shortcuts

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