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

feat: add cpu max burst support #356

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions cgroup2/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ func NewCPUMax(quota *int64, period *uint64) CPUMax {
return CPUMax(strings.Join([]string{max, strconv.FormatUint(*period, 10)}, " "))
}

func NewCPUMaxBurst(burst uint64) string {
return strconv.FormatUint(burst, 10)
}

type CPU struct {
Weight *uint64
Max CPUMax
Cpus string
Mems string
Weight *uint64
Max CPUMax
MaxBurst string
Cpus string
Mems string
}

func (c CPUMax) extractQuotaAndPeriod() (int64, uint64) {
Expand Down Expand Up @@ -79,5 +84,12 @@ func (r *CPU) Values() (o []Value) {
value: r.Mems,
})
}
if r.MaxBurst != "" {
o = append(o, Value{
filename: "cpu.max.burst",
value: r.MaxBurst,
})
}

return o
}
11 changes: 7 additions & 4 deletions cgroup2/cpuv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ func TestCgroupv2CpuStats(t *testing.T) {
group := "/cpu-test-cg"
groupPath := fmt.Sprintf("%s-%d", group, os.Getpid())
var (
burst uint64 = 1000
quota int64 = 10000
period uint64 = 8000
weight uint64 = 100
)

c, err := NewManager(defaultCgroup2Path, groupPath, &Resources{
CPU: &CPU{
Weight: &weight,
Max: NewCPUMax(&quota, &period),
Cpus: "0",
Mems: "0",
Weight: &weight,
Max: NewCPUMax(&quota, &period),
Cpus: "0",
Mems: "0",
MaxBurst: NewCPUMaxBurst(burst),
},
})
require.NoError(t, err, "failed to init new cgroup manager")
Expand All @@ -54,6 +56,7 @@ func TestCgroupv2CpuStats(t *testing.T) {
checkFileContent(t, c.path, "cpu.max", "10000 8000")
checkFileContent(t, c.path, "cpuset.cpus", "0")
checkFileContent(t, c.path, "cpuset.mems", "0")
checkFileContent(t, c.path, "cpu.max.burst", strconv.FormatUint(burst, 10))
}

func TestSystemdCgroupCpuController(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions cgroup2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func ToResources(spec *specs.LinuxResources) *Resources {
if period := cpu.Period; period != nil {
resources.CPU.Max = NewCPUMax(cpu.Quota, period)
}
if burst := cpu.Burst; burst != nil {
resources.CPU.MaxBurst = NewCPUMaxBurst(*burst)
}
}
if mem := spec.Memory; mem != nil {
resources.Memory = &Memory{}
Expand Down