Skip to content

Commit

Permalink
balloons: implement CPU and memory pinning preservation
Browse files Browse the repository at this point in the history
Signed-off-by: Antti Kervinen <[email protected]>
  • Loading branch information
askervin authored and klihub committed Feb 14, 2024
1 parent 42457cf commit 68c19f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/plugins/balloons/policy/balloons-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ func (p *balloons) Sync(add []cache.Container, del []cache.Container) error {

// AllocateResources is a resource allocation request for this policy.
func (p *balloons) AllocateResources(c cache.Container) error {
if c.PreserveCpuResources() {
log.Infof("not handling resources of container %s, preserving CPUs %q and memory %q", c.PrettyName(), c.GetCpusetCpus(), c.GetCpusetMems())
return nil
}
log.Debug("allocating resources for container %s (request %d mCPU, limit %d mCPU)...",
c.PrettyName(),
p.containerRequestedMilliCpus(c.GetID()),
Expand Down Expand Up @@ -1367,8 +1371,12 @@ func (p *balloons) pinCpuMem(c cache.Container, cpus cpuset.CPUSet, mems idset.I
}
}
if p.bpoptions.PinMemory == nil || *p.bpoptions.PinMemory {
log.Debug(" - pinning %s to memory %s", c.PrettyName(), mems)
c.SetCpusetMems(mems.String())
if c.PreserveMemoryResources() {
log.Debug(" - preserving %s pinning to memory %q", c.PrettyName, c.GetCpusetMems())
} else {
log.Debug(" - pinning %s to memory %s", c.PrettyName(), mems)
c.SetCpusetMems(mems.String())
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions docs/resource-policy/policy/balloons.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ defined explicitly among other balloon types. If not defined, a
built-in `default` balloon type is implicitly appended at the end of
the balloon types list.

## Disabling CPU or Memory Pinning of a Container

Some containers may need to run on all CPUs or access all memories
without restrictions. Annotate these pods and containers to prevent
the resource policy from touching their CPU or memory pinning.

```yaml
cpu.preserve.resource-policy.nri.io/container.CONTAINER_NAME: "true"
cpu.preserve.resource-policy.nri.io/pod: "true"
cpu.preserve.resource-policy.nri.io: "true"
memory.preserve.resource-policy.nri.io/container.CONTAINER_NAME: "true"
memory.preserve.resource-policy.nri.io/pod: "true"
memory.preserve.resource-policy.nri.io: "true"
```

## Metrics and Debugging

In order to enable more verbose logging and metrics exporting from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,17 @@ namespace="e2e-d" CONTCOUNT=2 create balloons-busybox
report allowed
verify 'cpus["pod6c0"] == cpus["pod6c1"]'


# pod7: preserve annotation should skip placing a container into any
# balloon even if namespace wildcard in a balloon type matches.
CPUREQ="100m" MEMREQ="100M" CPULIM="100m" MEMLIM="100M"
POD_ANNOTATION='cpu.preserve.resource-policy.nri.io/container.pod7c1: "true"
memory.preserve.resource-policy.nri.io: "true"'
namespace="e2e-d" CONTCOUNT=3 create balloons-busybox
report allowed
verify 'cpus["pod6c0"] == cpus["pod7c0"]' \
'len(cpus["pod7c1"]) > len(cpus["pod7c0"])' \
'len(cpus["pod7c1"]) == 16'

cleanup
helm-terminate

0 comments on commit 68c19f8

Please sign in to comment.