* [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt
@ 2025-08-06 19:43 Luis Claudio R. Goncalves
2025-08-11 10:06 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 7+ messages in thread
From: Luis Claudio R. Goncalves @ 2025-08-06 19:43 UTC (permalink / raw)
To: Oleg Nesterov, Peter Zijlstra, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Tejun Heo, David Vernet,
Barret Rhoden, Josh Don, Crystal Wood, linux-kernel,
linux-rt-devel, Juri Lelli, Ben Segall, Dietmar Eggemann,
Ingo Molnar, Mel Gorman, Valentin Schneider, Vincent Guittot,
Thomas Gleixner, Wander Lairson Costa
Commit 8671bad873eb ("sched: Do not call __put_task_struct() on rt
if pi_blocked_on is set") changed the behavior of put_task_struct()
unconditionally, even when PREEMPT_RT was not enabled, in clear mismatch
with the commit description.
Restore the previous behavior of put_task_struct() for the PREEMPT_RT
disabled case.
Fixes: 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set")
Acked-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
---
diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index ea41795a352b..51678a541477 100644
--- a/include/linux/sched/task.h
+++ b/include/linux/sched/task.h
@@ -130,6 +133,16 @@ static inline void put_task_struct(struct task_struct *t)
if (!refcount_dec_and_test(&t->usage))
return;
+ /* In !RT, it is always safe to call __put_task_struct(). */
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
+ static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP);
+
+ lock_map_acquire_try(&put_task_map);
+ __put_task_struct(t);
+ lock_map_release(&put_task_map);
+ return;
+ }
+
/*
* Under PREEMPT_RT, we can't call __put_task_struct
* in atomic context because it will indirectly
@@ -137,10 +150,6 @@ static inline void put_task_struct(struct task_struct *t)
* current process has a mutex enqueued (blocked on
* a PI chain).
*
- * In !RT, it is always safe to call __put_task_struct().
- * Though, in order to simplify the code, resort to the
- * deferred call too.
- *
* call_rcu() will schedule __put_task_struct_rcu_cb()
* to be called in process context.
*
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt
2025-08-06 19:43 [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt Luis Claudio R. Goncalves
@ 2025-08-11 10:06 ` Sebastian Andrzej Siewior
2025-08-11 10:40 ` Oleg Nesterov
0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-08-11 10:06 UTC (permalink / raw)
To: Luis Claudio R. Goncalves
Cc: Oleg Nesterov, Peter Zijlstra, Clark Williams, Steven Rostedt,
Tejun Heo, David Vernet, Barret Rhoden, Josh Don, Crystal Wood,
linux-kernel, linux-rt-devel, Juri Lelli, Ben Segall,
Dietmar Eggemann, Ingo Molnar, Mel Gorman, Valentin Schneider,
Vincent Guittot, Thomas Gleixner, Wander Lairson Costa
On 2025-08-06 16:43:55 [-0300], Luis Claudio R. Goncalves wrote:
> Commit 8671bad873eb ("sched: Do not call __put_task_struct() on rt
> if pi_blocked_on is set") changed the behavior of put_task_struct()
> unconditionally, even when PREEMPT_RT was not enabled, in clear mismatch
> with the commit description.
>
> Restore the previous behavior of put_task_struct() for the PREEMPT_RT
> disabled case.
>
> Fixes: 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set")
> Acked-by: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
> ---
> diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
> index ea41795a352b..51678a541477 100644
> --- a/include/linux/sched/task.h
> +++ b/include/linux/sched/task.h
> @@ -130,6 +133,16 @@ static inline void put_task_struct(struct task_struct *t)
> if (!refcount_dec_and_test(&t->usage))
> return;
>
> + /* In !RT, it is always safe to call __put_task_struct(). */
I don't want to drag this but this comment is obvious for anyone who is
fluent in C. It is just a statement with no explanation.
An important note would be that the atomic context restriction only
apply to PREEMPT_RT and therefore we have this context override for
lockdep below. The other question would be why don't we do this
unconditionally regardless of PREEMPT_RT. The only reason I could find
is that releasing the task here from the "exit path" makes the vmap
stack "earlier" available for reuse.
> + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
> + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP);
> +
> + lock_map_acquire_try(&put_task_map);
> + __put_task_struct(t);
> + lock_map_release(&put_task_map);
> + return;
> + }
> +
> /*
> * Under PREEMPT_RT, we can't call __put_task_struct
> * in atomic context because it will indirectly
> @@ -137,10 +150,6 @@ static inline void put_task_struct(struct task_struct *t)
> * current process has a mutex enqueued (blocked on
> * a PI chain).
> *
> - * In !RT, it is always safe to call __put_task_struct().
> - * Though, in order to simplify the code, resort to the
> - * deferred call too.
> - *
> * call_rcu() will schedule __put_task_struct_rcu_cb()
> * to be called in process context.
> *
>
Sebastian
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt
2025-08-11 10:06 ` Sebastian Andrzej Siewior
@ 2025-08-11 10:40 ` Oleg Nesterov
2025-08-11 11:05 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2025-08-11 10:40 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: Luis Claudio R. Goncalves, Peter Zijlstra, Clark Williams,
Steven Rostedt, Tejun Heo, David Vernet, Barret Rhoden, Josh Don,
Crystal Wood, linux-kernel, linux-rt-devel, Juri Lelli,
Ben Segall, Dietmar Eggemann, Ingo Molnar, Mel Gorman,
Valentin Schneider, Vincent Guittot, Thomas Gleixner,
Wander Lairson Costa
On 08/11, Sebastian Andrzej Siewior wrote:
>
> I don't want to drag this but this comment is obvious for anyone who is
> fluent in C. It is just a statement with no explanation.
> An important note would be that the atomic context restriction only
> apply to PREEMPT_RT and therefore we have this context override for
> lockdep below. The other question would be why don't we do this
> unconditionally regardless of PREEMPT_RT. The only reason I could find
> is that releasing the task here from the "exit path" makes the vmap
> stack "earlier" available for reuse.
Sorry, could you clarify your "other" question?
What exactly do you think we could do regardless of PREEMPT_RT?
Oleg.
>
> > + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
> > + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP);
> > +
> > + lock_map_acquire_try(&put_task_map);
> > + __put_task_struct(t);
> > + lock_map_release(&put_task_map);
> > + return;
> > + }
> > +
> > /*
> > * Under PREEMPT_RT, we can't call __put_task_struct
> > * in atomic context because it will indirectly
> > @@ -137,10 +150,6 @@ static inline void put_task_struct(struct task_struct *t)
> > * current process has a mutex enqueued (blocked on
> > * a PI chain).
> > *
> > - * In !RT, it is always safe to call __put_task_struct().
> > - * Though, in order to simplify the code, resort to the
> > - * deferred call too.
> > - *
> > * call_rcu() will schedule __put_task_struct_rcu_cb()
> > * to be called in process context.
> > *
> >
>
> Sebastian
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt
2025-08-11 10:40 ` Oleg Nesterov
@ 2025-08-11 11:05 ` Sebastian Andrzej Siewior
2025-08-11 11:21 ` Oleg Nesterov
0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-08-11 11:05 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Luis Claudio R. Goncalves, Peter Zijlstra, Clark Williams,
Steven Rostedt, Tejun Heo, David Vernet, Barret Rhoden, Josh Don,
Crystal Wood, linux-kernel, linux-rt-devel, Juri Lelli,
Ben Segall, Dietmar Eggemann, Ingo Molnar, Mel Gorman,
Valentin Schneider, Vincent Guittot, Thomas Gleixner,
Wander Lairson Costa
On 2025-08-11 12:40:34 [+0200], Oleg Nesterov wrote:
> On 08/11, Sebastian Andrzej Siewior wrote:
> >
> > I don't want to drag this but this comment is obvious for anyone who is
> > fluent in C. It is just a statement with no explanation.
> > An important note would be that the atomic context restriction only
> > apply to PREEMPT_RT and therefore we have this context override for
> > lockdep below. The other question would be why don't we do this
> > unconditionally regardless of PREEMPT_RT. The only reason I could find
> > is that releasing the task here from the "exit path" makes the vmap
> > stack "earlier" available for reuse.
>
> Sorry, could you clarify your "other" question?
>
> What exactly do you think we could do regardless of PREEMPT_RT?
Do what we do now and have one free path for task_struct regardless if
PREEMPT_RT is enabled or not. The one via RCU which delays the freeing
until after the grace period.
> Oleg.
Sebastian
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt
2025-08-11 11:05 ` Sebastian Andrzej Siewior
@ 2025-08-11 11:21 ` Oleg Nesterov
2025-08-11 12:15 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2025-08-11 11:21 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: Luis Claudio R. Goncalves, Peter Zijlstra, Clark Williams,
Steven Rostedt, Tejun Heo, David Vernet, Barret Rhoden, Josh Don,
Crystal Wood, linux-kernel, linux-rt-devel, Juri Lelli,
Ben Segall, Dietmar Eggemann, Ingo Molnar, Mel Gorman,
Valentin Schneider, Vincent Guittot, Thomas Gleixner,
Wander Lairson Costa
On 08/11, Sebastian Andrzej Siewior wrote:
>
> On 2025-08-11 12:40:34 [+0200], Oleg Nesterov wrote:
> >
> > What exactly do you think we could do regardless of PREEMPT_RT?
>
> Do what we do now and have one free path for task_struct regardless if
> PREEMPT_RT is enabled or not. The one via RCU which delays the freeing
> until after the grace period.
Ah, got it. I won't really argue, but...
call_rcu() is not free, it obviously delays free_task/etc. To me this
!PREEMPT_RT optimization makes sense.
But lets forget it for the moment. This patch
https://lore.kernel.org/all/aGvTz5VaPFyj0pBV@uudg.org
[PATCH v6] sched: do not call __put_task_struct() on rt if pi_blocked_on is set
removed that optimization by mistake, this doesn't even match the changelog.
I think it should be restored, and this is what the new patch from Luis does.
Then we can discuss this all again and possibly remove it, but this
should be explicitly documented in the changelog.
Oleg.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt
2025-08-11 11:21 ` Oleg Nesterov
@ 2025-08-11 12:15 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-08-11 12:15 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Luis Claudio R. Goncalves, Peter Zijlstra, Clark Williams,
Steven Rostedt, Tejun Heo, David Vernet, Barret Rhoden, Josh Don,
Crystal Wood, linux-kernel, linux-rt-devel, Juri Lelli,
Ben Segall, Dietmar Eggemann, Ingo Molnar, Mel Gorman,
Valentin Schneider, Vincent Guittot, Thomas Gleixner,
Wander Lairson Costa
On 2025-08-11 13:21:20 [+0200], Oleg Nesterov wrote:
> On 08/11, Sebastian Andrzej Siewior wrote:
> >
> > On 2025-08-11 12:40:34 [+0200], Oleg Nesterov wrote:
> > >
> > > What exactly do you think we could do regardless of PREEMPT_RT?
> >
> > Do what we do now and have one free path for task_struct regardless if
> > PREEMPT_RT is enabled or not. The one via RCU which delays the freeing
> > until after the grace period.
>
> Ah, got it. I won't really argue, but...
>
> call_rcu() is not free, it obviously delays free_task/etc. To me this
> !PREEMPT_RT optimization makes sense.
>
> But lets forget it for the moment. This patch
>
> https://lore.kernel.org/all/aGvTz5VaPFyj0pBV@uudg.org
> [PATCH v6] sched: do not call __put_task_struct() on rt if pi_blocked_on is set
>
> removed that optimization by mistake, this doesn't even match the changelog.
> I think it should be restored, and this is what the new patch from Luis does.
>
> Then we can discuss this all again and possibly remove it, but this
> should be explicitly documented in the changelog.
Certainly. I am not saying we should keep it as is. The added comment
appears wrong but I am all for getting this merged and then sorting out
later.
Thank you for spotting this ;)
> Oleg.
Sebastian
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt
@ 2025-08-25 13:50 Luis Claudio R. Goncalves
0 siblings, 0 replies; 7+ messages in thread
From: Luis Claudio R. Goncalves @ 2025-08-25 13:50 UTC (permalink / raw)
To: Oleg Nesterov, Peter Zijlstra, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Tejun Heo, David Vernet,
Barret Rhoden, Josh Don, Crystal Wood, linux-kernel,
linux-rt-devel, Juri Lelli, Ben Segall, Dietmar Eggemann,
Ingo Molnar, Mel Gorman, Valentin Schneider, Vincent Guittot,
Thomas Gleixner, Wander Lairson Costa
Commit 8671bad873eb ("sched: Do not call __put_task_struct() on rt
if pi_blocked_on is set") changed the behavior of put_task_struct()
unconditionally, even when PREEMPT_RT was not enabled, in clear mismatch
with the commit description.
Restore the previous behavior of put_task_struct() for the PREEMPT_RT
disabled case.
Fixes: 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set")
Acked-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
---
Note: This patch is a fix motivated by Oleg Nesterov's question at
https://lore.kernel.org/linux-rt-devel/20250728201441.GA4690@redhat.com/
diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index ea41795a352b..51678a541477 100644
--- a/include/linux/sched/task.h
+++ b/include/linux/sched/task.h
@@ -130,6 +133,16 @@ static inline void put_task_struct(struct task_struct *t)
if (!refcount_dec_and_test(&t->usage))
return;
+ /* In !RT, it is always safe to call __put_task_struct(). */
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
+ static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP);
+
+ lock_map_acquire_try(&put_task_map);
+ __put_task_struct(t);
+ lock_map_release(&put_task_map);
+ return;
+ }
+
/*
* Under PREEMPT_RT, we can't call __put_task_struct
* in atomic context because it will indirectly
@@ -137,10 +150,6 @@ static inline void put_task_struct(struct task_struct *t)
* current process has a mutex enqueued (blocked on
* a PI chain).
*
- * In !RT, it is always safe to call __put_task_struct().
- * Though, in order to simplify the code, resort to the
- * deferred call too.
- *
* call_rcu() will schedule __put_task_struct_rcu_cb()
* to be called in process context.
*
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-25 13:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-06 19:43 [RESEND PATCH] sched: restore the behavior of put_task_struct() for non-rt Luis Claudio R. Goncalves
2025-08-11 10:06 ` Sebastian Andrzej Siewior
2025-08-11 10:40 ` Oleg Nesterov
2025-08-11 11:05 ` Sebastian Andrzej Siewior
2025-08-11 11:21 ` Oleg Nesterov
2025-08-11 12:15 ` Sebastian Andrzej Siewior
-- strict thread matches above, loose matches on Subject: below --
2025-08-25 13:50 Luis Claudio R. Goncalves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).