From nobody Fri Apr 3 08:56:14 2026 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C078F3F166E for ; Thu, 19 Mar 2026 17:52:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773942767; cv=none; b=IISLWHiJWvlZf4FuYsrogEixpowZW/pA7Y/+P62Jd+Z6/kh+VcTn6wymzOEIYQnhE6zwMXdBxFn3qc1+FSwz9IHDdAlMCThVrrdcn8RaKS9+Qzs9AAI3iEygI13GHj0eeGIqP9of5/sVuBSvPvu1sHaZUWQLyWfnUcJaNH+FXq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773942767; c=relaxed/simple; bh=q0ND4yMrmH1YomFb9IGsMzFWWV+rd3Ua1sZmJ42tbV4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j3swmqBpmiJPd6NX87OmyyPM7GHC8x26yS1MP5Rjfk9XksXn0Ul3e0npQOjXjfMp+z4tz1YxSxS4NAVmrhkvtYzZXwSijKWntg+2dnTGYdXgUCZzwzp8qmM7leld4DQ7mjNQUlSGo/rigrkLv4luSkxxskMkSNH99M8tSM0sB8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ncsu.edu; spf=pass smtp.mailfrom=ncsu.edu; dkim=pass (2048-bit key) header.d=ncsu.edu header.i=@ncsu.edu header.b=PBqEq1Aa; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ncsu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ncsu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ncsu.edu header.i=@ncsu.edu header.b="PBqEq1Aa" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-79827d28fc4so12246187b3.1 for ; Thu, 19 Mar 2026 10:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1773942760; x=1774547560; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vSfyDfjcn1C7mC/PR2RRKlXH5W58p8V5M3927Neltqs=; b=PBqEq1AaLu4Jf5R9hmbckDM5iowbQnfwFOpwWxrYGWaPtVyivpTI0mn4gYM/BZRNLQ q/h8cPmawLeb7c/jypRmMjfxak7DjuB8fOQTkUC5gE6M99DEBqXPH173b61Zo2RV2YXZ ycKSvcx2tk40w+xB8S2Ed0DebVDtiy+mKKf6idUmYIJamadocG1OUmjkSL4wUapqI1In 3FM4IYnn0/MVLrKRXn41ErojJJFPW6WNWEqHxTpwqduNrp5/BXDicYiD+MOb6hsP2gSA xGA8/dOOc3dGZIWYjkQ/BfhZUwu5/B92g2AhL3cr8ysUaRb2NW2Rw1jegmazw0PLGjmr ml4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773942760; x=1774547560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vSfyDfjcn1C7mC/PR2RRKlXH5W58p8V5M3927Neltqs=; b=m4VfQGRYh2jbW8OwO/jPTeI89q0f+m8FvpP7rtVDIhWN0mYkZXGD6QJhFeEvZeoQ0/ BQTNqBMg0Wmrl2ZH9nuwAQBejQ8aSKYlnF/pJoW7lr25XGl2d6kWpKiuwCDjZFywuFNL WZre1xxBEX3McqrOs/p+pUqk/wZrqiyzejUj2vvnVDRoTejoPWspEBDIEBgiIBGo954Q H7kq4ithFYkIgt1sx3oJHwyVeJJHQ+KdXvTDXCBU/2nos7t37MXQAoXQhVwboOhZ1psc cP7GOKbS8nR1QEKTIYHoWqhWcks2s177I10W993jgTyBYRCS+e9v0rz309U/tImm+ULe Im9g== X-Forwarded-Encrypted: i=1; AJvYcCX6cQatZizB3nVVL70KNW06rwo1L2pnDE2oNKUg07daU3F2UDFQg1wE1gzFEdQOPfqpNUgKGOerBwOFGR0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxx8IeiXXGpR17uG9/UMph1ukcRMctn7SsPxi86l8yepxAeT/d6 EForaYKFOgTX+FLVpqnuTwzvzWuK/sFDy7jwMvGdjqltHCEraz4qZzVzp777cYz6Wg== X-Gm-Gg: ATEYQzyhmtOV0Q9Fv6hAillqzffSITh0BIl+ut3xfFyx0IOi1KVqKX92rKnPQsHQX7E vj6gS+y2Vu2Jkaue08DsZvKpSygaSa6cwt+oOq5Fn+rN5vVeE+AhaADiMzeyaRGFaN5zhhLDAkU unEoU+HbmTN61vntqOpyVp5IB8pSoVhBApozULvJq0XIi/lIFNoUEREaQTvDU/fsLRvCQpWVtJd Z9IV5zKUtYYQMPK6WQGgdEKHd/L432pXtyL6LzBiegYraoGpCDjDBZHK1COhbRbq3m+SgIAuv+8 c/SkNrffhE0xJBk0b8RNOOl9eFx291U5qKg3101yvcHtFNhJkEEq9XroSCujNOVkkJ1K/Ij4Vd1 o1r2+gItyJHnmnADFQshscVZgN5LiB0F/xvaQKjYkCv+93EDBsuccv4L1uxwD3zAMacSDScraYE bu8buIKBP2JzY5nMD2hVA7OCG9gtvZzBJ8Pfj37HnkArulbs4vxWdOnov3 X-Received: by 2002:a05:690c:f09:b0:798:56eb:f238 with SMTP id 00721157ae682-79a71ade0b4mr83808197b3.36.1773942760222; Thu, 19 Mar 2026 10:52:40 -0700 (PDT) Received: from um773-cachyos.sd.ncsu.edu ([152.7.255.206]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79a905bda3esm784667b3.47.2026.03.19.10.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 10:52:39 -0700 (PDT) From: Zecheng Li To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Rik van Riel , Chris Mason , Madadi Vineeth Reddy , Xu Liu , Blake Jones , Josh Don , Nilay Vaish , K Prateek Nayak , Andrew Morton , linux-kernel@vger.kernel.org, Zecheng Li , Zecheng Li Subject: [PATCH v9 RESEND 2/3] sched/fair: Remove task_group->se pointer array Date: Thu, 19 Mar 2026 13:52:14 -0400 Message-ID: <20260319175235.995183-3-zli94@ncsu.edu> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260319175235.995183-1-zli94@ncsu.edu> References: <20260319175235.995183-1-zli94@ncsu.edu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zecheng Li Now that struct sched_entity is co-located with struct cfs_rq for non-root task groups, the task_group->se pointer array is redundant. The associated sched_entity can be loaded directly from the cfs_rq. This patch performs the access conversion with the helpers: - is_root_task_group(tg): checks if a task group is the root task group. It compares the task group's address with the global root_task_group variable. - tg_se(tg, cpu): retrieves the cfs_rq and returns the address of the co-located se. This function checks if tg is the root task group to ensure behaving the same of previous tg->se[cpu]. Replaces all accesses that use the tg->se[cpu] pointer array with calls to the new tg_se(tg, cpu) accessor. - cfs_rq_se(cfs_rq): simplifies access paths like cfs_rq->tg->se[...] to use the co-located sched_entity. This function also checks if tg is the root task group to ensure same behavior. Since tg_se is not in very hot code paths, and the branch is a register comparison with an immediate value (`&root_task_group`), the performance impact is expected to be negligible. Signed-off-by: Zecheng Li Signed-off-by: Zecheng Li Reviewed-by: K Prateek Nayak Reviewed-by: Josh Don --- kernel/sched/core.c | 7 ++----- kernel/sched/debug.c | 2 +- kernel/sched/fair.c | 25 +++++++++---------------- kernel/sched/sched.h | 31 ++++++++++++++++++++++++++----- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 64b467c1d5b6..2df42786f780 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8609,7 +8609,7 @@ void __init sched_init(void) wait_bit_init(); =20 #ifdef CONFIG_FAIR_GROUP_SCHED - ptr +=3D 2 * nr_cpu_ids * sizeof(void **); + ptr +=3D nr_cpu_ids * sizeof(void **); #endif #ifdef CONFIG_RT_GROUP_SCHED ptr +=3D 2 * nr_cpu_ids * sizeof(void **); @@ -8618,9 +8618,6 @@ void __init sched_init(void) ptr =3D (unsigned long)kzalloc(ptr, GFP_NOWAIT); =20 #ifdef CONFIG_FAIR_GROUP_SCHED - root_task_group.se =3D (struct sched_entity **)ptr; - ptr +=3D nr_cpu_ids * sizeof(void **); - root_task_group.cfs_rq =3D (struct cfs_rq **)ptr; ptr +=3D nr_cpu_ids * sizeof(void **); =20 @@ -9697,7 +9694,7 @@ static int cpu_cfs_stat_show(struct seq_file *sf, voi= d *v) int i; =20 for_each_possible_cpu(i) { - stats =3D __schedstats_from_se(tg->se[i]); + stats =3D __schedstats_from_se(tg_se(tg, i)); ws +=3D schedstat_val(stats->wait_sum); } =20 diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index 6246008c431e..7e7860d56b4b 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -750,7 +750,7 @@ void dirty_sched_domain_sysctl(int cpu) #ifdef CONFIG_FAIR_GROUP_SCHED static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task= _group *tg) { - struct sched_entity *se =3D tg->se[cpu]; + struct sched_entity *se =3D tg_se(tg, cpu); =20 #define P(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F) #define P_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld\n", \ diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 79160d419c9f..c116e7c2b916 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6212,7 +6212,7 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq) { struct rq *rq =3D rq_of(cfs_rq); struct cfs_bandwidth *cfs_b =3D tg_cfs_bandwidth(cfs_rq->tg); - struct sched_entity *se =3D cfs_rq->tg->se[cpu_of(rq)]; + struct sched_entity *se =3D cfs_rq_se(cfs_rq); =20 /* * It's possible we are called with runtime_remaining < 0 due to things @@ -10067,7 +10067,6 @@ static bool __update_blocked_fair(struct rq *rq, bo= ol *done) { struct cfs_rq *cfs_rq, *pos; bool decayed =3D false; - int cpu =3D cpu_of(rq); =20 /* * Iterates the task_group tree in a bottom up fashion, see @@ -10087,7 +10086,7 @@ static bool __update_blocked_fair(struct rq *rq, bo= ol *done) } =20 /* Propagate pending load changes to the parent, if any: */ - se =3D cfs_rq->tg->se[cpu]; + se =3D cfs_rq_se(cfs_rq); if (se && !skip_blocked_update(se)) update_load_avg(cfs_rq_of(se), se, UPDATE_TG); =20 @@ -10113,8 +10112,7 @@ static bool __update_blocked_fair(struct rq *rq, bo= ol *done) */ static void update_cfs_rq_h_load(struct cfs_rq *cfs_rq) { - struct rq *rq =3D rq_of(cfs_rq); - struct sched_entity *se =3D cfs_rq->tg->se[cpu_of(rq)]; + struct sched_entity *se =3D cfs_rq_se(cfs_rq); unsigned long now =3D jiffies; unsigned long load; =20 @@ -13880,7 +13878,6 @@ void free_fair_sched_group(struct task_group *tg) } =20 kfree(tg->cfs_rq); - kfree(tg->se); } =20 int alloc_fair_sched_group(struct task_group *tg, struct task_group *paren= t) @@ -13893,9 +13890,6 @@ int alloc_fair_sched_group(struct task_group *tg, s= truct task_group *parent) tg->cfs_rq =3D kzalloc_objs(cfs_rq, nr_cpu_ids); if (!tg->cfs_rq) goto err; - tg->se =3D kzalloc_objs(se, nr_cpu_ids); - if (!tg->se) - goto err; =20 tg->shares =3D NICE_0_LOAD; =20 @@ -13910,7 +13904,7 @@ int alloc_fair_sched_group(struct task_group *tg, s= truct task_group *parent) cfs_rq =3D &state->cfs_rq; se =3D &state->se; init_cfs_rq(cfs_rq); - init_tg_cfs_entry(tg, cfs_rq, se, i, parent->se[i]); + init_tg_cfs_entry(tg, cfs_rq, se, i, tg_se(parent, i)); init_entity_runnable_average(se); } =20 @@ -13929,7 +13923,7 @@ void online_fair_sched_group(struct task_group *tg) =20 for_each_possible_cpu(i) { rq =3D cpu_rq(i); - se =3D tg->se[i]; + se =3D tg_se(tg, i); rq_lock_irq(rq, &rf); update_rq_clock(rq); attach_entity_cfs_rq(se); @@ -13946,7 +13940,7 @@ void unregister_fair_sched_group(struct task_group = *tg) =20 for_each_possible_cpu(cpu) { struct cfs_rq *cfs_rq =3D tg->cfs_rq[cpu]; - struct sched_entity *se =3D tg->se[cpu]; + struct sched_entity *se =3D tg_se(tg, cpu); struct rq *rq =3D cpu_rq(cpu); =20 if (se) { @@ -13983,7 +13977,6 @@ void init_tg_cfs_entry(struct task_group *tg, struc= t cfs_rq *cfs_rq, init_cfs_rq_runtime(cfs_rq); =20 tg->cfs_rq[cpu] =3D cfs_rq; - tg->se[cpu] =3D se; =20 /* se could be NULL for root_task_group */ if (!se) @@ -14014,7 +14007,7 @@ static int __sched_group_set_shares(struct task_gro= up *tg, unsigned long shares) /* * We can't change the weight of the root cgroup. */ - if (!tg->se[0]) + if (is_root_task_group(tg)) return -EINVAL; =20 shares =3D clamp(shares, scale_load(MIN_SHARES), scale_load(MAX_SHARES)); @@ -14025,7 +14018,7 @@ static int __sched_group_set_shares(struct task_gro= up *tg, unsigned long shares) tg->shares =3D shares; for_each_possible_cpu(i) { struct rq *rq =3D cpu_rq(i); - struct sched_entity *se =3D tg->se[i]; + struct sched_entity *se =3D tg_se(tg, i); struct rq_flags rf; =20 /* Propagate contribution to hierarchy */ @@ -14076,7 +14069,7 @@ int sched_group_set_idle(struct task_group *tg, lon= g idle) =20 for_each_possible_cpu(i) { struct rq *rq =3D cpu_rq(i); - struct sched_entity *se =3D tg->se[i]; + struct sched_entity *se =3D tg_se(tg, i); struct cfs_rq *grp_cfs_rq =3D tg->cfs_rq[i]; bool was_idle =3D cfs_rq_is_idle(grp_cfs_rq); long idle_task_delta; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 826f21fa3f36..258dc689a535 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -480,8 +480,6 @@ struct task_group { #endif =20 #ifdef CONFIG_FAIR_GROUP_SCHED - /* schedulable entities of this group on each CPU */ - struct sched_entity **se; /* runqueue "owned" by this group on each CPU */ struct cfs_rq **cfs_rq; unsigned long shares; @@ -920,7 +918,8 @@ struct dl_rq { }; =20 #ifdef CONFIG_FAIR_GROUP_SCHED - +/* Check whether a task group is root tg */ +#define is_root_task_group(tg) ((tg) =3D=3D &root_task_group) /* An entity is a task if it doesn't "own" a runqueue */ #define entity_is_task(se) (!se->my_q) =20 @@ -2259,6 +2258,28 @@ struct cfs_tg_state { struct sched_entity se; struct sched_statistics stats; } __no_randomize_layout; + +static inline struct sched_entity *tg_se(struct task_group *tg, int cpu) +{ + struct cfs_tg_state *state; + + if (is_root_task_group(tg)) + return NULL; + + state =3D container_of(tg->cfs_rq[cpu], struct cfs_tg_state, cfs_rq); + return &state->se; +} + +static inline struct sched_entity *cfs_rq_se(struct cfs_rq *cfs_rq) +{ + struct cfs_tg_state *state; + + if (is_root_task_group(cfs_rq->tg)) + return NULL; + + state =3D container_of(cfs_rq, struct cfs_tg_state, cfs_rq); + return &state->se; +} #endif =20 /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups= */ @@ -2271,8 +2292,8 @@ static inline void set_task_rq(struct task_struct *p,= unsigned int cpu) #ifdef CONFIG_FAIR_GROUP_SCHED set_task_rq_fair(&p->se, p->se.cfs_rq, tg->cfs_rq[cpu]); p->se.cfs_rq =3D tg->cfs_rq[cpu]; - p->se.parent =3D tg->se[cpu]; - p->se.depth =3D tg->se[cpu] ? tg->se[cpu]->depth + 1 : 0; + p->se.parent =3D tg_se(tg, cpu); + p->se.depth =3D p->se.parent ? p->se.parent->depth + 1 : 0; #endif =20 #ifdef CONFIG_RT_GROUP_SCHED --=20 2.53.0