Skip to content

Commit

Permalink
Merge pull request #94 from zxj874478410/main-dev
Browse files Browse the repository at this point in the history
Add support for adjusting OOM score adjustment.
  • Loading branch information
mikebrow authored Aug 19, 2024
2 parents c9b4798 + efcb2da commit 30ff2cf
Show file tree
Hide file tree
Showing 6 changed files with 929 additions and 812 deletions.
33 changes: 33 additions & 0 deletions pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,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 @@ -711,6 +714,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 @@ -948,6 +968,7 @@ type owners struct {
rdtClass string
unified map[string]string
cgroupsPath string
oomScoreAdj string
rlimits map[string]string
}

Expand Down Expand Up @@ -1064,6 +1085,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 @@ -1309,6 +1334,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 @@ -264,6 +264,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 30ff2cf

Please sign in to comment.