Re: [PATCH 26/94] Maple Tree: Add new data structure

From: Liam Howlett
Date: Fri May 14 2021 - 16:45:24 EST


* Peter Zijlstra <peterz@xxxxxxxxxxxxx> [210514 06:58]:
>
> Cc'ing a moderated list is sodding annoying, dropped it.
>
> On Wed, Apr 28, 2021 at 03:36:02PM +0000, Liam Howlett wrote:
>
> > +struct maple_range_64 {
> > + struct maple_pnode *parent;
> > + unsigned long pivot[MAPLE_RANGE64_SLOTS - 1];
> > + void __rcu *slot[MAPLE_RANGE64_SLOTS];
> > +};
> > +
> > +struct maple_arange_64 {
> > + struct maple_pnode *parent;
> > + unsigned long pivot[MAPLE_ARANGE64_SLOTS - 1];
> > + void __rcu *slot[MAPLE_ARANGE64_SLOTS];
> > + unsigned long gap[MAPLE_ARANGE64_SLOTS];
> > + unsigned char meta;
> > +};
> > +
> > +struct maple_alloc {
> > + unsigned long total;
> > + unsigned char node_count;
> > + unsigned int request_count;
> > + struct maple_alloc *slot[MAPLE_ALLOC_SLOTS];
> > +};
> > +
> > +struct maple_topiary {
> > + struct maple_pnode *parent;
> > + struct maple_enode *next; /* Overlaps the pivot */
> > +};
> > +
> > +enum maple_type {
> > + maple_dense,
> > + maple_leaf_64,
> > + maple_range_64,
> > + maple_arange_64,
> > +};
>
> > +struct maple_node {
> > + union {
> > + struct {
> > + struct maple_pnode *parent;
> > + void __rcu *slot[MAPLE_NODE_SLOTS];
> > + };
> > + struct {
> > + void *pad;
> > + struct rcu_head rcu;
> > + unsigned int ma_flags;
> > + enum maple_type type;
> > + };
> > + struct maple_range_64 mr64;
> > + struct maple_arange_64 ma64;
> > + struct maple_alloc alloc;
> > + };
> > +};
>
> This is somewhat inconsistent; would it make sense to have struct
> maple_dense and struct maple_leaf_64, and maybe even struct maple_free,
> such that one can write:
>
> struct maple_node {
> union {
> /* maple_type: */
> struct maple_dense md;
> struct maple_leaf_64 ml64;
> struct maple_range_64 mr64;
> struct maple_arange_64 ma64;
>
> /* internal, life-time: */
> struct maple_alloc alloc;
> struct maple_free free;
> };
> };
>
> Or something along those lines.
>

The problem I am solving with the anon structs is the resulting C code
looks much cleaner with the anon structs. I could make #defines or
small inline helpers to make the other side pretty, but at the expense
of readability imo. What do you think?