All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Thomas <james.thomas@codethink.co.uk>
To: stable@vger.kernel.org
Subject: BUG in LTS 5.15.x cpusets with tasks launched by newer systemd
Date: Fri, 21 Mar 2025 13:08:03 +0000	[thread overview]
Message-ID: <d3bbf1997bae30253a7be05c7e2a06fb@codethink.co.uk> (raw)

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

             reply	other threads:[~2025-03-21 13:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-21 13:08 James Thomas [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-03-20 10:07 BUG in LTS 5.15.x cpusets with tasks launched by newer systemd James Thomas
2025-03-20 18:52 ` Waiman Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d3bbf1997bae30253a7be05c7e2a06fb@codethink.co.uk \
    --to=james.thomas@codethink.co.uk \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.