Skip to content

Commit

Permalink
cache: support annotations to preserve CPU and memory pinning
Browse files Browse the repository at this point in the history
Signed-off-by: Antti Kervinen <antti.kervinen@intel.com>
  • Loading branch information
askervin authored and klihub committed Feb 14, 2024
1 parent 516da7f commit 5085371
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/resmgr/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const (

// TopologyHintsKey can be used to opt out from automatic topology hint generation.
TopologyHintsKey = "topologyhints" + "." + kubernetes.ResmgrKeyNamespace

// PreserveCpuKey means that CPU resources should not be touched.
PreserveCpuKey = "cpu.preserve." + kubernetes.ResmgrKeyNamespace
// PreserveMemoryKey means that memory resources should not be touched.
PreserveMemoryKey = "memory.preserve." + kubernetes.ResmgrKeyNamespace
)

// PodState is the pod state in the runtime.
Expand Down Expand Up @@ -245,6 +250,13 @@ type Container interface {
// GetMemorySwap gets the swap limit in bytes for the container.
GetMemorySwap() int64

// PreserveCpuResources() returns true if CPU resources of the
// container must not be changed.
PreserveCpuResources() bool
// PreserveMemoryResources() returns true if memory resources
// of the container must not be changed.
PreserveMemoryResources() bool

// GetPendingAdjusmentn clears and returns any pending adjustment for the container.
GetPendingAdjustment() *nri.ContainerAdjustment
// GetPendingUpdate clears and returns any pending update for the container.
Expand Down
10 changes: 10 additions & 0 deletions pkg/resmgr/cache/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,16 @@ func (c *container) GetMemorySwap() int64 {
return c.Ctr.GetLinux().GetResources().GetMemory().GetSwap().GetValue()
}

func (c *container) PreserveCpuResources() bool {
value, ok := c.GetEffectiveAnnotation(PreserveCpuKey)
return ok && value == "true"
}

func (c *container) PreserveMemoryResources() bool {
value, ok := c.GetEffectiveAnnotation(PreserveMemoryKey)
return ok && value == "true"
}

var (
// More complext rules, for Kubelet secrets and config maps
ignoredTopologyPathRegexps = []*regexp.Regexp{
Expand Down

0 comments on commit 5085371

Please sign in to comment.