Re: [PATCH v7 2/3] sched/task: Add the put_task_struct_atomic_safe() function

From: Wander Lairson Costa
Date: Thu May 04 2023 - 10:58:30 EST


On Thu, May 4, 2023 at 11:34 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Thu, May 04, 2023 at 02:29:45PM +0200, Oleg Nesterov wrote:
> > On 05/04, Peter Zijlstra wrote:
> > >
> > > Urgh.. that's plenty horrible. And I'm sure everybody plus kitchen sink
> > > has already asked why can't we just rcu free the thing unconditionally.
> > >
> > > Google only found me an earlier version of this same patch set, but I'm
> > > sure we've had that discussion many times over the past several years.
> >
> > Yes... see for example
> >
> > https://lore.kernel.org/lkml/CAHk-=whtj+aSYftniMRG4xvFE8dmmYyrqcJyPmzStsfj5w9r=w@xxxxxxxxxxxxxx/
> >
> > We already have an rcu pass before put_task_struct(zombie), see
> > put_task_struct_rcu_user(), another one look unfortunate.
>
> Ah indeed, it got mentioned there as well. And Linus seems to be arguing
> against doing an rcu free there. So humm..
>
> Then I'm thinking something trivial like so:
>
> static inline void put_task_struct(struct task_struct *t)
> {
> if (!refcount_dec_and_test(&t->usage))
> return;
>
> if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())
> call_rcu(&t->rcu, __put_task_struct_rcu);
>
> __put_task_struct(t);
> }
>

That's what v5 [1] does. What would be the path in this case? Should I
resend it as v8?

> should do, or alternatively use irq_work, which has a much lower
> latency, but meh..
>

Initially, I did that. I switched to call_rcu because the code got much simpler.

[1] https://lore.kernel.org/all/20230210161323.37400-1-wander@xxxxxxxxxx/