Re: [PATCH 1/6] rbtree: add rb_find_add_cached() to rbtree.h

From: Peter Zijlstra
Date: Mon Dec 16 2024 - 17:23:02 EST


On Tue, Dec 17, 2024 at 08:43:26AM +1030, Qu Wenruo wrote:
>
>
> 在 2024/12/13 19:36, Peter Zijlstra 写道:
> > On Thu, Dec 12, 2024 at 10:46:18AM -0600, Roger L. Beckermeyer III wrote:
> > > Adds rb_find_add_cached() as a helper function for use with
> > > red-black trees. Used in btrfs to reduce boilerplate code.
> > >
> > > Suggested-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> > > Signed-off-by: Roger L. Beckermeyer III <beckerlee3@xxxxxxxxx>
> >
> > Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
>
> I guess it's fine to merge this change through btrfs tree?

Yeah, I think so. I don't think there's anything else pending for this
file -- its not touched much.

>
> Just curious about the existing cmp() and less() functions, as they only
> accept the exist node as const.
>
> I'm wondering if this is intentional to allow the less/cmp() functions
> to modify the new node if needed.
> As I normally assume such cmp()/less() should never touch any node nor
> its entries.

Oh yeah, they probably should not. I think it's just because the
callchain as a whole does not have const on the new node (for obvious
raisins), and I failed to put it on for the comparators.

You could add it (and fix up the whole tree) and see if anything comes
apart.