Skip to content

Commit

Permalink
NRI plugins support adjust oom_score_adj
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaojin Zhang <[email protected]>
  • Loading branch information
z00784328 committed Aug 5, 2024
1 parent f575c3b commit 49d6c9d
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 155 deletions.
33 changes: 33 additions & 0 deletions pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
if err := r.adjustCgroupsPath(rpl.Linux.CgroupsPath, plugin); err != nil {
return err
}
if err := r.adjustOomScoreAdj(rpl.Linux.OomScoreAdj, plugin); err != nil {
return err
}
}
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
return err
Expand Down Expand Up @@ -666,6 +669,23 @@ func (r *result) adjustCgroupsPath(path, plugin string) error {
return nil
}

func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) error {
if OomScoreAdj == nil {
return nil
}

create, id := r.request.create, r.request.create.Container.Id

if err := r.owners.claimOomScoreAdj(id, plugin); err != nil {
return err
}

create.Container.Linux.OomScoreAdj = OomScoreAdj
r.reply.adjust.Linux.OomScoreAdj = OomScoreAdj

return nil
}

func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
for _, l := range rlimits {
Expand Down Expand Up @@ -893,6 +913,7 @@ type owners struct {
rdtClass string
unified map[string]string
cgroupsPath string
oomScoreAdj string
rlimits map[string]string
}

Expand Down Expand Up @@ -1001,6 +1022,10 @@ func (ro resultOwners) claimCgroupsPath(id, plugin string) error {
return ro.ownersFor(id).claimCgroupsPath(plugin)
}

func (ro resultOwners) claimOomScoreAdj(id, plugin string) error {
return ro.ownersFor(id).claimOomScoreAdj(plugin)
}

func (ro resultOwners) claimRlimits(id, typ, plugin string) error {
return ro.ownersFor(id).claimRlimit(typ, plugin)
}
Expand Down Expand Up @@ -1227,6 +1252,14 @@ func (o *owners) claimCgroupsPath(plugin string) error {
return nil
}

func (o *owners) claimOomScoreAdj(plugin string) error {
if other := o.oomScoreAdj; other != "" {
return conflict(plugin, other, "oom score adj")
}
o.oomScoreAdj = plugin
return nil
}

func (ro resultOwners) clearAnnotation(id, key string) {
ro.ownersFor(id).clearAnnotation(key)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/adjustment.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ func (a *ContainerAdjustment) SetLinuxCgroupsPath(value string) {
a.Linux.CgroupsPath = value
}

// SetLinuxOomScoreAdj records setting the kernel's Out-Of-Memory (OOM) killer score for a container.
func (a *ContainerAdjustment) SetLinuxOomScoreAdj(value *int) {
a.initLinux()
a.Linux.OomScoreAdj = Int(value) // using Int(value) from ./options.go to optionally allocate a pointer to normalized copy of value
}

//
// Initializing a container adjustment and container update.
//
Expand Down
Loading

0 comments on commit 49d6c9d

Please sign in to comment.