From nobody Tue Feb 10 15:44:50 2026 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 1D9CD322B60 for ; Mon, 12 Jan 2026 18:51:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768243900; cv=none; b=AG/nCNHwHt9v5Q59XsnZ6/UkOKbS4tCf6tYp9ymExWPQXcu6KdjoB1aS7Zhw1o7+Tws7S0XLFRlzj2G+mszK3X2rPv0gYNnTLbq0K66MZLa2dJsdRsywtuYbfX3OBLKL+w2qp32tjbjZY7UVtg2h9+EN7WbrQCVZmEVI5iohsEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768243900; c=relaxed/simple; bh=oYes/NvT0m1+qVFEg+RSCIN0j7SXE7LfE/k8YDzATL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G0embnU+HDTnZUdkM5amvp9zxb9QmRKa2Bcmdec9EyjR8EsyD93a6CY7O+WAPfX6dnhyCdeoVmNyJGQWXQi9OoF4pJRh/tR5x1PZqJ6HKSObcJtyt4A6zmM/EaoCJoZeDjbcH209PMpRG1sFUAhtMPEPxIvYekhmwaKXPunnNtg= 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=YmGlJmQ3; arc=none smtp.client-ip=209.85.160.180 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="YmGlJmQ3" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-4f4cd02f915so49848531cf.1 for ; Mon, 12 Jan 2026 10:51:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1768243898; x=1768848698; 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=z2jzWoQ0q2iGQ0VZmZ+Mn6NMao0VtZOCyErplWSX6qk=; b=YmGlJmQ3oqgWsKZi6vCgaFowPCSnt7pb0SsZ8JuGlSvgXRmCJ4xapDw1OvA+NyK2kk 5pBntHVj7DzBoYfQym1BWs1JVSPBV6KnoY1UC3Cp8mB8TvUER83mJD/0rUsQtmud3FFD cKNuFoYcK7wJmthz+j4JxCZ6q96SYaayLElxrdXUWoSWoFLSgY5y5HThjhAyxQBAT2J0 /bVUpRwwHDvyHF/o8hvsy2n3JzHPH1fOfrLpj+IZInClwqGb/3yVEX02+7XJGT1D+mE5 T/ZjgYXu4puL5zK3fxgvY6hzQV0SOkRpQMgDkMmkVpkt1sRXr6mUF21Fq2/I1H0y7bGp O4SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768243898; x=1768848698; 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=z2jzWoQ0q2iGQ0VZmZ+Mn6NMao0VtZOCyErplWSX6qk=; b=DTackKY62p2K90L86nZF7byIxUdMlKJ9WVtnNB5K0BMHtDHn8HYy64aMPQuK9IJmfE wauIo4wext2tN84WOa0m5Gn4iDR17ISqDMG4CzXD6P4nm35IpeMtd3VtA+TIgy4lEQCN 3UOP8xlcuZKVGlkn4oEFvuTuGtJ0LyjdG3kfMAtL/GmnvKCPfMWiW20BMO9fDPXnLew9 Cpue2Hy0/hnN3784Gpn19WC5Vra7NcXK3OHbzCH0wiKUvE9cc+iFlsld4pMtnnjk3l2j MiEsW1GW1F71Vri1o8bUSrwCvM3iZmM0hyOkpN/FTae/589X+M+x6L5mVbsFmfAszKkC 0syA== X-Forwarded-Encrypted: i=1; AJvYcCXYmWYzi+Qy7euAmxQZ2ybAPrk5SPCAgqDoxN9zbyFnOxvXreHipysaMlUIepBsYf0lvtKUS5p3/rDyKX8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx89eGZkmeVUYFIH0OHfLiSebgKBYaB2V/EMZfiES7uBNGBmvjm 81rRImGVUce8ZwsWD7kOOpB1iqkQl9DJvyOAGlg1ZdYs3Ut2eF9hB5c34hF1ZBNrew== X-Gm-Gg: AY/fxX5TIf26Qm+CrL/PlJuShDstOpzK18pCjDMauSMsQfRgXhHg6dCzD+DHHQj817W YC7SVllstCszhG5Bx7imGYuny5IEEUYhpaxA9c1V5ylCH4AjBKtD8LAQFskSMaYjnUVsNtLsm9D u/q7wgWhnMPqDuy27nEGgcliDhXVsoLtlQs78iF4LqUls9ONqJ3IeQslPz82hlavKHTDR+KMdlD Cer7wlH+xrEBSOViZ5BIG7mzaPo0JHQE8wQEQ/TT2b2RbKY3tFDPy9EzeAK8dHgw7GH/ZOMDPOZ QbxJVdvUFZjC4nJ5XW264lfbRIgzf3Ca8Tf2ivfy7xSJ6pC2LKB1n2rymF4bnAegc360qFF0SA+ G6ajCBCJO1pkGw0CmF4i0Kw94+T8SzPyzXQO85DW2KtWtxh1s0vXDZ4IT63GjRKDkBMkplMd1Hi 2xYswB2xuJAw== X-Google-Smtp-Source: AGHT+IFc7lfuo7yQDfcwypXaTFhaCn0ztoJq9R2+VDKCETftLEuTA9BXPWY0bNWeqlGtIrXpb7wodQ== X-Received: by 2002:a05:622a:4d8d:b0:4ff:b2a0:2b2e with SMTP id d75a77b69052e-4ffb4a44749mr279989911cf.46.1768243897639; Mon, 12 Jan 2026 10:51:37 -0800 (PST) Received: from um773-cachyos ([2600:1700:cc0:94af:eca6:9ff9:6f3c:5de9]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4ffa8e4bf3dsm137327951cf.23.2026.01.12.10.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 10:51:37 -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 v6 1/3] sched/fair: Co-locate cfs_rq and sched_entity Date: Mon, 12 Jan 2026 13:51:00 -0500 Message-ID: <20260112185121.3327881-2-zli94@ncsu.edu> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260112185121.3327881-1-zli94@ncsu.edu> References: <20260112185121.3327881-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_rq_with_se that holds both objects in a single allocation. This patch: - Moves struct sched_entity_stats from stats.h to sched.h to allow cfs_rq_with_se to use it while avoiding include order issues. - Defines the new struct cfs_rq_with_se containing cfs_rq and sched_entity_stats for type safety. - 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 | 17 +++++++++++++++++ kernel/sched/stats.h | 7 ------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7377f9117501..eef10f2ef2a9 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_rq_with_se *combined =3D + container_of(tg->cfs_rq[i], struct cfs_rq_with_se, cfs_rq); + kfree(combined); + } } =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_rq_with_se *combined; 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) + combined =3D kzalloc_node(sizeof(*combined), + GFP_KERNEL, cpu_to_node(i)); + if (!combined) 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 &combined->cfs_rq; + se =3D &combined->ses.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 3ceaa9dc9a9e..be32810f7475 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2172,6 +2172,23 @@ 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 + * cfs_rq_with_se needs it but stats.h has dependencies on things + * defined later in this file. + */ +struct sched_entity_stats { + struct sched_entity se; + struct sched_statistics stats; +} __no_randomize_layout; + +struct cfs_rq_with_se { + struct cfs_rq cfs_rq; + struct sched_entity_stats ses; +}; +#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..6d80d5c7a202 100644 --- a/kernel/sched/stats.h +++ b/kernel/sched/stats.h @@ -89,13 +89,6 @@ 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) { --=20 2.52.0