Skip to content

Commit 8174ac4

Browse files
committed
CP-50934: fix qemu cgroups to be compatible with cgroupv2
cgroup-v2 doesn't have a 'tasks' file anymore (which refers to threads, not processes). Use cgroup.procs instead which exists on both cgroupv1 and cgroupv2, and would be actually the correct one to use, because we want to move the entire process (even if it has, or will have multiple threads). Tested on cgroup-v1 (XS8): ``` systemd-cgls /sys/fs/cgroup/cpu/vm.slice|grep qemu-dm └─2421656 qemu-dm-22 -machine pc-i440fx-2.10,accel=xen,max-ram-below-4g=40265... ``` And on cgroup-v2 (XS9): ``` systemd-cgls /sys/fs/cgroup/vm.slice|grep qemu-dm └─777450 qemu-dm-511 -machine pc-i440fx-2.10,accel=xen,max-ram-below-4g=4026531… ``` Previously in cgroup-v2 qemu has ended up underneath forkexecd, which is part of control.slice, reducing the amount of CPU available to oxenstored and XAPI, leading to timeouts on busy machines. Signed-off-by: Edwin Török <[email protected]>
1 parent fd52035 commit 8174ac4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ocaml/xenopsd/scripts/qemu-wrapper

+9-4
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,18 @@ def prepare_exec():
9595
# Move to nominated cgroup slice
9696
print("Moving to cgroup slice '%s'" % cgroup_slice)
9797
try:
98-
# Note the default slice uses /sys/fs/cgroup/cpu/tasks but
99-
# other.slice uses /sys/fs/cgroup/cpu/other.slice/tasks.
100-
g = open("/sys/fs/cgroup/cpu/%s/tasks" % cgroup_slice, 'w')
98+
try:
99+
# cgroup-v1 path:
100+
# Note the default slice uses /sys/fs/cgroup/cpu/cgroup.procs but
101+
# other.slice uses /sys/fs/cgroup/cpu/other.slice/cgroup.procs.
102+
g = open("/sys/fs/cgroup/cpu/%s/cgroup.procs" % cgroup_slice, 'w')
103+
except FileNotFoundError:
104+
# cgroup-v2 path:
105+
g = open("/sys/fs/cgroup/%s/cgroup.procs" % cgroup_slice, 'w')
101106
g.write(str(os.getpid()))
102107
g.close()
103108
except IOError as e:
104-
print("Warning: writing pid to '%s' tasks file: %s" \
109+
print("Warning: writing pid to '%s' cgroup.procs file: %s" \
105110
% (cgroup_slice, e))
106111

107112
core_dump_limit = enable_core_dumps()

0 commit comments

Comments
 (0)