Hello all,
I encountered an issue with the CPU affinity of tasks launched by systemd in a slice, after updating from systemd 254 to by systemd >= 256, on the LTS 5.15.x branch (tested on v5.15.179).
Despite the slice file stipulating AllowedCPUS=2 (and confirming this was set in /sys/fs/cgroup/test.slice/cpuset.cpus) tasks launched in the slice would have the CPU affinity of the system.slice (i.e all by default) rather than 2.
To reproduce:
* Check kernel version and systemd version (I used a debian testing image for testing)
``` # uname -r 5.15.179 # systemctl --version systemd 257 (257.4-3) ... ```
* Create a test.slice with AllowedCPUS=2
``` # cat <<EOF > /usr/lib/systemd/system/test.slice [Unit] Description=Test slice Before=slices.target [Slice] AllowedCPUs=2 [Install] WantedBy=slices.target EOF # systemctl daemon-reload && systemctl start test.slice ```
* Confirm cpuset
``` # cat /sys/fs/cgroup/test.slice/cpuset.cpus 2 ```
* Launch task in slice
``` # systemd-run --slice test.slice yes Running as unit: run-r9187b97c6958498aad5bba213289ac56.service; invocation ID: f470f74047ac43b7a60861d03a7ef6f9 # cat /sys/fs/cgroup/test.slice/run-r9187b97c6958498aad5bba213289ac56.service/cgroup.procs
317 ```
# Check affinity
``` # taskset -pc 317 pid 317's current affinity list: 0-7 ```
This issue is fixed by applying upstream commits:
18f9a4d47527772515ad6cbdac796422566e6440 cgroup/cpuset: Skip spread flags update on v2 and 42a11bf5c5436e91b040aeb04063be1710bb9f9c cgroup/cpuset: Make cpuset_fork() handle CLONE_INTO_CGROUP properly
With these applied:
``` # systemd-run --slice test.slice yes Running as unit: run-r442c444559ff49f48c6c2b8325b3b500.service; invocation ID: 5211167267154e9292cb6b854585cb91 # cat /sys/fs/cgroup/test.slice/run-r442c444559ff49f48c6c2b8325b3b500.service/cgroup.procs 291 # taskset -pc 291 pid 291's current affinity list: 2 ```
Perhaps these are a good candidate for backport onto the 5.15 LTS branch?
Thanks James