From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Tejun Heo <tj@kernel.org>
Cc: Calvin Owens <calvin@wbinvd.org>,
linux-kernel@vger.kernel.org,
Dan Schatzberg <dschatzberg@meta.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH cgroup/for-6.19] cgroup: Fix sleeping from invalid context warning on PREEMPT_RT
Date: Thu, 6 Nov 2025 16:07:17 +0100 [thread overview]
Message-ID: <20251106150717.cZuPZnF5@linutronix.de> (raw)
In-Reply-To: <aQufmyZ7X7NdfiCL@slm.duckdns.org>
On 2025-11-05 09:03:55 [-1000], Tejun Heo wrote:
> +#ifdef CONFIG_PREEMPT_RT
> +/*
> + * cgroup_task_dead() is called from finish_task_switch() which doesn't allow
> + * scheduling even in RT. As the task_dead path requires grabbing css_set_lock,
> + * this lead to sleeping in the invalid context warning bug. css_set_lock is too
> + * big to become a raw_spinlock. The task_dead path doesn't need to run
> + * synchronously. Bounce through irq_work instead.
> + */
> +static DEFINE_PER_CPU(struct llist_head, cgrp_dead_tasks);
> +static DEFINE_PER_CPU(struct irq_work, cgrp_dead_tasks_iwork);
> +
> +static void cgrp_dead_tasks_iwork_fn(struct irq_work *iwork)
> +{
> + struct llist_node *lnode;
> + struct task_struct *task, *next;
> +
> + lnode = llist_del_all(this_cpu_ptr(&cgrp_dead_tasks));
> + llist_for_each_entry_safe(task, next, lnode, cg_dead_lnode) {
> + do_cgroup_task_dead(task);
> + put_task_struct(task);
> + }
> +}
> +
> +static void __init cgroup_rt_init(void)
> +{
> + int cpu;
> +
> + for_each_possible_cpu(cpu) {
> + init_llist_head(per_cpu_ptr(&cgrp_dead_tasks, cpu));
> + init_irq_work(per_cpu_ptr(&cgrp_dead_tasks_iwork, cpu),
> + cgrp_dead_tasks_iwork_fn);
How important is it, that it happens right away? Written as-is, this
leads to an interrupt then wakes irq_work/$cpu thread which then runs
this callback. That thread runs as SCHED_FIFO-1. This means the
termination of a SCHED_OTHER tasks on a single CPU will run as follows:
- TASK_DEAD
schedule()
- queue IRQ_WORK
-> INTERRUPT
-> WAKE irq_work
-> preempt to irq_work/
-> handle one callback
schedule()
back to next TASK_DEAD
So cgrp_dead_tasks_iwork_fn() will never have to opportunity to batch.
Unless the exiting task's priority is > 1. Then it will be delayed
until all RT tasks are done.
My proposal would be to init the irq_work item with
*per_cpu_ptr(&cgrp_dead_tasks_iwork, cpu) = IRQ_WORK_INIT_LAZY(cgrp_dead_tasks_iwork_fn);
instead which won't raise an IRQ immediately and delay the callback
until the next timer tick. So it could batch multiple tasks.
[ queue_work() should work, too but the overhead to schedule is greater
imho so this makes sense ]
Sebastian
next prev parent reply other threads:[~2025-11-06 15:07 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 18:11 DEBUG_ATOMIC_SLEEP spew in cgroup_task_dead() on next-20251104 Calvin Owens
2025-11-04 19:30 ` Tejun Heo
2025-11-05 15:16 ` Calvin Owens
2025-11-05 19:03 ` [PATCH cgroup/for-6.19] cgroup: Fix sleeping from invalid context warning on PREEMPT_RT Tejun Heo
2025-11-06 1:15 ` Calvin Owens
2025-11-06 17:36 ` Tejun Heo
2025-11-06 15:07 ` Sebastian Andrzej Siewior [this message]
2025-11-06 17:37 ` Tejun Heo
2025-11-06 17:46 ` Sebastian Andrzej Siewior
2025-11-06 17:55 ` Tejun Heo
2025-11-06 18:06 ` Sebastian Andrzej Siewior
2026-02-19 16:46 ` ~90s reboot delay with v6.19 and PREEMPT_RT Bert Karwatzki
2026-02-19 20:53 ` Calvin Owens
2026-02-19 23:10 ` Bert Karwatzki
2026-02-20 0:58 ` Steven Rostedt
2026-02-20 9:15 ` ~90s shutdown " Bert Karwatzki
2026-02-20 15:44 ` Steven Rostedt
2026-02-23 0:35 ` Bert Karwatzki
2026-02-23 8:22 ` Steven Rostedt
2026-02-23 13:36 ` Bert Karwatzki
2026-02-23 23:36 ` Bert Karwatzki
2026-02-24 12:44 ` Bert Karwatzki
2026-02-24 12:58 ` Bert Karwatzki
2026-02-24 14:20 ` Steven Rostedt
2026-02-24 15:45 ` ~90s reboot " Sebastian Andrzej Siewior
2026-02-25 15:43 ` Sebastian Andrzej Siewior
2026-02-25 16:37 ` Bert Karwatzki
2026-02-25 16:59 ` Sebastian Andrzej Siewior
2026-02-25 22:31 ` Sebastian Andrzej Siewior
2026-02-26 13:24 ` Bert Karwatzki
2026-02-26 13:46 ` Sebastian Andrzej Siewior
2026-02-26 16:37 ` Steven Rostedt
2026-02-27 14:13 ` Sebastian Andrzej Siewior
2026-02-27 22:57 ` Bert Karwatzki
2026-03-02 11:15 ` Sebastian Andrzej Siewior
2025-11-04 19:32 ` [PATCH cgroup/for-6.19 1/2] cgroup: Convert css_set_lock from spinlock_t to raw_spinlock_t Tejun Heo
2025-11-05 7:30 ` Sebastian Andrzej Siewior
2025-11-05 16:19 ` Tejun Heo
2025-11-05 8:50 ` Peter Zijlstra
2025-11-05 16:20 ` Tejun Heo
2025-11-04 19:32 ` [PATCH cgroup/for-6.19 2/2] cgroup: Convert css_set_lock locking to use cleanup guards Tejun Heo
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=20251106150717.cZuPZnF5@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=calvin@wbinvd.org \
--cc=dschatzberg@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tj@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®