From nobody Tue Feb 10 04:13:35 2026 Received: from mail-yx1-f43.google.com (mail-yx1-f43.google.com [74.125.224.43]) (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 BB9E51FECCD for ; Sun, 18 Jan 2026 03:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768707283; cv=none; b=BcfUCqfEPoCRWhcvbC36bF1lJG5UEha3b9DIwPs8ETriFe3l77sTF2ZJs04r5Lbr4Jq1UAxvNme9rQy7JUoYOgL2FSYzNx9LAIKtT12gP5s5qrduTntC3gfZU3b4S3nOYaI7WbvB8oeF5JOmyJaXQUD6sHgn7F0Kg7PnuOvhE7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768707283; c=relaxed/simple; bh=cp3CcsjOowTItZRLs99rQor7AK0AXH9C3064oV2AQLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P3G/eG6PD5vreX07QvUQLX6SG0h6F+WhaUZDsxOhqgSa+q0KMMW6YiHI18qcNu5Qb5sQc75uEINIgqUXEm09JBlG4UmOTwmr4FMHuFuSlhZQi72OR7nPfrQRrFuHZiYJkRFpPg69uATUJNz5HPXrEn36YLuUKESbYZ8YcxX+I5I= 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=cedtpg5J; arc=none smtp.client-ip=74.125.224.43 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="cedtpg5J" Received: by mail-yx1-f43.google.com with SMTP id 956f58d0204a3-644715aad1aso3655620d50.0 for ; Sat, 17 Jan 2026 19:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1768707281; x=1769312081; 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=oeTWICU1rnHmY5pG3T1Iu+H5wz88ZwNtaW//ZDioqfw=; b=cedtpg5J+fcVDqVPV7SOijQ9niiKbr1FiwQozVmHJ54O6J9gSCI0ceXFkMiqkXkdj5 Y/q64uOEHj2Goi3zWuf7XpR+3jAMItgZide24TG9MLru2n9W8vQx6E9027FQgRNoicZd zf8VSSbmKBgJDJ6vLZzzhYPLBNtfaNwZgYNMHOMOWHWXxhOmEJoWXbDNYBeHKvQhzeO+ NXYP8jVokjoyqQFtgOsBnXEWXwna99/iu9RJQMCXpB4AGShhXMmgNVTV9d+7+GBOz7rd aIV00tkxW886gyBVL+c2l6+1LfZlRLYI1TmDwoRXZfvzd7+32w10hpYJCuPAnhj6lpue /icA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768707281; x=1769312081; 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=oeTWICU1rnHmY5pG3T1Iu+H5wz88ZwNtaW//ZDioqfw=; b=siuq06snq2F+ofmYkexyD+tzoY3Dl1BGzXDLv0nayQat08MtVAxthy+8GoC+I96PGY 8WBKnhjOI1E4OHQaLv0ASYtWJA6X+ozEPYmXW8qncG2W+SXgXUZ5330jUrTiQLFT4aV+ noxV+zml9kPxiTAvUIzgdB3FwtG8aN0y1x0kbO0jJA4HnXCUsh2jA7KFxfX9RJ86ljV2 ch5tdMqIsrdFxspG3Prv3c8gdZgPLjRLg6LInSoXWYmYwtrifvgJ2S66RxUe09BwFqPN EVrx5wYsn+PNkwqYUS+B2wjpWpRN3pSMd0acMd5LwcwGLHq0j9XQb2wPnJ1dG0nLlEUK 5hWA== X-Forwarded-Encrypted: i=1; AJvYcCU93IXIGAAdf31eYmygQiSpH9RWRXNjAD2P9AdPRcU2ubR6hb21Gujnql2svNT8fLEqwDQ8DCQgQgYQm58=@vger.kernel.org X-Gm-Message-State: AOJu0YwXbSQzmhq6NxcipE/Xqp3IU2EXjkjS7yVQil2i9dJCb/1xTW3I 5SLn/Td+wt5rOWMGRd6nczvlweRkU44xETVcWn4RZ07CV5aCGmTVVLJTUkNLq32fOQ== X-Gm-Gg: AY/fxX7vF2NStihdxHO6gAm5z/ZiRCuiy1sUqgZhmsxDaNTM0vzRVTCkgelVHZE8H0G o9K5J50KxCmVuJvpS1jf3C0SNQcUiU1LS7xD8KmRK9vQz/L4as/y/hqSLDD+lROOr1buvWA7xiF onK5v/NM3LapW7MNOd3YyUaTHfzBKum3YgqxQ8uGnRnuSL3BT8GnyNVt7UFq9TgOby8gtF6NFJ5 rxY5xrq/J1aiPq55ZSm6e1PXICkmARWTDSQWn2wpM47+dI73dhYN2weM3twlrAivPugyO88ESeY Lwrr+fam6Vf1EUG3p18VZJXtXQDIM1VayOGeDkWIC3HLC92odq7hwD8IoULScDVNsPaCMyO/T0l fPDd68Lyua567cSSIjGiK6UwydQErZBok8Vc9UhSvc8FUBGtKqhC4oe87KLwyDIK0GhZZCliOIZ 3bM1u3cEAoyw== X-Received: by 2002:a05:690e:1919:b0:644:7b19:c207 with SMTP id 956f58d0204a3-64916b7d34emr5698225d50.38.1768707280561; Sat, 17 Jan 2026 19:34:40 -0800 (PST) Received: from um773-cachyos ([2600:1700:cc0:94af:eca6:9ff9:6f3c:5de9]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-649170acbdbsm3235607d50.13.2026.01.17.19.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jan 2026 19:34:39 -0800 (PST) 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 , linux-kernel@vger.kernel.org, Zecheng Li , Zecheng Li Subject: [PATCH v7 1/3] sched/fair: Co-locate cfs_rq and sched_entity in cfs_tg_state Date: Sat, 17 Jan 2026 22:34:11 -0500 Message-ID: <20260118033431.158464-2-zli94@ncsu.edu> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260118033431.158464-1-zli94@ncsu.edu> References: <20260118033431.158464-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 Improve data locality and reduce pointer chasing by allocating struct cfs_rq and struct sched_entity together for non-root task groups. This is achieved by introducing a new combined struct cfs_tg_state that holds both objects in a single allocation. This patch: - Introduces struct cfs_tg_state that embeds cfs_rq, sched_entity, and sched_statistics together in a single structure. - Updates __schedstats_from_se() in stats.h to use cfs_tg_state for accessing sched_statistics from a group sched_entity. - Modifies alloc_fair_sched_group() and free_fair_sched_group() to allocate and free the new struct as a single unit. - Modifies the per-CPU pointers in task_group->se and task_group->cfs_rq to point to the members in the new combined structure. Signed-off-by: Zecheng Li Signed-off-by: Zecheng Li --- kernel/sched/fair.c | 25 +++++++++++-------------- kernel/sched/sched.h | 12 ++++++++++++ kernel/sched/stats.h | 9 +-------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 04993c763a06..0897dab69236 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13617,10 +13617,11 @@ void free_fair_sched_group(struct task_group *tg) int i; =20 for_each_possible_cpu(i) { - if (tg->cfs_rq) - kfree(tg->cfs_rq[i]); - if (tg->se) - kfree(tg->se[i]); + if (tg->cfs_rq && tg->cfs_rq[i]) { + struct cfs_tg_state *state =3D + container_of(tg->cfs_rq[i], struct cfs_tg_state, cfs_rq); + kfree(state); + } } =20 kfree(tg->cfs_rq); @@ -13629,6 +13630,7 @@ void free_fair_sched_group(struct task_group *tg) =20 int alloc_fair_sched_group(struct task_group *tg, struct task_group *paren= t) { + struct cfs_tg_state *state; struct sched_entity *se; struct cfs_rq *cfs_rq; int i; @@ -13645,16 +13647,13 @@ int alloc_fair_sched_group(struct task_group *tg,= struct task_group *parent) init_cfs_bandwidth(tg_cfs_bandwidth(tg), tg_cfs_bandwidth(parent)); =20 for_each_possible_cpu(i) { - cfs_rq =3D kzalloc_node(sizeof(struct cfs_rq), - GFP_KERNEL, cpu_to_node(i)); - if (!cfs_rq) + state =3D kzalloc_node(sizeof(*state), + GFP_KERNEL, cpu_to_node(i)); + if (!state) goto err; =20 - se =3D kzalloc_node(sizeof(struct sched_entity_stats), - GFP_KERNEL, cpu_to_node(i)); - if (!se) - goto err_free_rq; - + 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_entity_runnable_average(se); @@ -13662,8 +13661,6 @@ int alloc_fair_sched_group(struct task_group *tg, s= truct task_group *parent) =20 return 1; =20 -err_free_rq: - kfree(cfs_rq); err: return 0; } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 58c9d244f12b..50b37ed2f7d6 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2191,6 +2191,18 @@ static inline struct task_group *task_group(struct t= ask_struct *p) return p->sched_task_group; } =20 +#ifdef CONFIG_FAIR_GROUP_SCHED +/* + * Defined here to be available before stats.h is included, since + * stats.h has dependencies on things defined later in this file. + */ +struct cfs_tg_state { + struct cfs_rq cfs_rq; + struct sched_entity se; + struct sched_statistics stats; +} __no_randomize_layout; +#endif + /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups= */ static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h index c903f1a42891..63b9a800a354 100644 --- a/kernel/sched/stats.h +++ b/kernel/sched/stats.h @@ -89,19 +89,12 @@ static inline void rq_sched_info_depart (struct rq *rq= , unsigned long long delt =20 #endif /* CONFIG_SCHEDSTATS */ =20 -#ifdef CONFIG_FAIR_GROUP_SCHED -struct sched_entity_stats { - struct sched_entity se; - struct sched_statistics stats; -} __no_randomize_layout; -#endif - static inline struct sched_statistics * __schedstats_from_se(struct sched_entity *se) { #ifdef CONFIG_FAIR_GROUP_SCHED if (!entity_is_task(se)) - return &container_of(se, struct sched_entity_stats, se)->stats; + return &container_of(se, struct cfs_tg_state, se)->stats; #endif return &task_of(se)->stats; } --=20 2.52.0