Re: [PATCH v9 RESEND 3/3] sched/fair: Allocate cfs_tg_state with percpu allocator
From: Josh Don
Date: Tue Mar 31 2026 - 15:50:17 EST
On Thu, Mar 19, 2026 at 10:52 AM Zecheng Li <zli94@xxxxxxxx> wrote:
>
> From: Zecheng Li <zecheng@xxxxxxxxxx>
>
> To remove the cfs_rq pointer array in task_group, allocate the combined
> cfs_rq and sched_entity using the per-cpu allocator.
>
> This patch implements the following:
>
> - Changes task_group->cfs_rq from struct cfs_rq ** to struct cfs_rq
> __percpu *.
>
> - Updates memory allocation in alloc_fair_sched_group() and
> free_fair_sched_group() to use alloc_percpu() and free_percpu()
> respectively.
>
> - Uses the inline accessor tg_cfs_rq(tg, cpu) with per_cpu_ptr() to
> retrieve the pointer to cfs_rq for the given task group and CPU.
>
> - Replaces direct accesses tg->cfs_rq[cpu] with calls to the new
> tg_cfs_rq(tg, cpu) helper.
>
> - Handles the root_task_group: since struct rq is already a per-cpu
> variable (runqueues), its embedded cfs_rq (rq->cfs) is also per-cpu.
> Therefore, we assign root_task_group.cfs_rq = &runqueues.cfs.
>
> - Cleanup the code in initializing the root task group.
>
> This change places each CPU's cfs_rq and sched_entity in its local
> per-cpu memory area to remove the per-task_group pointer arrays.
>
> Signed-off-by: Zecheng Li <zecheng@xxxxxxxxxx>
> Signed-off-by: Zecheng Li <zli94@xxxxxxxx>
> Reviewed-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
> ---
> kernel/sched/core.c | 35 +++++++++++-----------------
> kernel/sched/fair.c | 54 ++++++++++++++++++--------------------------
> kernel/sched/sched.h | 14 ++++++++----
> 3 files changed, 45 insertions(+), 58 deletions(-)
Reviewed-by: Josh Don <joshdon@xxxxxxxxxx>