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

topology-aware: correctly reconfigure implicit affinities for configuration changes. #394

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
19 changes: 14 additions & 5 deletions cmd/plugins/topology-aware/policy/affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,25 @@ func (p *policy) registerImplicitAffinities() error {
},
}

enabled := map[string]cache.ImplicitAffinity{}
var (
add = map[string]cache.ImplicitAffinity{}
del = []string{}
)

for _, a := range affinities {
if a.disabled {
name := PolicyName + ":" + a.name
del = append(del, name)

if !a.disabled {
log.Info("implicit affinity %s is enabled", a.name)
add[name] = a.affinity
} else {
log.Info("implicit affinity %s is disabled", a.name)
continue
}
enabled[PolicyName+":"+a.name] = a.affinity
}

if err := p.cache.AddImplicitAffinities(enabled); err != nil {
p.cache.DeleteImplicitAffinities(del...)
if err := p.cache.AddImplicitAffinities(add); err != nil {
return policyError("failed to register implicit affinities: %v", err)
}

Expand Down
9 changes: 9 additions & 0 deletions cmd/plugins/topology-aware/policy/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
resmgr "github.com/containers/nri-plugins/pkg/apis/resmgr/v1alpha1"
"github.com/containers/nri-plugins/pkg/cpuallocator"
"github.com/containers/nri-plugins/pkg/resmgr/cache"
libmem "github.com/containers/nri-plugins/pkg/resmgr/lib/memory"
"github.com/containers/nri-plugins/pkg/sysfs"
system "github.com/containers/nri-plugins/pkg/sysfs"
"github.com/containers/nri-plugins/pkg/topology"
Expand Down Expand Up @@ -186,6 +187,9 @@ func (c *mockCPU) GetCachesByLevel(int) []*sysfs.Cache {
func (c *mockCPU) GetCacheByIndex(int) *sysfs.Cache {
panic("unimplemented")
}
func (c *mockCPU) GetNthLevelCacheCPUSet(n int) cpuset.CPUSet {
panic("unimplemented")
}
func (c *mockCPU) GetLastLevelCaches() []*sysfs.Cache {
panic("unimplemented")
}
Expand Down Expand Up @@ -531,6 +535,9 @@ func (m *mockContainer) PreserveCpuResources() bool {
func (m *mockContainer) PreserveMemoryResources() bool {
return false
}
func (m *mockContainer) MemoryTypes() (libmem.TypeMask, error) {
return libmem.TypeMaskDRAM, nil
}

type mockPod struct {
name string
Expand Down Expand Up @@ -669,6 +676,8 @@ func (m *mockCache) EvaluateAffinity(*cache.Affinity) map[string]int32 {
func (m *mockCache) AddImplicitAffinities(map[string]cache.ImplicitAffinity) error {
return nil
}
func (m *mockCache) DeleteImplicitAffinities(...string) {
}
func (m *mockCache) GetActivePolicy() string {
panic("unimplemented")
}
Expand Down
14 changes: 0 additions & 14 deletions cmd/plugins/topology-aware/policy/pools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,6 @@ func TestWorkloadPlacement(t *testing.T) {
expectedRemainingNodes: []int{0, 1, 2, 3, 4, 5, 6},
expectedLeafNode: false,
},
{
path: path.Join(dir, "sysfs", "server", "sys"),
name: "workload placement on a server system root node: memory doesn't fit to leaf",
req: &request{
memReq: 190000000000,
memLim: 190000000000,
memType: memoryUnspec,
isolate: false,
full: 28,
container: &mockContainer{},
},
expectedRemainingNodes: []int{2, 6},
expectedLeafNode: false,
},
}
for _, tc := range tcases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
8 changes: 7 additions & 1 deletion cmd/plugins/topology-aware/policy/topology-aware-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func (p *policy) Setup(opts *policyapi.BackendOptions) error {
return policyError("failed to initialize %s policy: %w", PolicyName, err)
}

p.registerImplicitAffinities()
if err := p.registerImplicitAffinities(); err != nil {
return policyError("failed to initialize %s policy: %w", PolicyName, err)
}

log.Info("***** default CPU priority is %s", defaultPrio)

Expand Down Expand Up @@ -484,6 +486,10 @@ func (p *policy) Reconfigure(newCfg interface{}) error {
return policyError("failed to reconfigure: %v", err)
}

if err := p.registerImplicitAffinities(); err != nil {
return policyError("failed to reconfigure: %v", err)
}

for _, grant := range allocations.grants {
if err := grant.RefetchNodes(); err != nil {
*p = savedPolicy
Expand Down
2 changes: 1 addition & 1 deletion pkg/resmgr/cache/affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (cch *cache) AddImplicitAffinities(implicit map[string]ImplicitAffinity) er
}

// DeleteImplicitAffinities removes a previously registered set of implicit affinities.
func (cch *cache) DeleteImplicitAffinities(names []string) {
func (cch *cache) DeleteImplicitAffinities(names ...string) {
for _, name := range names {
delete(cch.implicit, name)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/resmgr/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ type Cache interface {
EvaluateAffinity(*Affinity) map[string]int32
// AddImplicitAffinities adds a set of implicit affinities (added to all containers).
AddImplicitAffinities(map[string]ImplicitAffinity) error
// DeleteImplicitAffinities deletes a set of implicit affinities by name.
DeleteImplicitAffinities(names ...string)

// GetActivePolicy returns the name of the active policy stored in the cache.
GetActivePolicy() string
Expand Down