From nobody Mon Apr 6 15:52:16 2026 Received: from mail-yx1-f54.google.com (mail-yx1-f54.google.com [74.125.224.54]) (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 082B430E855 for ; Wed, 18 Mar 2026 21:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773868307; cv=none; b=gC7/lXboF18Tm+iBvbIjl1Xmw+sbrgNetnlrlJqHTT9ncbSNUmOQf6J9oUuWu8xRPNUaGLgtm4ZLNxOtuIzyFtJ9cBkkQW4psoR+8g4dEV/Hm1dgN+RJWCsFiTxYyP/v39Ve0U8NRy2qw6DCd7fW4NPSbtZK8pozXAIth2lctcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773868307; c=relaxed/simple; bh=gAJU4zC5x6JuY+pTVSWv+bDUwPqDdTnR5X4UgnLK29s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=enRYD/u9OrzGSNh5mt/QJPBtjuYC0jRVS+b/mQQNgLLh2y8m4bBof26Ch8wvhENx6sEw4F3dZGBqlNHZZrCy9LMj9jwbcaA5C0iFXdebc1pKX4xgtRy3T+LNEzV3EG7XQ/Li/xP8Jl8I9rO25LA+FOK4U8OAe3v0xXX9MubuLzU= 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=bN91cTmV; arc=none smtp.client-ip=74.125.224.54 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="bN91cTmV" Received: by mail-yx1-f54.google.com with SMTP id 956f58d0204a3-64aedd812baso428660d50.3 for ; Wed, 18 Mar 2026 14:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1773868305; x=1774473105; 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=NZL/wJBtZ7x/udHyrL9BfhVlsQqTeT94Yhy16V0LzLA=; b=bN91cTmVdRZoLkQIaQDi5m19x9dyhPjQI7lT45oAaoq9qjIL6scNrturWXNH+SVrQL 0KpmDsKA7qBQQmYuQ1bIKh7P5eyh7d1AoVRaOpcLv1nTTKAJX3sNBKuFM0m/HbzN7sxH B/YRbVVQe43U0CYMQLYaoHFykGWAPTysDJeanKOyxUOQTlTT+vphM3rICY2QV1LM9xiH FaXR7P0AFVOamp4Kmp2iseyIBg//ZWVfyGOQG3i6PgbjTsz4aVTZ94FfRbRGHqB9m0Rn aO2EVkXQjH24tzQcMLXpehSZrsajiZogTkBIX3NS6SI1bp2fieuky/YpyJ1HnjCt2MsZ gPdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773868305; x=1774473105; 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=NZL/wJBtZ7x/udHyrL9BfhVlsQqTeT94Yhy16V0LzLA=; b=qhVZHBVBv2F84giuU/Asvzfbb5t2IR0HvuSNwwOyrTFmmUJHkgquWzc7TR8tIMUXb8 6F/N0lfXF2GJPehe+LA4li4Qk3n1AwwW0CWP0nEriIfg9w/cpejvhcLwZDaogl2t9gA3 FCsLkt3aX00726YcHXXeZQaFY/rLrHWeRko2xb8ErshKdGYPRVMTU5H14iK9OGPXuqOQ 8Lm7FPS5av8YEJHVpEFtEi8MmpI8PnCpvkxK5lTyBUYxZcTs1GXUh7PjzKQuwMbFyrDV 9CBmiUZCO/L36LtDaAih34qvnCJnBGsck0lHmycysEZXaKaYJXzdDwecSACZrKVxY3Ye LScw== X-Forwarded-Encrypted: i=1; AJvYcCUEXZokepEzLUSbU/D7f/n0F0XWkwQNZAvLyW5BgUEjwmm+jTLb2OIvpuH9OOcxqGWG/lZ6wR1nJOapX5g=@vger.kernel.org X-Gm-Message-State: AOJu0YwsTaXZ3RggWUL86xb3e5+RHniuZoLpAt9k36NH0Cab2wkbGokF OvZuwDdzio8szEigCL0IHuJQorAyqhHo13y5N+OpqXJhg2dvfRYELWVhNdK3bbx3CQ== X-Gm-Gg: ATEYQzx6UlKAS/BbNB3BaC4ZUqxH1zWc6aJY53ELKzPBWh4JTu9Bb+7WgZPFqbOKWGK aasrdZj7ueP22/qmPaAAMNZi1Pf2/B9BClVfh7OKxpJLMWcqi9hoF6lhftmAMWUbCF6r7cn8MMG qjTpfn0c9roOt++LHbcIm4pTIS+Fa0iGce2a8ygJrDIvHP8pF8IBbEG5ip3PiMGFc3YdDUwglCt 9P3tsf0xp4KX1QnPZPHp5ErxfN2Md5cgduEjwHlKcbvGIlwfsz6RY/KXmrpggsGvWHPfkNkLXpd Zt0mcw4/J6zvfRv6kFQurejZAEvmRnzJASrkj9Wu23UAh3Y5Ona7Dg0mii2zAz2qj7RRvpIhoSi ush9mNEEFJWnWOaCOiJZsrGVL7pwwyzKk9SHGqCMF0KgL4f9uTc+2sgl6iyyFtJjqa6pYfcl9p5 lgHnHNqB/813UlgCdNpcDQ9bLiMWJOuCT9I6JdwgD1dZjXfAuiTel4SFQ0 X-Received: by 2002:a05:690c:dc5:b0:798:e281:a4f3 with SMTP id 00721157ae682-79a71bf0da7mr48740367b3.40.1773868305042; Wed, 18 Mar 2026 14:11:45 -0700 (PDT) Received: from um773-cachyos.sd.ncsu.edu ([152.7.255.206]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79a7136f0c1sm24377927b3.7.2026.03.18.14.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 14:11:44 -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 , Steven Rostedt , linux-kernel@vger.kernel.org, Zecheng Li , Zecheng Li Subject: [PATCH v9 1/3] sched/fair: Co-locate cfs_rq and sched_entity in cfs_tg_state Date: Wed, 18 Mar 2026 17:11:08 -0400 Message-ID: <20260318211139.876385-2-zli94@ncsu.edu> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260318211139.876385-1-zli94@ncsu.edu> References: <20260318211139.876385-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 Reviewed-by: K Prateek Nayak --- kernel/sched/fair.c | 18 ++++++------------ kernel/sched/sched.h | 12 ++++++++++++ kernel/sched/stats.h | 9 +-------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 0a35a82e4792..79160d419c9f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13877,8 +13877,6 @@ void free_fair_sched_group(struct task_group *tg) for_each_possible_cpu(i) { if (tg->cfs_rq) kfree(tg->cfs_rq[i]); - if (tg->se) - kfree(tg->se[i]); } =20 kfree(tg->cfs_rq); @@ -13887,6 +13885,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; @@ -13903,16 +13902,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); @@ -13920,8 +13916,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 b863bbda6de8..826f21fa3f36 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2249,6 +2249,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 a612cf253c87..ebe0a7765f98 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.53.0 From nobody Mon Apr 6 15:52:16 2026 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (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 73073314B6E for ; Wed, 18 Mar 2026 21:11:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773868309; cv=none; b=H4IEoRwH2YZQnnWbPjbvcQvx7urxWO4rnkTjxzcRza41ZTuX4uQG5+ngXvO7BN3qtM8nkLcMjACqqRbhlK6rFtKXSsftaBLmYLHRzXDyCuEb2VzioprDZHXFcRh0HzYRfLS06KjVlUSXckNgXCq5Mej3IUa9oKMR0kzCPR6G968= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773868309; c=relaxed/simple; bh=q0ND4yMrmH1YomFb9IGsMzFWWV+rd3Ua1sZmJ42tbV4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jsQkkcwJEHN4gCnNqGhsdJGEpnA/KcRGvkNLPDLTuDbQWmIsOzpuoGcGv6BwEG6D1m4YZJTfvzrexzc7UCJ1lzvpxzXa0i7cThKnapQyxOPlxVM7rP3V4UKCT/XI7oSsVzcQ1rcjVJiV1qcN0dTMk9MmuhfL9T5y8IHfKKfTtt0= 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=a0Lmeakq; arc=none smtp.client-ip=209.85.128.178 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="a0Lmeakq" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-79a610a32a6so4778647b3.0 for ; Wed, 18 Mar 2026 14:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1773868306; x=1774473106; 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=a0LmeakqOY8OqSiNpvlg8yNUcCu4gGxZzQV6YyZdUdZQkV/ciYHp4lWa848R/FpPmO SlpGnYSNeeTY5koAcBW04VFfJjlyYqKcZ9AG0TN1cOnzM3kgS0bcqlZQeAK8FSAmtxEb I8LbzU+L2y3IOljc3zScq44kN3MS4q8TeXhd1p7ILto4j4VIp2U15ESl7yhY0Mz25Oh4 uzvk6DFW8E2tXY686F4eDUIp0n9HZAFr9M0XBpvTmQUq7lPcuZDdx/AryeC6xI/zzB2e 2oWEK0LZcgvt2klh7Pc/0pHovHqKvDbRR0pllPjzLDxtM2FxnX0GogDgNTZkA6y93//e w7qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773868306; x=1774473106; 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=pmjrFOlshF8OxpJ3+MXfXgDf/148biWjIXAoBl4KPEh5MMEM8VhRye9z3fSgdBG7lh IMRbVuQ9kuS0cCVx6ZPZB2oV1Lyxq1EbNjWGZWXb8k9a1tXkJMK7icyTIxACKeNywVpT RUPxauEi6ljWa4XULCnLTSI6fjz3njwNUdSXVO80RRPock1EvuJdABZ99O0w9GWx/Lv5 FCZ2e+mfK2NK6AGRAzqMzQ27KSoi0K9fiVnOXe/XooCwGNqK1gs8f1cz/mkRXBv/UHuD EA3R5hBSC8nabbpWVLIVB8SRxIh6e7Zihgi76k+Nxz2ATXICdWEDLxoBmASzmC+M5c5j vxUg== X-Forwarded-Encrypted: i=1; AJvYcCW0K9ujqJaXanUakWJfPpHex7cxKejcPH4f7ULRcj38HF0dBbIuBgJwPS3q8+aiCm6jRHHxT2hb76eju4o=@vger.kernel.org X-Gm-Message-State: AOJu0YyHodZXHDqVZNQ/Q0yAHyma66aOdqTIffJSh66MZdMcVcnuZTbw gCY6Q+598mSCNxjprPpsYaJ2CKt7oQHrlnlC1UjbDWyME2ZtrwUA2xphPDxGq3Rp8Q== X-Gm-Gg: ATEYQzyWsi32S/pSTnk3j5fLNXyK8JOCc5yoSfZKzEtuTyd+KXyul6MbL2FP4kdHBqi Iz6zELE2qoIXIV55+ceCQv0A8nEdKtMuaZCTpXJKCPPj5j1YaaxESEZwEmT7+Q6UZEFQsLG5ZYk gSieQ/w9lYNjmb7/fOQsSICiJJ+zhm7EsfySfEfqYtYD5/ZZbbP2HpSW0sswX9HrfPBVJ1FTX25 K+nPyQ08oivEqQf77a1yztTM8jgZgp3zpcCkbel6XHTlMKscyp2iH6ayqWlJX3qfpqqxfQYPD65 c69HCZjHoSW+K6kTIIGJDNc5GHR17GsiJRz2/rc6+ty+fWw7lZg92TUj1uMFQFYMZHegU7Jek9X 7nhY8tTury5kHg4+jxlObmgyMeCiGRe1fuB++xldVrc5zY5upoPpXbu9Ab4eW3mIhgUp0r1trFr TeGWWSElgwy48/9q69yNsDAbiHh50PBr62gZYJk9xlwAEWPOiyrw928N8K X-Received: by 2002:a05:690c:13:b0:79a:4fe4:ff52 with SMTP id 00721157ae682-79a718c35f4mr51003347b3.19.1773868306247; Wed, 18 Mar 2026 14:11:46 -0700 (PDT) Received: from um773-cachyos.sd.ncsu.edu ([152.7.255.206]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79a7136f0c1sm24377927b3.7.2026.03.18.14.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 14:11:45 -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 , Steven Rostedt , linux-kernel@vger.kernel.org, Zecheng Li , Zecheng Li Subject: [PATCH v9 2/3] sched/fair: Remove task_group->se pointer array Date: Wed, 18 Mar 2026 17:11:09 -0400 Message-ID: <20260318211139.876385-3-zli94@ncsu.edu> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260318211139.876385-1-zli94@ncsu.edu> References: <20260318211139.876385-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 --- 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 From nobody Mon Apr 6 15:52:16 2026 Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.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 8AF5C37418A for ; Wed, 18 Mar 2026 21:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773868310; cv=none; b=tM8fCTVXFPtCqLTpeTn/x/h3gyGauw6ELOgqJr5eT53MXQnawcO8/fW4tuYqyr1/To+4GhNjWcImse03B9mkcXvy4X13B5q6lz6LWQtMmC6aO3kKGqa/QcZsnzaw34uHJdlcNOIJrjmdsRxwqiYmxhuxHgnTiCiqCkb6Yn+AmQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773868310; c=relaxed/simple; bh=UCkCte7WiHCq4yQkiqq1brTnkl+ALKYPJxT+9jsckz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nwMPGED+B1dsFcc5wLl+N73LRTzTcjEKiggr8M/4fXe+LcONnrOaRge20l28r5wXOg+nkVJsnWPj4t4fzo9EjNXUhCDUxRYOC4eifVi8nCYFM3wf1JXxSxF4QfDqkrqolOeNgTlhoDuGVA0UJBwyl8pv+7Y2Fe+li80OlOEc2H8= 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=aDJRmBx3; arc=none smtp.client-ip=209.85.128.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="aDJRmBx3" Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-79827d28fc4so3810857b3.1 for ; Wed, 18 Mar 2026 14:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1773868307; x=1774473107; 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=UoUS2WogCfwmVhkFhiQQopzO9BXXtaFBus16kYgbVhQ=; b=aDJRmBx3xM3ICjKpOTBOfk2mjw6ei9g6YIkkamjE6sjOfn2MJ53X0JPMT1pODgqi1h 4Mwunw+fyAsypNPxjogrnjHL39wvzOHbenhthEeIuhAT94soSusZ/JBUL1MmNBwXBlmp l3hzgoZy2xMtNFK4oBp5VO/f5JcXWVJdJ9bV20sd2lFmSANLFlaQ/pGui+Dxsu145/oS l9XIU8Ti//SzXE+6GgiIiZHK77GMFydcagePhYdubgJQbRQ56Iq0niz+Pp7YMGCeB4B/ ajWMgWIUp1c07pldYI2mhahIudM4KpQG7PxYzYJEanwhGtHBDHxz6l8SpIOJYuzsRWoQ 5NwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773868307; x=1774473107; 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=UoUS2WogCfwmVhkFhiQQopzO9BXXtaFBus16kYgbVhQ=; b=iYPOd3BhoQ21gk+t6bFfD9vKgJIDdCkynBWRIbYdwwtYMHtxLEaDawfRQcyKCQEPE3 H0dn+mPQaMu9fw2XstZI0+/R3wM8LUEwxYqAb8aP6oeqhtclOgWXg7EnnwIwjDYv2BYQ BaqGg/S8T5Pz2FEmyObftb8QTgt5X+xggJVUrwMpW7BisrZzJ1HWxilUG6ccm/YZFVou idxrUv/eUuMxZsJwidPDkNHrDUncERtwGwJ1Km9T7XKrByiMt+/h+VX5ARyi3hcKYeit 1M50AB4oHcXjbgIAaJJ7sryyHZvQfBs8DAzuZyqBdjvhx8sRAQ/vmwkP75BBXewfJl4K Zavw== X-Forwarded-Encrypted: i=1; AJvYcCWX6gji8IIKK1Me2gJF+Xv1qgqjln4LiDT2C7izuH9/5jv5B0XMEBU9ky9bYFfL04wsImsKtxou7o7qjSU=@vger.kernel.org X-Gm-Message-State: AOJu0YwSMZ0xBWcla8Grb7Cr9gXyfhuZTGzFK5mrQqg6XJEY7E7LHXCS qXfN0CrNmVLL5RqqMO2ExPF2/2gYLc1Y2vQSlNjkxWd5jUKzlOJ4AkNY6K1xJaLcVw== X-Gm-Gg: ATEYQzx8A3Dp9+DjHAkv2WsaQm6BWZ1QF2Uqzpr60mS1GaU5BSB4gJVFiPGleJlQaSr ADEuEMrtP6tcuIs6mA9OzZ+7zZ6/KkCWrOKPFpny7LgYn+kP7UAfLWe8qx/8xWPjbQZ89IsxSE0 4b4N58KcCUkV/VLP9PjlTyE2yQN18FwuqEstKNQ5/TGPGKcqSU4vUi1eU71/xMJgyhYoy3YihFv FJCwz2RvUqXOZyYTFD5v0IYumpgY62yLzFzqiCMSS2MlIqWccK4BaJ1+p5VVahYzxIcYBztXE1W sstmq3Q3RngzE37I2j8co8zNgQ+5bm8XQvKjGW+u2sv76pftVmrR0pBxosfHJdZJadqWFNbc/sB DoI8KtP0aNalDRS/A/dxsY8zK00WaQe+V7joTYFdU6aT2AK80/PWxEISJ0kow/UJ1tTwh9n6MNA zJZ9pr+oR8dVqC/F2exmghqoYLIMiO6BiyDzr+BB2jIOt2AvqvhoLbA2RB X-Received: by 2002:a05:690c:38b:b0:79a:42f3:ff9f with SMTP id 00721157ae682-79a71cb3abdmr54563367b3.56.1773868307398; Wed, 18 Mar 2026 14:11:47 -0700 (PDT) Received: from um773-cachyos.sd.ncsu.edu ([152.7.255.206]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79a7136f0c1sm24377927b3.7.2026.03.18.14.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 14:11:46 -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 , Steven Rostedt , linux-kernel@vger.kernel.org, Zecheng Li , Zecheng Li Subject: [PATCH v9 3/3] sched/fair: Allocate cfs_tg_state with percpu allocator Date: Wed, 18 Mar 2026 17:11:10 -0400 Message-ID: <20260318211139.876385-4-zli94@ncsu.edu> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260318211139.876385-1-zli94@ncsu.edu> References: <20260318211139.876385-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 Reviewed-by: K Prateek Nayak --- kernel/sched/core.c | 35 +++++++++++----------------- kernel/sched/fair.c | 54 ++++++++++++++++++-------------------------- kernel/sched/sched.h | 14 ++++++++---- 3 files changed, 45 insertions(+), 58 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2df42786f780..0e03b257ca9a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8593,7 +8593,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 */ @@ -8609,33 +8609,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 @@ -9545,7 +9536,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); @@ -9713,7 +9704,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 c116e7c2b916..5a6491edcf31 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -334,7 +334,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 @@ -342,7 +342,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 @@ -4387,7 +4387,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); } @@ -5930,7 +5930,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) @@ -6076,7 +6076,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) @@ -6147,7 +6147,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; @@ -6621,8 +6621,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)); @@ -6814,7 +6814,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; @@ -6843,7 +6843,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; @@ -9636,7 +9636,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 @@ -13604,7 +13604,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 @@ -13870,39 +13870,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) - kfree(tg->cfs_rq[i]); - } - - 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_tg_state *state; + struct cfs_tg_state __percpu *state; struct sched_entity *se; struct cfs_rq *cfs_rq; int i; =20 - tg->cfs_rq =3D kzalloc_objs(cfs_rq, nr_cpu_ids); - if (!tg->cfs_rq) + state =3D alloc_percpu_gfp(struct cfs_tg_state, GFP_KERNEL); + if (!state) goto err; =20 + tg->cfs_rq =3D &state->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) { - state =3D kzalloc_node(sizeof(*state), - GFP_KERNEL, cpu_to_node(i)); - if (!state) + cfs_rq =3D tg_cfs_rq(tg, i); + if (!cfs_rq) goto err; =20 - cfs_rq =3D &state->cfs_rq; - se =3D &state->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); @@ -13939,7 +13931,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 @@ -13976,8 +13968,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; @@ -14070,7 +14060,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 258dc689a535..0d0f87e873fe 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -481,7 +481,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 @@ -2259,6 +2259,12 @@ struct cfs_tg_state { struct sched_statistics stats; } __no_randomize_layout; =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) { struct cfs_tg_state *state; @@ -2266,7 +2272,7 @@ static inline struct sched_entity *tg_se(struct task_= group *tg, int cpu) if (is_root_task_group(tg)) return NULL; =20 - state =3D container_of(tg->cfs_rq[cpu], struct cfs_tg_state, cfs_rq); + state =3D container_of(tg_cfs_rq(tg, cpu), struct cfs_tg_state, cfs_rq); return &state->se; } =20 @@ -2290,8 +2296,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.53.0