-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
cgroup2: split fs2 from fs #2169
Conversation
Test script: #!/bin/sh
x(){
echo + "$@"
"$@"
}
for runtime in /usr/local/bin/crun /usr/local/sbin/runc; do
echo "=== RUNTIME $runtime ==="
for manager in cgroupfs systemd; do
echo "= MANAGER $manager ="
x sudo podman --runtime=$runtime --cgroup-manager=$manager run -d --name tmp -v /:/host --device /dev/sda1 --cgroupns=host --pids-limit=10 alpine top
x sudo podman exec tmp cat /proc/self/cgroup
x sudo podman exec tmp sh -c 'echo should be 10; cat /sys/fs/cgroup$(cat /proc/self/cgroup | sed -e s/0:://g)/pids.max'
x sudo podman exec tmp sh -c 'echo should fail; hexdump -C /host/dev/sda | head -n 1'
x sudo podman exec tmp sh -c 'echo should succeed; hexdump -C /host/dev/sda1 | head -n 1'
x sudo podman rm -f tmp
done
echo "= MANAGER cgroupfs (rootless) ="
x podman --runtime=$runtime --cgroup-manager=cgroupfs run --rm --cgroupns=host alpine cat /proc/self/cgroup
# runc+systemd+rootless is not supported yet (#2163)
done result (working as expected): === RUNTIME /usr/local/bin/crun ===
= MANAGER cgroupfs =
+ sudo podman --runtime=/usr/local/bin/crun --cgroup-manager=cgroupfs run -d --name tmp -v /:/host --device /dev/sda1 --cgroupns=host --pids-limit=10 alpine top
5bd05442b7b72d4dbe16a8ded0c1c8ac1b2a2a22ca1f50363f23d66f2371347e
+ sudo podman exec tmp cat /proc/self/cgroup
0::/libpod_parent/libpod-5bd05442b7b72d4dbe16a8ded0c1c8ac1b2a2a22ca1f50363f23d66f2371347e
+ sudo podman exec tmp sh -c echo should be 10; cat /sys/fs/cgroup$(cat /proc/self/cgroup | sed -e s/0:://g)/pids.max
should be 10
10
+ sudo podman exec tmp sh -c echo should fail; hexdump -C /host/dev/sda | head -n 1
should fail
hexdump: /host/dev/sda: Operation not permitted
hexdump: /host/dev/sda: Bad file descriptor
+ sudo podman exec tmp sh -c echo should succeed; hexdump -C /host/dev/sda1 | head -n 1
should succeed
00000000 eb 58 90 6d 6b 66 73 2e 66 61 74 00 02 08 20 00 |.X.mkfs.fat... .|
+ sudo podman rm -f tmp
5bd05442b7b72d4dbe16a8ded0c1c8ac1b2a2a22ca1f50363f23d66f2371347e
= MANAGER systemd =
+ sudo podman --runtime=/usr/local/bin/crun --cgroup-manager=systemd run -d --name tmp -v /:/host --device /dev/sda1 --cgroupns=host --pids-limit=10 alpine top
b7f24f4c38258791ba7a7cccc2967e4e8bd3141c9043fb9755888d06e13dbee6
+ sudo podman exec tmp cat /proc/self/cgroup
0::/machine.slice/libpod-b7f24f4c38258791ba7a7cccc2967e4e8bd3141c9043fb9755888d06e13dbee6.scope
+ sudo podman exec tmp sh -c echo should be 10; cat /sys/fs/cgroup$(cat /proc/self/cgroup | sed -e s/0:://g)/pids.max
should be 10
10
+ sudo podman exec tmp sh -c echo should fail; hexdump -C /host/dev/sda | head -n 1
should fail
hexdump: /host/dev/sda: Operation not permitted
hexdump: /host/dev/sda: Bad file descriptor
+ sudo podman exec tmp sh -c echo should succeed; hexdump -C /host/dev/sda1 | head -n 1
should succeed
00000000 eb 58 90 6d 6b 66 73 2e 66 61 74 00 02 08 20 00 |.X.mkfs.fat... .|
+ sudo podman rm -f tmp
b7f24f4c38258791ba7a7cccc2967e4e8bd3141c9043fb9755888d06e13dbee6
= MANAGER cgroupfs (rootless) =
+ podman --runtime=/usr/local/bin/crun --cgroup-manager=cgroupfs run --rm --cgroupns=host alpine cat /proc/self/cgroup
0::/user.slice/user-1001.slice/[email protected]/user.slice/podman-40576.scope
=== RUNTIME /usr/local/sbin/runc ===
= MANAGER cgroupfs =
+ sudo podman --runtime=/usr/local/sbin/runc --cgroup-manager=cgroupfs run -d --name tmp -v /:/host --device /dev/sda1 --cgroupns=host --pids-limit=10 alpine top
d1ca9ac588f32ad168420348734ccf1323d8bdf37d8f1fcee33e0520fea40e28
+ sudo podman exec tmp cat /proc/self/cgroup
0::/libpod_parent/libpod-d1ca9ac588f32ad168420348734ccf1323d8bdf37d8f1fcee33e0520fea40e28
+ sudo podman exec tmp sh -c echo should be 10; cat /sys/fs/cgroup$(cat /proc/self/cgroup | sed -e s/0:://g)/pids.max
should be 10
10
+ sudo podman exec tmp sh -c echo should fail; hexdump -C /host/dev/sda | head -n 1
should fail
hexdump: /host/dev/sda: Operation not permitted
hexdump: /host/dev/sda: Bad file descriptor
+ sudo podman exec tmp sh -c echo should succeed; hexdump -C /host/dev/sda1 | head -n 1
should succeed
00000000 eb 58 90 6d 6b 66 73 2e 66 61 74 00 02 08 20 00 |.X.mkfs.fat... .|
+ sudo podman rm -f tmp
d1ca9ac588f32ad168420348734ccf1323d8bdf37d8f1fcee33e0520fea40e28
= MANAGER systemd =
+ sudo podman --runtime=/usr/local/sbin/runc --cgroup-manager=systemd run -d --name tmp -v /:/host --device /dev/sda1 --cgroupns=host --pids-limit=10 alpine top
e96d5cff6ac7a27cacd13bc24207c167e707b86bbdb42904a3b20659b3910ddf
+ sudo podman exec tmp cat /proc/self/cgroup
0::/machine.slice/libpod-e96d5cff6ac7a27cacd13bc24207c167e707b86bbdb42904a3b20659b3910ddf.scope
+ sudo podman exec tmp sh -c echo should be 10; cat /sys/fs/cgroup$(cat /proc/self/cgroup | sed -e s/0:://g)/pids.max
should be 10
10
+ sudo podman exec tmp sh -c echo should fail; hexdump -C /host/dev/sda | head -n 1
should fail
hexdump: /host/dev/sda: Operation not permitted
hexdump: /host/dev/sda: Bad file descriptor
+ sudo podman exec tmp sh -c echo should succeed; hexdump -C /host/dev/sda1 | head -n 1
should succeed
00000000 eb 58 90 6d 6b 66 73 2e 66 61 74 00 02 08 20 00 |.X.mkfs.fat... .|
+ sudo podman rm -f tmp
e96d5cff6ac7a27cacd13bc24207c167e707b86bbdb42904a3b20659b3910ddf
= MANAGER cgroupfs (rootless) =
+ podman --runtime=/usr/local/sbin/runc --cgroup-manager=cgroupfs run --rm --cgroupns=host alpine cat /proc/self/cgroup
0::/user.slice/user-1001.slice/[email protected]/user.slice/podman-41213.scope |
@giuseppe @filbranden PTAL? This PR is large, but almost all changes are in |
Thanks @AkihiroSuda! I'm out this weekend and I'll be back on Tuesday. I'll give this PR my full attention when I'm back. Cheers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this a bit and it works for me.
Also took a closer look at the code. Overall, everything looks good, I have a few nitpicks but mostly minor.
I really wonder about memory.high
vs. memory.low
, but looks like that's pre-existing, we can probably address that one in a follow up if needed.
Cheers!
Filipe
bcea75a
to
2ddb057
Compare
split fs2 package from fs, as mixing up fs and fs2 is very likely to result in unmaintainable code. Inspired by containerd/cgroups#109 Fix opencontainers#2157 Signed-off-by: Akihiro Suda <[email protected]>
Signed-off-by: Akihiro Suda <[email protected]>
I guess the fix for #2175 should be split off from this PR (seeing that the CI is currently broken, resp. how long PRs can take to be reviewed)? |
I tried to do that, but it was hard because the v1 codes and the v2 codes are entangled complicatedly on the git master. |
…#2169 gets merged) CI seems to have been broken due to some bad rebase during merging multiple cgroup2 PRs: opencontainers#2175 The failure is being fixed in opencontainers#2169, but still waiting for review. This PR updates .travis.yml to ignore the failure as a workaround until opencontainers#2169 gets merged. This PR can be closed if opencontainers#2169 can get merged right now (and that's even better). Signed-off-by: Akihiro Suda <[email protected]>
@mrunalp PTAL? |
A new method was added to the cgroup interface when opencontainers#2177 was merged. After opencontainers#2177 got merged, opencontainers#2169 was merged without rebase (sorry!) and compilation was failing: libcontainer/cgroups/fs2/fs2.go:208:22: container.Cgroup undefined (type *configs.Config has no field or method Cgroup) Signed-off-by: Akihiro Suda <[email protected]>
follow-up: #2206 |
A new method was added to the cgroup interface when opencontainers#2177 was merged. After opencontainers#2177 got merged, opencontainers#2169 was merged without rebase (sorry!) and compilation was failing: libcontainer/cgroups/fs2/fs2.go:208:22: container.Cgroup undefined (type *configs.Config has no field or method Cgroup) Signed-off-by: Akihiro Suda <[email protected]>
split fs2 package from fs, as mixing up fs and fs2 is very likely to result in
unmaintainable code.
Inspired by containerd/cgroups#109
Fix #2157
Signed-off-by: Akihiro Suda [email protected]
This PR is large, but almost all changes are in
libcontainer/cgroups/fs2
andlibcontainer/cgroups/systemd/unified_hierarchy.go
.Other changes are just for deduplicating files across
cgroups/fs
andcgroups/fs2
.