Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resmgr: lifecycle overlap detection and workaround. #358

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 70 additions & 5 deletions cmd/plugins/topology-aware/policy/topology-aware-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (p *policy) Start() error {
p.checkColdstartOff()

p.root.Dump("<post-start>")
p.checkAllocations(" <post-start>")

return nil
}
Expand All @@ -148,19 +149,82 @@ func (p *policy) Sync(add []cache.Container, del []cache.Container) error {
p.AllocateResources(c)
}

p.checkAllocations(" <post-sync>")

return nil
}

func (p *policy) checkAllocations(format string, args ...interface{}) {
var (
prefix = fmt.Sprintf(format, args...)
cpuExcl = 0
cpuPart = 0
mem = uint64(0)
ctr = map[string]Grant{}
dup = map[string][]Grant{}
)

getMemorySize := func(g Grant) uint64 {
var (
limit = g.MemLimit()
total = uint64(0)
)
for _, memType := range []memoryType{memoryDRAM, memoryPMEM, memoryHBM} {
total += limit[memType]
}
return total
}

for _, g := range p.allocations.grants {
log.Debug("%s %s (%s)", prefix, g, g.GetContainer().GetID())
full := g.ExclusiveCPUs().Size()
part := g.CPUPortion()
cpuExcl += full
cpuPart += part

mem += getMemorySize(g)

_, ok := p.cache.LookupContainer(g.GetContainer().GetID())
if !ok {
log.Error("%s %s STALE container among allocations, not found in cache", prefix, g)
}

key := g.GetContainer().PrettyName()
old, ok := ctr[key]
if ok {
if len(dup[key]) == 0 {
dup[key] = []Grant{old, g}
} else {
dup[key] = append(dup[key], g)
}
} else {
ctr[key] = g
}
}

for key, grants := range dup {
log.Error("%s DUPLICATE allocation entries for container %s", prefix, key)
for _, g := range grants {
log.Error("%s %s (%s)", prefix, g, g.GetContainer().GetID())
}
}

log.Info("%s total CPU granted: %dm (%d exclusive + %dm shared), total memory granted: %s",
klihub marked this conversation as resolved.
Show resolved Hide resolved
prefix, 1000*cpuExcl+cpuPart, cpuExcl, cpuPart, prettyMem(mem))

}

// AllocateResources is a resource allocation request for this policy.
func (p *policy) AllocateResources(container cache.Container) error {
log.Debug("allocating resources for %s...", container.PrettyName())
log.Debug("allocating resources for %s (%s)...", container.PrettyName(), container.GetID())

err := p.allocateResources(container, "")
if err != nil {
return err
}

p.root.Dump("<post-alloc>")
p.checkAllocations(" <post-alloc %s>", container.PrettyName())

return nil
}
Expand All @@ -179,13 +243,14 @@ func (p *policy) allocateResources(container cache.Container, poolHint string) e

// ReleaseResources is a resource release request for this policy.
func (p *policy) ReleaseResources(container cache.Container) error {
log.Debug("releasing resources of %s...", container.PrettyName())
log.Debug("releasing resources for %s (%s)...", container.PrettyName(), container.GetID())

if grant, found := p.releasePool(container); found {
p.updateSharedAllocations(&grant)
}

p.root.Dump("<post-release>")
p.checkAllocations(" <post-release %s>", container.PrettyName())

return nil
}
Expand All @@ -208,6 +273,7 @@ func (p *policy) UpdateResources(container cache.Container) error {
}

p.root.Dump("<post-update>")
p.checkAllocations(" <post-update %s>", container.PrettyName())

return nil
}
Expand Down Expand Up @@ -394,7 +460,7 @@ func (p *policy) reallocateResources(containers []cache.Container, pools map[str
p.releasePool(c)
}
for _, c := range containers {
log.Debug("reallocating resources for %s...", c.PrettyName())
log.Debug("reallocating resources for %s (%s)...", c.PrettyName(), c.GetID())

grant, err := p.allocatePool(c, pools[c.GetID()])
if err != nil {
Expand All @@ -410,8 +476,6 @@ func (p *policy) reallocateResources(containers []cache.Container, pools map[str

p.updateSharedAllocations(nil)

p.root.Dump("<post-realloc>")

return nil
}

Expand Down Expand Up @@ -452,6 +516,7 @@ func (p *policy) Reconfigure(newCfg interface{}) error {
}

p.root.Dump("<post-config>")
p.checkAllocations(" <post-config>")

return nil
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/resmgr/cache/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,9 @@ func (p *pod) PrettyName() string {
}

namespace := p.GetNamespace()
switch namespace {
case "default":
p.prettyName = ""
case "":
if namespace == "" {
p.prettyName = "<unknown-namespace>/"
default:
} else {
p.prettyName = namespace + "/"
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/resmgr/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"flag"
"time"

nri "github.com/containerd/nri/pkg/api"
"github.com/containerd/nri/pkg/api"
"github.com/containers/nri-plugins/pkg/pidfile"
)

Expand Down Expand Up @@ -54,7 +54,7 @@ func init() {
"NRI plugin name to register.")
flag.StringVar(&opt.NriPluginIdx, "nri-plugin-index", defaultPluginIndex,
"NRI plugin index to register.")
flag.StringVar(&opt.NriSocket, "nri-socket", nri.DefaultSocketPath,
flag.StringVar(&opt.NriSocket, "nri-socket", api.DefaultSocketPath,
"NRI unix domain socket path to connect to.")

flag.StringVar(&opt.PidFile, "pid-file", pidfile.GetPath(),
Expand Down
Loading