From nobody Mon Feb 9 05:10:35 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 From nobody Mon Feb 9 05:10:35 2026 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (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 EA4ED3644A6 for ; Mon, 12 Jan 2026 18:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768243904; cv=none; b=m/BpBknSTMp4SSlZpi2Lgq/tDDd3OePmwVgoX2zegkum/FAM8A4MMXsmuGDDx8KU9UFyT3Ofhi/1GDUiCGbqmJJsggqIxJ6sBgRc/2SrhsewnJqTMrGy4+t2CbixycoXe2H1quAA9/8padgEAYcgG8PVqrL7qwaRZGoi21eWn/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768243904; c=relaxed/simple; bh=ucXz/PY1wR0L0RXr4BlHAsuFcg4Z8BCRzW83WkLbDio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BsykapG6wGCMycJsYjQidQBZg57vCwX9Ye+T5xam1joPPYOI1G17VlhWXUUDifJ8wkWnQvtOjdekVsGoRgjlHd7X6giPi6t/GGXO2n3UubPYYAqVWl5NUVkvMZ0Qe41k19SL7SnHhLj17jkVhO3PiY7jPp0GftpXO6m9wdrbsxc= 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=C12dOMr7; arc=none smtp.client-ip=209.85.160.171 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="C12dOMr7" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-4ee257e56aaso62017061cf.0 for ; Mon, 12 Jan 2026 10:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1768243899; x=1768848699; 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=+Xgyb0uFWZM7DKrtyjAwW38ymN3Q9k9LCOvQnsUcKBk=; b=C12dOMr75abrwmt/Qh3HtPFNjcYOiFSNPACchkVjJJ3SHGhZGjUMpD3BK1oxuO3uNX 3vTd2YrkRRD40+kmwL1v+ZCE2V//x1CCLe+qPkoFBZWwkchvCmBr77JqQWBl71cy5a7w QrYPV+RRfhwhio26vbxTR9GzT2Tzdpwp/E7osQQNmGKI2gwUbqhGZIzOgI+ued1ddrvw qGXuiRDfMUHR0i6/4y4/0w94HAb8yR7980rym6BJkJvITBC1nuMcvw8tuQJBnWIMZZ2X 2odkppj0r9O+fTr2Fiwb02EzCDXIJAvyZzwUKe/Gr8g8OF23joYVAjHDGhFg4/2D4Ear 06Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768243899; x=1768848699; 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=+Xgyb0uFWZM7DKrtyjAwW38ymN3Q9k9LCOvQnsUcKBk=; b=Okocxb0UCEYGjc/B2V5AouUgMjEKxRNrndc9+UabgZx2oub2mPuTgSw+2b8FssDdVS Mtkkw2NfE7OhbJbcaulVFOkLoZrtmpKzc9klTEK7Ya1Y8ecn5WxVwtIxuTvG8wU5M/zq 2lH+QFtJfNSNaShL/lGh0pUlcZGshAX288WFoXCevUssSXVQcSmvG41ir/gyToDa4VfW h5Zv0ehyi4i9SjkfUTBG69KcglNQXH2RZb7gqo0pmNNbop4M88QqXQJAeaSXRlPDMovL dCvYKjPBCpQHrapMxhjafCzouYuqlBzv5s6tUx9hzcrI3BxwtGy3ZEBQbn1TzxmNGiE3 ro7Q== X-Forwarded-Encrypted: i=1; AJvYcCUuhRT4rYByyF9H5n5fgDTg95ou1HFWkMVE0U+jtXO+LQaOA94ZSMbTVr6GLflzeu3f9dnkO4sXAdMJ9LA=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+5H0xzjDp5gPADxAjMFemAw6qNvGAxidl6hJ7Qe3Dfg+p0Lw/ 4IUXHMxDuGepMxwbEKzWfdDUKbnjIy2hlij0govyUV0DNMXLbaW5X8Y76jBINP6h4Q== X-Gm-Gg: AY/fxX5SZeo8GOX2Hi8stp/RkEzd5PWJSPlRfXS7bSROnXKMwAWKO18/d57fTKasI4U 1qnr2owGS8LHXyEhoQNHr85x76NN2I1q5NlGdlknX57fS0E1ixnwvh+Fwuv8ruapwXzzasvxUFr 78gXCcaY1Oj9/KtdehrOblR26HEViTOJM3/DnPyPSH2fSrvrb/qkcgK5uKW9h6DSn3/7jy5a0cW Itsh/cpfE0irFvaYaCMA60Tt1qc3nwSp0DfawBtLgcv5PHBjkp11mjMhQG4b8QFvmfVP4/e0ZdK SVT9prhBbaLlvRKRR0NU8b3fs8r29WJHeQ5NgWjx2la7D0v6AvEqqTGnII/3juwIRtIQ291rFfq WLPDUQtZ2bBs583BOQY7OGR8DKJL4hvoP/R3fktYpxkaahYNF0guL6yYKphV4fz0byC8IsnB33e AePYe1lHApKDNwWglGFAIO X-Received: by 2002:ac8:7e8c:0:b0:4f1:8412:46e2 with SMTP id d75a77b69052e-501397e856bmr6315341cf.29.1768243898887; Mon, 12 Jan 2026 10:51:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 10:51:38 -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 2/3] sched/fair: Remove task_group->se pointer array Date: Mon, 12 Jan 2026 13:51:01 -0500 Message-ID: <20260112185121.3327881-3-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 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 --- kernel/sched/core.c | 7 ++----- kernel/sched/debug.c | 2 +- kernel/sched/fair.c | 25 +++++++++---------------- kernel/sched/sched.h | 29 ++++++++++++++++++++++++----- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5b17d8e3cb55..2db052414794 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8561,7 +8561,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 **); @@ -8570,9 +8570,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 @@ -9640,7 +9637,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 41caa22e0680..a18c1be40578 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -644,7 +644,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 eef10f2ef2a9..db10e617a638 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5974,7 +5974,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 @@ -9845,7 +9845,6 @@ static bool __update_blocked_fair(struct rq *rq, bool= *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 @@ -9865,7 +9864,7 @@ static bool __update_blocked_fair(struct rq *rq, bool= *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 @@ -9891,8 +9890,7 @@ static bool __update_blocked_fair(struct rq *rq, bool= *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 @@ -13625,7 +13623,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) @@ -13638,9 +13635,6 @@ int alloc_fair_sched_group(struct task_group *tg, s= truct task_group *parent) tg->cfs_rq =3D kcalloc(nr_cpu_ids, sizeof(cfs_rq), GFP_KERNEL); if (!tg->cfs_rq) goto err; - tg->se =3D kcalloc(nr_cpu_ids, sizeof(se), GFP_KERNEL); - if (!tg->se) - goto err; =20 tg->shares =3D NICE_0_LOAD; =20 @@ -13655,7 +13649,7 @@ int alloc_fair_sched_group(struct task_group *tg, s= truct task_group *parent) 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_tg_cfs_entry(tg, cfs_rq, se, i, tg_se(parent, i)); init_entity_runnable_average(se); } =20 @@ -13674,7 +13668,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); @@ -13691,7 +13685,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) { @@ -13728,7 +13722,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) @@ -13759,7 +13752,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)); @@ -13770,7 +13763,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 */ @@ -13821,7 +13814,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 be32810f7475..97c27ac0ae18 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -476,8 +476,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; @@ -915,7 +913,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 @@ -2187,6 +2186,26 @@ struct cfs_rq_with_se { struct cfs_rq cfs_rq; struct sched_entity_stats ses; }; + +static inline struct sched_entity *tg_se(struct task_group *tg, int cpu) +{ + if (is_root_task_group(tg)) + return NULL; + + struct cfs_rq_with_se *combined =3D + container_of(tg->cfs_rq[cpu], struct cfs_rq_with_se, cfs_rq); + return &combined->ses.se; +} + +static inline struct sched_entity *cfs_rq_se(struct cfs_rq *cfs_rq) +{ + if (is_root_task_group(cfs_rq->tg)) + return NULL; + + struct cfs_rq_with_se *combined =3D + container_of(cfs_rq, struct cfs_rq_with_se, cfs_rq); + return &combined->ses.se; +} #endif =20 /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups= */ @@ -2199,8 +2218,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.52.0 From nobody Mon Feb 9 05:10:35 2026 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (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 C00243876D0 for ; Mon, 12 Jan 2026 18:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768243907; cv=none; b=gk9ZrSv6X+FjV09nMSMnbd/RU0cPY2MwRJHCsjHkCGicW0U8EC0tELJcAPrFnDhLHHJ0HO7rWLaBLrMfkhu8HHUH+pW43A9V989yAtZ/f0tWYb0dXEqiobBTU8eTyHOr1Y2ccIzYo4koF16SNwHBFXUY0qkKDx64fZjtqUAGrxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768243907; c=relaxed/simple; bh=JDU2ZFavPDCgEjRWmn1wtmOV+p0Va4BKv11TVkJjWLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bOalMb+z6xAPYJ40r8L45PvRV0uGACe0cuPRfjlyuSL/lGW8ztgLJmbh+6BF43GcnF03/0t6LrdfZjzveeXPKQ391ORmG0wFP7m14nusqYWKqq8GfzduTSivj7qWZOfng3h7ZgNNe5R6iigExyhTfpNuL+QfnUOKzQIldV8v2UY= 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=ZMZQMhHj; arc=none smtp.client-ip=209.85.160.173 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="ZMZQMhHj" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-4ffc0ddefc4so74501761cf.3 for ; Mon, 12 Jan 2026 10:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1768243901; x=1768848701; 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=YDOPwHV2kw/rsOvhuKiqH8DoSNAERAKpdRTmwWJAso0=; b=ZMZQMhHjnuJltcjSgyiTg8Jq9nCH2tAdQMHvitmPc8u3wZbN7vmNBk8gawu/mJGcOI USqWyR1XHDQJ3t3nO3XMuqP6BA8c+BBY0jgUz2d2JB8VfdV5HEHksxt8BxfARbYWnI1M f9kHlIAfHRzMgTazWFuxFbqz9702MesXp/emmB6+vpOBCv6+0IVfoZ6VIVxrl6jXmH6f IR+f5fNkqE/3z4gnfYphtoKLT7pg2o2Lfj0gm/ofQnGvc//YVQ8PNLzywOgeey70tgAQ MZnt7M9HzEg4yI/KlERyEaaYESHFbU9DrvQpf0qk9XSl91NstR5hh+lNkr878yTNbc1s wbnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768243901; x=1768848701; 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=YDOPwHV2kw/rsOvhuKiqH8DoSNAERAKpdRTmwWJAso0=; b=LO3cg7D+NCVJbuKcm9D7/LO4TcRHpmSJyGlyX/L6koA17tpChYAy5R4omnJnP/AfxT j85e41W+L16ZxQHS0W6SsDlpwUktbORhpLTy7MGhrlH54lmdBvBWAB0lyd0X5DPB01No pZo2m8V5h1nCJeFqL7Am0h/zqFsotV38uFwW+vm8/bDprzHbzG++0yezEA63CwbqzSu6 Rd/wn3ku1f01tK0zHAsZ+tyZpp3SQMdLF5TcokgEQl3Ttd5clvj1mNf+/LXY7QH8L5L6 P999oekuYXVYbwG832L4JXdXVsxYGsTwxCZS31WgTqKsjr4OItBwZiOYWJuuqzNFeiR+ ZGgA== X-Forwarded-Encrypted: i=1; AJvYcCXXvBNH6EfGjm0zNq9PE+7wC9B1zdj54qROWEz38XEmXvYj4OpVX6lsoOtehMMKF/0f8GP3giFLDoeHrIU=@vger.kernel.org X-Gm-Message-State: AOJu0YyE+ssuRwyZdpM5qdKfzDwJKZo4yQbHXEE+B7koXjRnQwDLdo07 XeYAWFrmsSD+JH2av4EGo1CcuMnV4nX0IxbX0qdjP2361W34bdkfMk14SyoF9R9ndQ== X-Gm-Gg: AY/fxX6oq9USeTccsrZlvRqj3h1nYMLu2L78c4G2RJ/LJYHdxUU+efvRTlB1fLJQja4 L7yF4tmWz3nsbpXy+6XKAind1mNIYzKdqwFxV9YUS+iUrJbGlZnzB424B3EBUIZZ7dsejNwesbr Lktos9hbmHrBCrAk4GRvTp2F8PoTBM7dStyZ5gM3j/xcjDKO3evjEz/43gPVsX5oZWIJyS+L2kz 0Qn+Y7H0fPZq61PhhWsLKVSi8fP4zxfXo7DEu6NPeJCuof7S+GUa2oE5lEhjQjX7QRRsVjZSvZi e2x43++JIbvX+9PWG6qElfbbITbmT9BHbjfDI+cRXFtmQFqflmGix9psDZG6oaRN9NLjL/DBMKY kICx3wmnczg7yCZQO/oA6w8/bEx9ZFu001rXz/6RVZ+VotCHSeqxW3JxeUQRhLN2XOuda5w+48f znnMKUoIWpNfo8nTfPqgsr X-Google-Smtp-Source: AGHT+IGAFnDifwBOtt7rscT0rNxuYuadbd5qVVoDhargxgNe/1RDn2vUmKzt5r+HWXVoao6+rBwl+g== X-Received: by 2002:a05:622a:19a2:b0:4f3:565b:c52c with SMTP id d75a77b69052e-4ffb497ba07mr273314331cf.39.1768243900117; Mon, 12 Jan 2026 10:51:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 10:51: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 v6 3/3] sched/fair: Allocate both cfs_rq and sched_entity with per-cpu Date: Mon, 12 Jan 2026 13:51:02 -0500 Message-ID: <20260112185121.3327881-4-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 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 =3D &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 Signed-off-by: Zecheng Li --- kernel/sched/core.c | 35 ++++++++++----------------- kernel/sched/fair.c | 57 +++++++++++++++++--------------------------- kernel/sched/sched.h | 14 +++++++---- 3 files changed, 45 insertions(+), 61 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2db052414794..cf63bf089fa0 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8545,7 +8545,7 @@ static struct kmem_cache *task_group_cache __ro_after= _init; =20 void __init sched_init(void) { - unsigned long ptr =3D 0; + unsigned long __maybe_unused ptr =3D 0; int i; =20 /* Make sure the linker didn't screw up */ @@ -8561,33 +8561,24 @@ void __init sched_init(void) wait_bit_init(); =20 #ifdef CONFIG_FAIR_GROUP_SCHED - ptr +=3D nr_cpu_ids * sizeof(void **); -#endif -#ifdef CONFIG_RT_GROUP_SCHED - ptr +=3D 2 * nr_cpu_ids * sizeof(void **); -#endif - if (ptr) { - ptr =3D (unsigned long)kzalloc(ptr, GFP_NOWAIT); + root_task_group.cfs_rq =3D &runqueues.cfs; =20 -#ifdef CONFIG_FAIR_GROUP_SCHED - root_task_group.cfs_rq =3D (struct cfs_rq **)ptr; - ptr +=3D nr_cpu_ids * sizeof(void **); - - root_task_group.shares =3D ROOT_TASK_GROUP_LOAD; - init_cfs_bandwidth(&root_task_group.cfs_bandwidth, NULL); + root_task_group.shares =3D ROOT_TASK_GROUP_LOAD; + init_cfs_bandwidth(&root_task_group.cfs_bandwidth, NULL); #endif /* CONFIG_FAIR_GROUP_SCHED */ #ifdef CONFIG_EXT_GROUP_SCHED - scx_tg_init(&root_task_group); + scx_tg_init(&root_task_group); #endif /* CONFIG_EXT_GROUP_SCHED */ #ifdef CONFIG_RT_GROUP_SCHED - root_task_group.rt_se =3D (struct sched_rt_entity **)ptr; - ptr +=3D nr_cpu_ids * sizeof(void **); + ptr +=3D 2 * nr_cpu_ids * sizeof(void **); + ptr =3D (unsigned long)kzalloc(ptr, GFP_NOWAIT); + root_task_group.rt_se =3D (struct sched_rt_entity **)ptr; + ptr +=3D nr_cpu_ids * sizeof(void **); =20 - root_task_group.rt_rq =3D (struct rt_rq **)ptr; - ptr +=3D nr_cpu_ids * sizeof(void **); + root_task_group.rt_rq =3D (struct rt_rq **)ptr; + ptr +=3D nr_cpu_ids * sizeof(void **); =20 #endif /* CONFIG_RT_GROUP_SCHED */ - } =20 init_defrootdomain(); =20 @@ -9488,7 +9479,7 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, } =20 for_each_online_cpu(i) { - struct cfs_rq *cfs_rq =3D tg->cfs_rq[i]; + struct cfs_rq *cfs_rq =3D tg_cfs_rq(tg, i); struct rq *rq =3D cfs_rq->rq; =20 guard(rq_lock_irq)(rq); @@ -9656,7 +9647,7 @@ static u64 throttled_time_self(struct task_group *tg) u64 total =3D 0; =20 for_each_possible_cpu(i) { - total +=3D READ_ONCE(tg->cfs_rq[i]->throttled_clock_self_time); + total +=3D READ_ONCE(tg_cfs_rq(tg, i)->throttled_clock_self_time); } =20 return total; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index db10e617a638..359c1c1edee5 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -327,7 +327,7 @@ static inline bool list_add_leaf_cfs_rq(struct cfs_rq *= cfs_rq) * to a tree or when we reach the top of the tree */ if (cfs_rq->tg->parent && - cfs_rq->tg->parent->cfs_rq[cpu]->on_list) { + tg_cfs_rq(cfs_rq->tg->parent, cpu)->on_list) { /* * If parent is already on the list, we add the child * just before. Thanks to circular linked property of @@ -335,7 +335,7 @@ static inline bool list_add_leaf_cfs_rq(struct cfs_rq *= cfs_rq) * of the list that starts by parent. */ list_add_tail_rcu(&cfs_rq->leaf_cfs_rq_list, - &(cfs_rq->tg->parent->cfs_rq[cpu]->leaf_cfs_rq_list)); + &(tg_cfs_rq(cfs_rq->tg->parent, cpu)->leaf_cfs_rq_list)); /* * The branch is now connected to its tree so we can * reset tmp_alone_branch to the beginning of the @@ -4156,7 +4156,7 @@ static void __maybe_unused clear_tg_offline_cfs_rqs(s= truct rq *rq) =20 rcu_read_lock(); list_for_each_entry_rcu(tg, &task_groups, list) { - struct cfs_rq *cfs_rq =3D tg->cfs_rq[cpu_of(rq)]; + struct cfs_rq *cfs_rq =3D tg_cfs_rq(tg, cpu_of(rq)); =20 clear_tg_load_avg(cfs_rq); } @@ -5692,7 +5692,7 @@ static inline int throttled_hierarchy(struct cfs_rq *= cfs_rq) =20 static inline int lb_throttled_hierarchy(struct task_struct *p, int dst_cp= u) { - return throttled_hierarchy(task_group(p)->cfs_rq[dst_cpu]); + return throttled_hierarchy(tg_cfs_rq(task_group(p), dst_cpu)); } =20 static inline bool task_is_throttled(struct task_struct *p) @@ -5838,7 +5838,7 @@ static void enqueue_task_fair(struct rq *rq, struct t= ask_struct *p, int flags); static int tg_unthrottle_up(struct task_group *tg, void *data) { struct rq *rq =3D data; - struct cfs_rq *cfs_rq =3D tg->cfs_rq[cpu_of(rq)]; + struct cfs_rq *cfs_rq =3D tg_cfs_rq(tg, cpu_of(rq)); struct task_struct *p, *tmp; =20 if (--cfs_rq->throttle_count) @@ -5909,7 +5909,7 @@ static void record_throttle_clock(struct cfs_rq *cfs_= rq) static int tg_throttle_down(struct task_group *tg, void *data) { struct rq *rq =3D data; - struct cfs_rq *cfs_rq =3D tg->cfs_rq[cpu_of(rq)]; + struct cfs_rq *cfs_rq =3D tg_cfs_rq(tg, cpu_of(rq)); =20 if (cfs_rq->throttle_count++) return 0; @@ -6382,8 +6382,8 @@ static void sync_throttle(struct task_group *tg, int = cpu) if (!tg->parent) return; =20 - cfs_rq =3D tg->cfs_rq[cpu]; - pcfs_rq =3D tg->parent->cfs_rq[cpu]; + cfs_rq =3D tg_cfs_rq(tg, cpu); + pcfs_rq =3D tg_cfs_rq(tg->parent, cpu); =20 cfs_rq->throttle_count =3D pcfs_rq->throttle_count; cfs_rq->throttled_clock_pelt =3D rq_clock_pelt(cpu_rq(cpu)); @@ -6575,7 +6575,7 @@ static void __maybe_unused update_runtime_enabled(str= uct rq *rq) rcu_read_lock(); list_for_each_entry_rcu(tg, &task_groups, list) { struct cfs_bandwidth *cfs_b =3D &tg->cfs_bandwidth; - struct cfs_rq *cfs_rq =3D tg->cfs_rq[cpu_of(rq)]; + struct cfs_rq *cfs_rq =3D tg_cfs_rq(tg, cpu_of(rq)); =20 raw_spin_lock(&cfs_b->lock); cfs_rq->runtime_enabled =3D cfs_b->quota !=3D RUNTIME_INF; @@ -6604,7 +6604,7 @@ static void __maybe_unused unthrottle_offline_cfs_rqs= (struct rq *rq) =20 rcu_read_lock(); list_for_each_entry_rcu(tg, &task_groups, list) { - struct cfs_rq *cfs_rq =3D tg->cfs_rq[cpu_of(rq)]; + struct cfs_rq *cfs_rq =3D tg_cfs_rq(tg, cpu_of(rq)); =20 if (!cfs_rq->runtime_enabled) continue; @@ -9414,7 +9414,7 @@ static inline int task_is_ineligible_on_dst_cpu(struc= t task_struct *p, int dest_ struct cfs_rq *dst_cfs_rq; =20 #ifdef CONFIG_FAIR_GROUP_SCHED - dst_cfs_rq =3D task_group(p)->cfs_rq[dest_cpu]; + dst_cfs_rq =3D tg_cfs_rq(task_group(p), dest_cpu); #else dst_cfs_rq =3D &cpu_rq(dest_cpu)->cfs; #endif @@ -13346,7 +13346,7 @@ static int task_is_throttled_fair(struct task_struc= t *p, int cpu) struct cfs_rq *cfs_rq; =20 #ifdef CONFIG_FAIR_GROUP_SCHED - cfs_rq =3D task_group(p)->cfs_rq[cpu]; + cfs_rq =3D tg_cfs_rq(task_group(p), cpu); #else cfs_rq =3D &cpu_rq(cpu)->cfs; #endif @@ -13612,42 +13612,31 @@ static void task_change_group_fair(struct task_st= ruct *p) =20 void free_fair_sched_group(struct task_group *tg) { - int i; - - for_each_possible_cpu(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); - } - } - - kfree(tg->cfs_rq); + free_percpu(tg->cfs_rq); } =20 int alloc_fair_sched_group(struct task_group *tg, struct task_group *paren= t) { - struct cfs_rq_with_se *combined; + struct cfs_rq_with_se __percpu *combined; struct sched_entity *se; struct cfs_rq *cfs_rq; int i; =20 - tg->cfs_rq =3D kcalloc(nr_cpu_ids, sizeof(cfs_rq), GFP_KERNEL); - if (!tg->cfs_rq) + combined =3D alloc_percpu_gfp(struct cfs_rq_with_se, GFP_KERNEL); + if (!combined) goto err; =20 + tg->cfs_rq =3D &combined->cfs_rq; tg->shares =3D NICE_0_LOAD; =20 init_cfs_bandwidth(tg_cfs_bandwidth(tg), tg_cfs_bandwidth(parent)); =20 for_each_possible_cpu(i) { - combined =3D kzalloc_node(sizeof(*combined), - GFP_KERNEL, cpu_to_node(i)); - if (!combined) + cfs_rq =3D tg_cfs_rq(tg, i); + if (!cfs_rq) goto err; =20 - cfs_rq =3D &combined->cfs_rq; - se =3D &combined->ses.se; + se =3D tg_se(tg, i); init_cfs_rq(cfs_rq); init_tg_cfs_entry(tg, cfs_rq, se, i, tg_se(parent, i)); init_entity_runnable_average(se); @@ -13684,7 +13673,7 @@ void unregister_fair_sched_group(struct task_group = *tg) destroy_cfs_bandwidth(tg_cfs_bandwidth(tg)); =20 for_each_possible_cpu(cpu) { - struct cfs_rq *cfs_rq =3D tg->cfs_rq[cpu]; + struct cfs_rq *cfs_rq =3D tg_cfs_rq(tg, cpu); struct sched_entity *se =3D tg_se(tg, cpu); struct rq *rq =3D cpu_rq(cpu); =20 @@ -13721,8 +13710,6 @@ void init_tg_cfs_entry(struct task_group *tg, struc= t cfs_rq *cfs_rq, cfs_rq->rq =3D rq; init_cfs_rq_runtime(cfs_rq); =20 - tg->cfs_rq[cpu] =3D cfs_rq; - /* se could be NULL for root_task_group */ if (!se) return; @@ -13815,7 +13802,7 @@ int sched_group_set_idle(struct task_group *tg, lon= g idle) for_each_possible_cpu(i) { struct rq *rq =3D cpu_rq(i); struct sched_entity *se =3D tg_se(tg, i); - struct cfs_rq *grp_cfs_rq =3D tg->cfs_rq[i]; + struct cfs_rq *grp_cfs_rq =3D tg_cfs_rq(tg, i); bool was_idle =3D cfs_rq_is_idle(grp_cfs_rq); long idle_task_delta; struct rq_flags rf; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 97c27ac0ae18..b42ae324bab8 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -477,7 +477,7 @@ struct task_group { =20 #ifdef CONFIG_FAIR_GROUP_SCHED /* runqueue "owned" by this group on each CPU */ - struct cfs_rq **cfs_rq; + struct cfs_rq __percpu *cfs_rq; unsigned long shares; /* * load_avg can be heavily contended at clock tick time, so put @@ -2187,13 +2187,19 @@ struct cfs_rq_with_se { struct sched_entity_stats ses; }; =20 +/* Access a specific CPU's cfs_rq from a task group */ +static inline struct cfs_rq *tg_cfs_rq(struct task_group *tg, int cpu) +{ + return per_cpu_ptr(tg->cfs_rq, cpu); +} + static inline struct sched_entity *tg_se(struct task_group *tg, int cpu) { if (is_root_task_group(tg)) return NULL; =20 struct cfs_rq_with_se *combined =3D - container_of(tg->cfs_rq[cpu], struct cfs_rq_with_se, cfs_rq); + container_of(tg_cfs_rq(tg, cpu), struct cfs_rq_with_se, cfs_rq); return &combined->ses.se; } =20 @@ -2216,8 +2222,8 @@ static inline void set_task_rq(struct task_struct *p,= unsigned int cpu) #endif =20 #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]; + set_task_rq_fair(&p->se, p->se.cfs_rq, tg_cfs_rq(tg, cpu)); + p->se.cfs_rq =3D tg_cfs_rq(tg, cpu); p->se.parent =3D tg_se(tg, cpu); p->se.depth =3D p->se.parent ? p->se.parent->depth + 1 : 0; #endif --=20 2.52.0