Skip to content

Commit cb059fa

Browse files
committed
Experimental support for cgroups v2
Currently one test in the integration specs is failing. Unclear if this is the fault of my docker setup or if this represents an actual issue with how `runc` is being setup. Failure: ``` ------------------------------ • [FAILED] [0.167 seconds] resource limits memory [It] gets OOMed when it exceeds its memory limit /bpm/src/bpm/integration/resource_limits_test.go:116 Timeline >> If this test fails, then make sure you have enabled swap accounting! Details are in the README. Error: failed to start job-process: exit status 1 [FAILED] in [It] - /bpm/src/bpm/integration/resource_limits_test.go:122 @ 06/28/24 22:07:30.852 BEGIN '/bpmtmp/resource-limits-test1115196611/sys/log/0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2/0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2.stderr.log' time="2024-06-28T22:07:30Z" level=warning msg="unable to get oom kill count" error="openat2 /sys/fs/cgroup/bpm-0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2/memory.events: no such file or directory" time="2024-06-28T22:07:30Z" level=error msg="runc run failed: unable to start container process: unable to apply cgroup configuration: cannot enter cgroupv2 \"/sys/fs/cgroup/bpm-0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2\" with domain controllers -- it is in an invalid state" END '/bpmtmp/resource-limits-test1115196611/sys/log/0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2/0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2.stderr.log' BEGIN '/bpmtmp/resource-limits-test1115196611/sys/log/0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2/0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2.stdout.log' END '/bpmtmp/resource-limits-test1115196611/sys/log/0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2/0cf7c73a-0b65-4f46-90a7-eb0bb809e6c2.stdout.log' << Timeline [FAILED] Expected <int>: 1 to match exit code: <int>: 0 In [It] at: /bpm/src/bpm/integration/resource_limits_test.go:122 @ 06/28/24 22:07:30.852 ------------------------------ •••••••••••••••••••••••••• ------------------------------ • [FAILED] [0.364 seconds] start when a broken runc configuration is left on the system [It] `bpm start` cleans up the broken-ness and starts it /bpm/src/bpm/integration/start_test.go:329 Timeline >> Error: failed to start job-process: exit status 1 [FAILED] in [It] - /bpm/src/bpm/integration/start_test.go:337 @ 06/28/24 22:07:31.915 BEGIN '/bpmtmp/start-test2475062763/sys/log/e599a26c-5d89-421d-a740-04dd490c314b/e599a26c-5d89-421d-a740-04dd490c314b.stdout.log' en_US.UTF-8 Logging to STDOUT Received a TERM signal END '/bpmtmp/start-test2475062763/sys/log/e599a26c-5d89-421d-a740-04dd490c314b/e599a26c-5d89-421d-a740-04dd490c314b.stdout.log' BEGIN '/bpmtmp/start-test2475062763/sys/log/e599a26c-5d89-421d-a740-04dd490c314b/e599a26c-5d89-421d-a740-04dd490c314b.stderr.log' Logging to STDERR [WARN tini (1)] Reaped zombie process with pid=8 time="2024-06-28T22:07:31Z" level=error msg="runc run failed: unable to get cgroup PIDs: read /sys/fs/cgroup/bpm-e599a26c-5d89-421d-a740-04dd490c314b/cgroup.procs: operation not supported" END '/bpmtmp/start-test2475062763/sys/log/e599a26c-5d89-421d-a740-04dd490c314b/e599a26c-5d89-421d-a740-04dd490c314b.stderr.log' << Timeline [FAILED] Expected <int>: 1 to match exit code: <int>: 0 In [It] at: /bpm/src/bpm/integration/start_test.go:337 @ 06/28/24 22:07:31.915 ------------------------------ ••••••••••••••••••••••••••••• Summarizing 2 Failures: [FAIL] resource limits memory [It] gets OOMed when it exceeds its memory limit /bpm/src/bpm/integration/resource_limits_test.go:122 [FAIL] start when a broken runc configuration is left on the system [It] `bpm start` cleans up the broken-ness and starts it /bpm/src/bpm/integration/start_test.go:337 Ran 69 of 69 Specs in 27.622 seconds FAIL! -- 67 Passed | 2 Failed | 0 Pending | 0 Skipped ```
1 parent d89fe9f commit cb059fa

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/bpm/cgroups/cgroup.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import (
3232
const cgroupRoot = "/sys/fs/cgroup"
3333

3434
func Setup() error {
35+
if cgroups.IsCgroup2UnifiedMode() {
36+
return nil
37+
}
38+
3539
mounts, err := mountinfo.GetMounts(mountinfo.ParentsFilter(cgroupRoot))
3640
if err != nil {
3741
return fmt.Errorf("unable to retrieve mounts: %s", err)

src/bpm/sysfeat/sysfeat.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import (
2525
)
2626

2727
const (
28-
swapPath = "memory.memsw.limit_in_bytes"
28+
swapPathCgroup1 = "memory.memsw.limit_in_bytes"
29+
swapPathCgroup2 = "memory.swap.max"
30+
31+
unifiedMountpoint = "/sys/fs/cgroup"
32+
hybridMountpoint = "/sys/fs/cgroup/unified"
2933
)
3034

3135
// Features contains information about what features the host system supports.
@@ -35,17 +39,43 @@ type Features struct {
3539
}
3640

3741
func Fetch() (*Features, error) {
38-
mountpoint, err := cgroups.FindCgroupMountpoint("", "memory")
42+
supported, err := swapLimitSupported()
3943
if err != nil {
4044
return nil, err
4145
}
4246

4347
return &Features{
44-
SwapLimitSupported: swapLimitSupported(mountpoint),
48+
SwapLimitSupported: supported,
4549
}, nil
4650
}
4751

48-
func swapLimitSupported(mount string) bool {
49-
_, err := os.Stat(filepath.Join(mount, swapPath))
50-
return err == nil
52+
func swapLimitSupported() (bool, error) {
53+
if cgroups.IsCgroup2UnifiedMode() {
54+
return swapLimitSupportedCgroup2()
55+
}
56+
57+
return swapLimitSupportedCgroup1()
58+
}
59+
60+
func swapLimitSupportedCgroup2() (bool, error) {
61+
mountpoint := unifiedMountpoint
62+
if cgroups.IsCgroup2HybridMode() {
63+
mountpoint = hybridMountpoint
64+
}
65+
66+
if cgroups.PathExists(filepath.Join(mountpoint, swapPathCgroup2)) {
67+
return true, nil
68+
}
69+
70+
return false, nil
71+
}
72+
73+
func swapLimitSupportedCgroup1() (bool, error) {
74+
mountPoint, err := cgroups.FindCgroupMountpoint("", "memory")
75+
if err != nil {
76+
return false, err
77+
}
78+
79+
_, err = os.Stat(filepath.Join(mountPoint, swapPathCgroup1))
80+
return err == nil, nil
5181
}

0 commit comments

Comments
 (0)