@@ -2,16 +2,19 @@ package fs2
2
2
3
3
import (
4
4
"bufio"
5
+ "errors"
5
6
"os"
6
7
"strconv"
7
8
9
+ "golang.org/x/sys/unix"
10
+
8
11
"github.com/opencontainers/runc/libcontainer/cgroups"
9
12
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
10
13
"github.com/opencontainers/runc/libcontainer/configs"
11
14
)
12
15
13
16
func isCpuSet (r * configs.Resources ) bool {
14
- return r .CpuWeight != 0 || r .CpuQuota != 0 || r .CpuPeriod != 0 || r .CPUIdle != nil
17
+ return r .CpuWeight != 0 || r .CpuQuota != 0 || r .CpuPeriod != 0 || r .CPUIdle != nil || r . CpuBurst != nil
15
18
}
16
19
17
20
func setCpu (dirPath string , r * configs.Resources ) error {
@@ -32,6 +35,23 @@ func setCpu(dirPath string, r *configs.Resources) error {
32
35
}
33
36
}
34
37
38
+ var burst string
39
+ if r .CpuBurst != nil {
40
+ burst = strconv .FormatUint (* r .CpuBurst , 10 )
41
+ if err := cgroups .WriteFile (dirPath , "cpu.max.burst" , burst ); err != nil {
42
+ // Sometimes when the burst to be set is larger
43
+ // than the current one, it is rejected by the kernel
44
+ // (EINVAL) as old_quota/new_burst exceeds the parent
45
+ // cgroup quota limit. If this happens and the quota is
46
+ // going to be set, ignore the error for now and retry
47
+ // after setting the quota.
48
+ if ! errors .Is (err , unix .EINVAL ) || r .CpuQuota == 0 {
49
+ return err
50
+ }
51
+ } else {
52
+ burst = ""
53
+ }
54
+ }
35
55
if r .CpuQuota != 0 || r .CpuPeriod != 0 {
36
56
str := "max"
37
57
if r .CpuQuota > 0 {
@@ -47,6 +67,11 @@ func setCpu(dirPath string, r *configs.Resources) error {
47
67
if err := cgroups .WriteFile (dirPath , "cpu.max" , str ); err != nil {
48
68
return err
49
69
}
70
+ if burst != "" {
71
+ if err := cgroups .WriteFile (dirPath , "cpu.max.burst" , burst ); err != nil {
72
+ return err
73
+ }
74
+ }
50
75
}
51
76
52
77
return nil
0 commit comments