Re: [PATCH] kfree_rcu() should use the new kfree_bulk() interface for freeing rcu structures

From: Paul E. McKenney
Date: Tue Dec 19 2017 - 15:22:31 EST

On Tue, Dec 19, 2017 at 11:56:30AM -0800, Rao Shoaib wrote:
> On 12/19/2017 11:30 AM, Matthew Wilcox wrote:
> >On Tue, Dec 19, 2017 at 09:52:27AM -0800, rao.shoaib@xxxxxxxxxx wrote:

[ . . . ]

> >I've been doing a lot of thinking about this because I really want a
> >way to kfree_rcu() an object without embedding a struct rcu_head in it.
> >But I see no way to do that today; even if we have an external memory
> >allocation to point to the object to be freed, we have to keep track of
> >the grace periods.
> I am not sure I understand. If you had external memory you can
> easily do that.
> I am exactly doing that, the only reason the RCU structure is needed
> is to get the pointer to the object being freed.

This can be done as long as you are willing to either:

1. Occasionally have kfree_rcu() wait for a grace period.

2. Occasionally have kfree_rcu() allocate memory.

3. Keep the rcu_head, but use it only when you would otherwise
have to accept the above two penalties. (The point of this
is that tracking lists of memory waiting for a grace period
using dense arrays improves cache locality.)

There might be others, and if you come up with one, please don't keep it
a secret. The C++ standards committee insisted on an interface using
option #2 above. (There is also an option to use their equivalent of
an rcu_head.)

Thanx, Paul