Re: [PATCH RFC tip/core/rcu 05/41] rcu: Avoid waking up CPUs havingonly kfree_rcu() callbacks

From: Paul E. McKenney
Date: Thu Feb 02 2012 - 11:41:29 EST

On Wed, Feb 01, 2012 at 05:15:52PM -0800, Josh Triplett wrote:
> On Wed, Feb 01, 2012 at 11:41:23AM -0800, Paul E. McKenney wrote:
> > From: "Paul E. McKenney" <paul.mckenney@xxxxxxxxxx>
> >
> > When CONFIG_RCU_FAST_NO_HZ is enabled, RCU will allow a given CPU to
> > enter dyntick-idle mode even if it still has RCU callbacks queued.
> > RCU avoids system hangs in this case by scheduling a timer for several
> > jiffies in the future. However, if all of the callbacks on that CPU
> > are from kfree_rcu(), there is no reason to wake the CPU up, as it is
> > not a problem to defer freeing of memory.
> >
> > This commit therefore tracks the number of callbacks on a given CPU
> > that are from kfree_rcu(), and avoids scheduling the timer if all of
> > a given CPU's callbacks are from kfree_rcu().
> Minor nit: I think it would make much more sense to track the number of
> "strict" callbacks *not* from kfree_rcu, and check for that number != 0,
> rather than tracking the number of "lazy" callbacks from kfree_rcu and
> checking for all != lazy. You can always compute one number from the
> other, but since you only ever need to know the strict count, not the
> lazy count, why not directly track the thing you care about?

I will think about this. My guess is that when I add call_rcu_lazy(),
the naming will outweigh the slowpath subtraction, but will see.

> Also, any way this could hide the new kfree_call_rcu internally rather
> than adding it as a new export? In particular, why introduce a new
> exported API only suitable for internal use or foot-shooting?

It is called from __kfree_rcu, which is a static inline in
include/linux/rcupdate.h, so needs to be exported so that modules can
use kfree_rcu().

Of course, if I take the earlier patch that removes the first
BUILD_BUG_ON() from __kfree_rcu(), then I could move __kfree_rcu()
to rcupdate.c, and then I could move the export from kfree_call_rcu()
to __kfree_rcu(). But either way I would be exporting a function that
should not be invoked directly.

My concern with the earlier patch is that someone might have something
silly like a structure with an array with an rcu_head in each element.
Calling kfree_rcu() on such a beast would be ill-advised. This might
just be me being overly paranoid, though, hence my lack of additional
response to that patch.

Thanx, Paul

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at