Re: [PATCH v2 0/6] RCU tasks fixes for v6.9

From: Frederic Weisbecker
Date: Mon Feb 26 2024 - 08:56:16 EST


Le Fri, Feb 23, 2024 at 04:43:04PM -0800, Paul E. McKenney a écrit :
> I do indeed mean doing cond_resched() mid-stream.
>
> One way to make this happen would be to do something like this:
>
> struct task_struct_anchor {
> struct list_head tsa_list;
> struct list_head tsa_adjust_list;
> atomic_t tsa_ref; // Or use an appropriate API.
> bool tsa_is_anchor;
> }
>
> Each task structure would contain one of these, though there are a
> number of ways to conserve space if needed.
>
> These anchors would be placed perhaps every 1,000 tasks or so. When a
> traversal encountered one, it could atomic_inc_not_zero() the reference
> count, and if that succeeded, exit the RCU read-side critical section and
> do a cond_resched(). It could then enter a new RCU read-side critical
> section, drop the reference, and continue.
>
> A traveral might container_of() its way from ->tsa_list to the
> task_struct_anchor structure, then if ->tsa_is_anchor is false,
> container_of() its way to the enclosing task structure.
>
> How to maintain proper spacing of the anchors?
>
> One way is to make the traversals do the checking. If the space between a
> pair of anchors was to large or too small, it could add the first of the
> pair to a list to be adjusted. This list could periodically be processed,
> perhaps with more urgency if a huge gap had opened up.
>
> Freeing an anchor requires decrementing the reference count, waiting for
> it to go to zero, removing the anchor, waiting for a grace period (perhaps
> asynchronously), and only then freeing the anchor.
>
> Anchors cannot be moved, only added or removed.
>
> So it is possible. But is it reasonable? ;-)

Wow! And this will need to be done both for process leaders (p->tasks)
and for threads (p->thread_node) :-)