Re: [PATCH 1/2] Move kfree_call_rcu() to slab_common.c

From: Paul E. McKenney
Date: Thu Jan 04 2018 - 18:47:05 EST


On Thu, Jan 04, 2018 at 03:13:07PM -0800, Matthew Wilcox wrote:
> On Thu, Jan 04, 2018 at 02:18:50PM -0800, Rao Shoaib wrote:
> > > > > > +#define kfree_rcu(ptr, rcu_head_name) \
> > > > > > +    do { \
> > > > > > +        typeof(ptr) __ptr = ptr;    \
> > > > > > +        unsigned long __off = offsetof(typeof(*(__ptr)), \
> > > > > > +                              rcu_head_name); \
> > > > > > +        struct rcu_head *__rptr = (void *)__ptr + __off; \
> > > > > > +        __kfree_rcu(__rptr, __off); \
> > > > > > +    } while (0)
> > > > > why do you want to open code this?
> > > But why are you changing this macro at all? If it was to avoid the
> > > double-mention of "ptr", then you haven't done that.
> > I have -- I do not get the error because ptr is being assigned only one. If
> > you have a better way than let me know and I will be happy to make the
> > change.
>
> But look at the original:
>
> #define kfree_rcu(ptr, rcu_head) \
> __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
> ^^^ ^^^
>
> versus your version:
>
> +#define kfree_rcu(ptr, rcu_head_name) \
> +    do { \
> +        typeof(ptr) __ptr = ptr;    \
> ^^^ ^^^
> +        unsigned long __off = offsetof(typeof(*(__ptr)), \
> +                              rcu_head_name); \
> +        struct rcu_head *__rptr = (void *)__ptr + __off; \
> +        __kfree_rcu(__rptr, __off); \
> +    } while (0)
>
> I don't see the difference.

I was under the impression that typeof did not actually evaluate its
argument, but rather only returned its type. And there are a few macros
with this pattern in mainline.

Or am I confused about what typeof does?

Thanx, Paul