Skip to content

Commit

Permalink
additional cgroup testing and implementation of cpu-shares (weight in…
Browse files Browse the repository at this point in the history
… systemd)

Signed-off-by: Charlie Doern <cdoern@redhat.com>
  • Loading branch information
cdoern committed Jul 1, 2022
1 parent 178929c commit ae2b542
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/cgroups/cgroups_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func TestResources(t *testing.T) {
var resources configs.Resources
resources.CpuPeriod = 100000
resources.CpuQuota = 100000
resources.CpuShares = 100
resources.CpusetCpus = "0"
resources.CpusetMems = "0"
resources.Memory = 900
resources.MemorySwap = 1000
resources.BlkioWeight = 300
Expand Down
6 changes: 6 additions & 0 deletions pkg/cgroups/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ func resourcesToProps(res *configs.Resources) (map[string]uint64, map[string]str
uMap["CPUQuotaPerSecUSec"] = cpuQuotaPerSecUSec
}

if res.CpuShares != 0 {
// convert from shares to weight. weight only supports 1-10000
wt := (1 + ((res.CpuShares-2)*9999)/262142)
uMap["CPUWeight"] = wt
}

// CPUSet
if res.CpusetCpus != "" {
bits := []byte(res.CpusetCpus)
Expand Down

0 comments on commit ae2b542

Please sign in to comment.