Re: [PATCH 2/3] rbtree: update augmented data on the way down in rb_add_augmented_cached()
From: Peter Zijlstra
Date: Mon Sep 28 2026 - 09:45:45 EST
On Mon, Sep 28, 2026 at 08:26:10PM +0800, Yiwei Lin wrote:
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 7455a83a6a990..60db4624b9897 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1066,9 +1066,20 @@ static inline bool min_vruntime_update(struct sched_entity *se, bool exit)
> se->max_slice == old_max_slice;
> }
>
> +/*
> + * Fold @new's subtree data into @se, for each @se on @new's insertion path.
> + */
> +static inline void
> +min_vruntime_merge(struct sched_entity *se, struct sched_entity *new)
> +{
> + __min_vruntime_update(se, &new->run_node);
> + __min_slice_update(se, &new->run_node);
> + __max_slice_update(se, &new->run_node);
> +}
>
So min_vruntime_update() can be written in terms of this helper like:
static inline bool min_vruntime_update(struct sched_entity *se, bool exit)
{
u64 old_min_vruntime = se->min_vruntime;
u64 old_min_slice = se->min_slice;
u64 old_max_slice = se->max_slice;
struct rb_node *node = &se->run_node;
se->min_vruntime = se->vruntime;
se->min_slice = se->slice;
se->max_slice = se->slice;
min_vruntime_merge(se, node->rb_right);
min_vruntime_merge(se, node->rb_left);
return se->min_vruntime == old_min_vruntime &&
se->min_slice == old_min_slice &&
se->max_slice == old_max_slice;
}
And that is *very* close to being generalizable, obviating the need for
RBCOMPUTE. Does your LLM see a way to make that happen?
That is, for RB_DECLARE_CALLBACKS() and RD_DECLARE_CALLBACKS_MAX() this
is trivially doable, but I'm not sure I see a clean way to make this
happen for RB_DECLARE_CALLBACKS_MULTI().