Skip to content

Commit

Permalink
Merge pull request #76 from yylt/pid
Browse files Browse the repository at this point in the history
support pids cgroup
  • Loading branch information
mikebrow authored Aug 6, 2024
2 parents 5fd8cf6 + 1719502 commit a09d0ae
Show file tree
Hide file tree
Showing 8 changed files with 583 additions and 386 deletions.
34 changes: 33 additions & 1 deletion pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package adaptation
import (
"fmt"
"strings"

"github.com/containerd/nri/pkg/api"
)

type result struct {
Expand Down Expand Up @@ -645,7 +647,16 @@ func (r *result) adjustResources(resources *LinuxResources, plugin string) error
container.RdtClass = String(v.GetValue())
reply.RdtClass = String(v.GetValue())
}

if v := resources.GetPids(); v != nil {
if err := r.owners.claimPidsLimit(id, plugin); err != nil {
return err
}
pidv := &api.LinuxPids{
Limit: v.GetLimit(),
}
container.Pids = pidv
reply.Pids = pidv
}
return nil
}

Expand Down Expand Up @@ -820,6 +831,14 @@ func (r *result) updateResources(reply, u *ContainerUpdate, plugin string) error
}
resources.RdtClass = String(v.GetValue())
}
if v := resources.GetPids(); v != nil {
if err := r.owners.claimPidsLimit(id, plugin); err != nil {
return err
}
resources.Pids = &api.LinuxPids{
Limit: v.GetLimit(),
}
}

// update request/reply from copy on success
reply.Linux.Resources = resources.Copy()
Expand Down Expand Up @@ -888,6 +907,7 @@ type owners struct {
cpuRealtimePeriod string
cpusetCpus string
cpusetMems string
pidsLimit string
hugepageLimits map[string]string
blockioClass string
rdtClass string
Expand Down Expand Up @@ -981,6 +1001,10 @@ func (ro resultOwners) claimCpusetMems(id, plugin string) error {
return ro.ownersFor(id).claimCpusetMems(plugin)
}

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

func (ro resultOwners) claimHugepageLimit(id, size, plugin string) error {
return ro.ownersFor(id).claimHugepageLimit(size, plugin)
}
Expand Down Expand Up @@ -1169,6 +1193,14 @@ func (o *owners) claimCpusetMems(plugin string) error {
return nil
}

func (o *owners) claimPidsLimit(plugin string) error {
if other := o.pidsLimit; other != "" {
return conflict(plugin, other, "pids pinning")
}
o.pidsLimit = plugin
return nil
}

func (o *owners) claimHugepageLimit(size, plugin string) error {
if o.hugepageLimits == nil {
o.hugepageLimits = make(map[string]string)
Expand Down
13 changes: 13 additions & 0 deletions pkg/api/adjustment.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ func (a *ContainerAdjustment) SetLinuxCPUSetMems(value string) {
a.Linux.Resources.Cpu.Mems = value
}

// SetLinuxPidLimits records setting the pid max number for a container.
func (a *ContainerAdjustment) SetLinuxPidLimits(value int64) {
a.initLinuxResourcesPids()
a.Linux.Resources.Pids.Limit = value
}

// AddLinuxHugepageLimit records adding a hugepage limit for a container.
func (a *ContainerAdjustment) AddLinuxHugepageLimit(pageSize string, value uint64) {
a.initLinuxResources()
Expand Down Expand Up @@ -302,6 +308,13 @@ func (a *ContainerAdjustment) initLinuxResourcesCPU() {
}
}

func (a *ContainerAdjustment) initLinuxResourcesPids() {
a.initLinuxResources()
if a.Linux.Resources.Pids == nil {
a.Linux.Resources.Pids = &LinuxPids{}
}
}

func (a *ContainerAdjustment) initLinuxResourcesUnified() {
a.initLinuxResources()
if a.Linux.Resources.Unified == nil {
Expand Down
Loading

0 comments on commit a09d0ae

Please sign in to comment.