Re: [PATCH v4] kernel/fork: beware of __put_task_struct calling context
From: Sebastian Andrzej Siewior
Date: Fri Feb 10 2023 - 11:48:45 EST
On 2023-02-06 17:27:58 [+0100], Oleg Nesterov wrote:
> On 02/06, Sebastian Andrzej Siewior wrote:
> >
> > On 2023-02-06 16:27:12 [+0100], Oleg Nesterov wrote:
> >
> > > > If so why not use it
> > > > unconditionally?
> > >
> > > performance ?
> >
> > All the free() part is moved from the caller into rcu.
>
> sorry, I don't understand,
That callback does mostly free() and it is batched with other free()
invocations. This also is moved away from the caller which _might_
benefit.
> > > And... I still don't like the name of delayed_put_task_struct_rcu() to me
> > > ___put_task_struct_rcu() looks a bit less confusing, note that we already
> > > have delayed_put_task_struct(). But this is minor.
> >
> > So if we do it unconditionally then we could get rid of
> > put_task_struct_rcu_user().
>
> Yes. But the whole purpose of rcu_users is that we want to avoid the unconditional
> rcu grace period before free_task() ?
Oh, this is usage vs rcu_users. Okay, mixed that up.
> Just in case... please note that delayed_put_task_struct() delays
> refcount_sub(t->usage), not free_task().
Just noticed ;)
> Why do we need this? Consider
>
> rcu_read_lock();
>
> task = find-task-in-rcu-protected-list;
>
> // Safe, task->usage can't be zero
> get_task_struct(task);
>
> rcu_read_unlock();
>
>
> > Otherwise we could use put_task_struct_rcu_user() in that timer
> > callback because it will lead to lockdep warnings once printk is fixed.
>
> IIUC there are more in-atomic callers of put_task_struct(). But perhaps
> I misunderstood you...
That is true. So you are saying that we don't what to use RCU for
put_task_struct() unconditionally?
> Oleg.
Sebastian