From nobody Fri Oct 3 07:43:40 2025 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) (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 4021636808C for ; Wed, 3 Sep 2025 19:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756928711; cv=none; b=qGlJRnaOyBZdgvxsutWM9ruqoy16IeAQWOzyawCOLsQF5eK7o6Fi/1aAab96tfMFGUUEvoediS086FqKvAyDXrAMNJrFvCojeylKS3IPWIkfBohrm9GGb0dE69ycTJrkEmMkF/8wJbT0uG0pt55me0tlMGleEiLsGfQ3W08VqDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756928711; c=relaxed/simple; bh=7IEWcm8us9vmBMU3584kE797tvzwdo7OwGXxguuwARQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VdIVIVB7+PHwzgF4GYxX2SSo9RzLe4KyyCizJQbx2qW5UDJsM5qZQ3hyTHUvUVlFoDvoMLIurc9CZHhkCR4bA1TUIr64uPMPpyl6uCvLp5tR1/JXeORNpb92dY3cMxquzuKivx2h5KTt4lShLrxC6DYiARNLm5VebNTXqT65rq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--zecheng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RAqFij9G; arc=none smtp.client-ip=209.85.222.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--zecheng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RAqFij9G" Received: by mail-qk1-f202.google.com with SMTP id af79cd13be357-804512c4373so60037385a.3 for ; Wed, 03 Sep 2025 12:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756928709; x=1757533509; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jPmZgpH78dyHbtmHWdLrneqqYQ+ydVlA4Y0sZXa+eVk=; b=RAqFij9Gcl1eGj0dY3HfHktHL+oL5I1N277FadHAusUArPOwG+rsfAcv7HEdAaP+qs XtFOBuqlYleQ6OOxWEGHYqTLbTafr1Mp+2pomrYYokroYD3WD7Ejyr9gPctwL+Q0RlQf XPAN+yNvjY66UnugCk9QgFFv/m5ctlrI14O5NJpSl5kuJYG6d+dTZMYb5Sp3NoLNmGAO DkZA9fQGwafqVbfZBT1m2cObwwb9ndPmFDQi8GJWDtBlk3aCZidsXV9mG6v7rhsfA8rx jRwTF7aAUKaD/0bEHX8RCVMjHgxTy39pTCB2BSzZq/239hW08vsttM593CDn4IosKixI 2tfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756928709; x=1757533509; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jPmZgpH78dyHbtmHWdLrneqqYQ+ydVlA4Y0sZXa+eVk=; b=LQFIi31Kahnz5ADmzZDcD1+PiMPj3Rok8tplcSuvQX2M+llZL9yl76rOXFlKWEnxZo 7W4eClDtjm102Hjol7hfn04EZNn3S5q/rNNAwpa65j5POoDqz/QOg7EYyQWaNxnisH+c vsKjPQ2fEHC4rUOD5dxV0wwdOYyvbtqfsizV8eVkyorzTp8k6DSZ5qJ7BD4V+xYdTL8U W544dDU9DgBKi8QQbIL2lK9QlL7WhZ45nVpdmtFu6EoDbJgiTLTXENskjBhvOckZD0Sx bwnSHh/GaoA1Uw0RqZtQZxtW1sXCCMkHPJUfaoQCfaBeN/xdy+L/SbXPHaGPdUw49J2K ld8g== X-Forwarded-Encrypted: i=1; AJvYcCUUb8W3oHtuz5S0+OoxkPFRPhed5TAfYNwfGTjERWq6iwzeslvAshOcKC29v04YMwBj9H0vyTVWlXIbK3w=@vger.kernel.org X-Gm-Message-State: AOJu0YzI7XxQHUEXLgFelsOWTMNo2fcnsEfBfEMIfUPbQOwftC0EJmUX RtPxvjpeZYYHMKCzFo00IChofzsCl1j4+Zyu3lDr2U84NNYiuL2F3m+4EejbMbWJg4qT+4CBmfL rZx3B2Ke2WA== X-Google-Smtp-Source: AGHT+IFG2nR6q1V9H6XX2gR8HGprCJoeGE60Pt9bBvsRouwz10WVe8PH4nhkKWJ6ijEYAfSVxpBEwSLhx64d X-Received: from qkbdx3.prod.google.com ([2002:a05:620a:6083:b0:808:15f9:475]) (user=zecheng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:a80a:b0:801:a5f7:1645 with SMTP id af79cd13be357-801a5f71a68mr1334143785a.85.1756928709114; Wed, 03 Sep 2025 12:45:09 -0700 (PDT) Date: Wed, 3 Sep 2025 19:45:00 +0000 In-Reply-To: <20250903194503.1679687-1-zecheng@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250903194503.1679687-1-zecheng@google.com> X-Mailer: git-send-email 2.51.0.338.gd7d06c2dae-goog Message-ID: <20250903194503.1679687-2-zecheng@google.com> Subject: [PATCH v4 1/3] sched/fair: Co-locate cfs_rq and sched_entity 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 , linux-kernel@vger.kernel.org, Zecheng Li Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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: - Defines the new struct cfs_rq_with_se. - 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 --- kernel/sched/fair.c | 23 ++++++++++------------- kernel/sched/sched.h | 8 ++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index df8dc389af8e..fc8bc2d4614f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13321,10 +13321,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); @@ -13333,6 +13334,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; @@ -13349,16 +13351,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), + combined =3D kzalloc_node(sizeof(struct cfs_rq_with_se), GFP_KERNEL, cpu_to_node(i)); - if (!cfs_rq) + 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->se; init_cfs_rq(cfs_rq); init_tg_cfs_entry(tg, cfs_rq, se, i, parent->se[i]); init_entity_runnable_average(se); @@ -13366,8 +13365,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 b5367c514c14..8b37de788eeb 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -745,6 +745,14 @@ struct cfs_rq { #endif /* CONFIG_FAIR_GROUP_SCHED */ }; =20 +#ifdef CONFIG_FAIR_GROUP_SCHED +struct cfs_rq_with_se { + struct cfs_rq cfs_rq; + /* cfs_rq's sched_entity on parent runqueue */ + struct sched_entity se ____cacheline_aligned; +}; +#endif + #ifdef CONFIG_SCHED_CLASS_EXT /* scx_rq->flags, protected by the rq lock */ enum scx_rq_flags { base-commit: 5b726e9bf9544a349090879a513a5e00da486c14 --=20 2.51.0.338.gd7d06c2dae-goog From nobody Fri Oct 3 07:43:40 2025 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) (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 65B6A369963 for ; Wed, 3 Sep 2025 19:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756928713; cv=none; b=twIztyVr9u0JJjkfrlRY5+ZrTUrxm9p6aQKGZDFD0EgoWwn4x/0NUPaPzkNXuh1OY+6FNgkJ93ixbLBxiZP8URaIuUJLu1vA40x6WFQBF0G1zJvxWe2nuC4tiZ0kuIyCotCDKBU/sn06Vbs4S+kHQKFG2t+ihdqdDcGVVme627w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756928713; c=relaxed/simple; bh=FMBiWzNwTzzlN5GTyRqSv0FYEs/GD6WMfrSmQIzif10=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lz9AVhFWLJGc6kwEYvAYx58RDlb7kLVy4/nMdGjSgVboF+KgtmcV6xtSoT0nFbLHnPZoIXxyVy+zi+U8YbM99mbI5lB+BB6TXQpLW/GEMjr+JeVDVEITwoUi7ibe+8+nyh4Bvs30PqHsB9ue+k36mZEx0SA9rLxKyxpBkxptOMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--zecheng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DYnWsYgd; arc=none smtp.client-ip=209.85.222.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--zecheng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DYnWsYgd" Received: by mail-qk1-f201.google.com with SMTP id af79cd13be357-80584b42d15so62266785a.3 for ; Wed, 03 Sep 2025 12:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756928710; x=1757533510; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2AZ1QGVNuCg4PV0LCwZKcF9MIi5NqekDv2CLRHczJ3E=; b=DYnWsYgdyze23OWrCGqLqTTUGGQjydDNL3Amzn3kN1As4Pz1gFUtbPPL/WuwY20mcb +F5eFr44hEdsUWpUtt5VGA49xV72vxPy+zJj32pc+dOl13tF5kwo1H5vc+sKdv2cFJrG LM0VOcl9BFChwzY+wopmfASGiPLtfephzc5MCARbjEw1oQN7xbWflMvfqhiqDpCW2H32 qeDXSvKwK1hw/Y13/zO1PWacxiPqyfI0o/xsGk1/YEgT5PczW8myAoIpmzqX2gOGNcPT lEwd/MwmYpnF/ZU4nORgnpy80twa+a+F3Y74OnDWBMNNilKd5sPVZpjFSgC6LAEQDAHl Zp3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756928710; x=1757533510; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2AZ1QGVNuCg4PV0LCwZKcF9MIi5NqekDv2CLRHczJ3E=; b=lNsWdSeHPpMK5afJmup+7U2IsIJ82zMg9KyQgOns2YCsNrItGeQV8oV2Cx2utRT1TT 8LGgg9bQhb/v6a7qcL1FJ40eyCQqC8PcQAmipZyPhVI1oHF8ja7hS/3rCJi3WJwC/78q rSeL8olkKcKEKLowrjmlUtlD9bogiUBy9dYNMu8mGguJ3dGvnO92D/BO11LhPksrUEpp af46VOtgo4dgVeQXLD0al7eYytBcWXqm9YAcrdXd0hwFSanw2dR3AQyMEnmBlFIyxy4j DfITqGAAKyKZRc3VO9nSFHT/5mK1ktjuWh6+/osJKuVvQfH2aE4d0iibZyBNmhOuqZ1p Xvkw== X-Forwarded-Encrypted: i=1; AJvYcCXP3hYhvUJsbKPJPxNUmRo+En/+0A1tgcwtBVNVhQRFAYfnKzIN1bINyi4GdWwUcXUfRsqJCTJgem2o2Jo=@vger.kernel.org X-Gm-Message-State: AOJu0YxCKpm9fqwoCpVyO4nYddz8xXQbBMO//NL069p8amwq08+MLM4t kHSUN3XxAKjrv6OKyHdaQx4C/kFLFdIkQ/Kkw1dGuLP7RBOb8f7ZJIr2QDRN+m1XMa1H46H/6eT vpGluWXmG9w== X-Google-Smtp-Source: AGHT+IHv23SMUkd7fwdpw2+BVynRXXTL1YDNbdD21QcOQYgGUL0ZBwr2CMUnzubMXyKpHgBGLDOSQuQ2JBL2 X-Received: from qknqb2.prod.google.com ([2002:a05:620a:6502:b0:80e:b15:b019]) (user=zecheng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:3909:b0:7e9:f820:2b7e with SMTP id af79cd13be357-7ff2cbd845dmr1659910385a.84.1756928710177; Wed, 03 Sep 2025 12:45:10 -0700 (PDT) Date: Wed, 3 Sep 2025 19:45:01 +0000 In-Reply-To: <20250903194503.1679687-1-zecheng@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250903194503.1679687-1-zecheng@google.com> X-Mailer: git-send-email 2.51.0.338.gd7d06c2dae-goog Message-ID: <20250903194503.1679687-3-zecheng@google.com> Subject: [PATCH v4 2/3] sched/fair: Remove task_group->se pointer array 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 , linux-kernel@vger.kernel.org, Zecheng Li Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- kernel/sched/core.c | 7 ++----- kernel/sched/debug.c | 2 +- kernel/sched/fair.c | 27 ++++++++++----------------- kernel/sched/sched.h | 29 ++++++++++++++++++++++++----- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index feb750aae71b..11efddf383ed 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8691,7 +8691,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 **); @@ -8700,9 +8700,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 @@ -9785,7 +9782,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 02e16b70a790..16542596d4b0 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 fc8bc2d4614f..8777e288f0e0 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6014,7 +6014,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; =20 /* * It's possible we are called with !runtime_remaining due to things @@ -6029,7 +6029,7 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq) if (cfs_rq->runtime_enabled && cfs_rq->runtime_remaining <=3D 0) return; =20 - se =3D cfs_rq->tg->se[cpu_of(rq)]; + se =3D cfs_rq_se(cfs_rq); =20 cfs_rq->throttled =3D 0; =20 @@ -9763,7 +9763,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 @@ -9783,7 +9782,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 @@ -9809,8 +9808,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 @@ -13329,7 +13327,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) @@ -13342,9 +13339,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 @@ -13359,7 +13353,7 @@ int alloc_fair_sched_group(struct task_group *tg, s= truct task_group *parent) cfs_rq =3D &combined->cfs_rq; se =3D &combined->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 @@ -13378,7 +13372,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); @@ -13395,7 +13389,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) { @@ -13432,7 +13426,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) @@ -13463,7 +13456,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)); @@ -13474,7 +13467,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 */ @@ -13525,7 +13518,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 8b37de788eeb..2b350c25f116 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -452,8 +452,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; @@ -899,7 +897,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 @@ -1583,6 +1582,26 @@ static inline struct task_struct *task_of(struct sch= ed_entity *se) return container_of(se, struct task_struct, se); } =20 +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->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->se; +} + static inline struct cfs_rq *task_cfs_rq(struct task_struct *p) { return p->se.cfs_rq; @@ -2151,8 +2170,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.51.0.338.gd7d06c2dae-goog From nobody Fri Oct 3 07:43:40 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 B892D36999D for ; Wed, 3 Sep 2025 19:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756928716; cv=none; b=uXozn9VUnre4SrMK4gTqPyWOKwZMge2+JQvetzCsOQNQNjOpfW45OhbnpSeTXJCqGJh82+U5RXRJWjdkbweGKFojREBM0pk3IXdnMX17bCwTumpyMoGNNqlGgIEv0xOmoYp349IAqPRT7tEgc+IR9nY/4PrPs2yrdlM9Vkx3i5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756928716; c=relaxed/simple; bh=yeNTnbTZHiN8c1nGkA0zioSsJAz8wd4K7GS/fVdBAU8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TxEI50VY8dcWde9RdnR0jNIf+by30ZjEM+QiM10w1nTCrjo9ULBYJcDg03etoJFNRRlDz07YUK0ceIcopA5elKef/kixCHHFX8EMpA6roib7nTyZ+adZEccTb2lYcfN+krYASbxSHMZOhZsiCBgh5MXoZa3mvb4CDt+PwNO5V2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--zecheng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Kr0lKcjM; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--zecheng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Kr0lKcjM" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-71d603bf1c4so4585507b3.1 for ; Wed, 03 Sep 2025 12:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756928711; x=1757533511; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GG48k3biDVzwK4t/1L7jbByzp/D3GDddVkiJ5P6Qq+o=; b=Kr0lKcjMq0P9Hn3+pjePTIS77eJTB9qljQGGQBgY2yVjTiiF72m3rHQuGQIXuNBNX+ rJC5Qy9S9fk2fZ2Jtu9pMu+6obQd5sv4ubLs9VfLkP8YsQu/Nb39B4C9o2dzOCSABL2P ynPNs5w0+D7XV33KeJ1RqwmGZAaXEWnvVMHct3C+cewWtiXH8TzWC4sgeUueBQ/8XbMb MJtJr/3lb1uRdHOjjQCfAa1RVml0hbIC1an2UMsBuD5cIG99Oa49sDziW6l687jJeZZL D3cCskeo3q6JtwWBMGqwR6nRJsP9p0IQSa1uAlwbSjADIIHnCPC12MawQYRcKff9Nv0l xBXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756928711; x=1757533511; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GG48k3biDVzwK4t/1L7jbByzp/D3GDddVkiJ5P6Qq+o=; b=AugyO+Jz0Le5ick/BYmcPfK7OBGmdqoWNklAisPVFXIhXzCqTIz6ZTPr3O5lj4XJje vqonkE06NQxff6QpTQhV9Xkuq/Rw9W/yg8ZwO47fZHOjgUzpQTLnuG1Ap7gIg47xQ5JW +/6TnzTkxdGQKgaycrMGm8IwYr7Nx1HDx+1OE5VTvTK5cJj65qOZuDeJoSrhWWVlu1LC Oqd7PvC2GzF6riTZeDXUkT0M9PxT/KPr4y+BuJwgUTsoFSufgEDlTl719sWgtA/iysAL Y4lEFT+rIed1OLLaJnUuFQLwFQJ4NVzCEhe8vkMj75EqlPCKJycI5pJeGbsB7xlAxJAk WUIg== X-Forwarded-Encrypted: i=1; AJvYcCVhKb5gYMJfMrf2yqwIfUj4x9bjPcmyxeXwCOZcqOD3ySHKySsfpCqmnv4ieL3VsCEY96Dv7U6YmrMKpoc=@vger.kernel.org X-Gm-Message-State: AOJu0YyrPxAlevp7biVr+MbsVcJHnaBmrBbjyZfYPf9pQmNwDPplTAoN 7DSGs7XfYMHnSUE5uJLt5g5F65ZlgiiPEhVulf/4Yqed3YPbbVmgvB0cVTS25Fs4JKkL4QfBDPx K9mIUjkGoAw== X-Google-Smtp-Source: AGHT+IGB9OFaRNFhLGuEFvu5jHvJV5f5vxk/k6yWY4OlIds6qF4P39SVTU8d8MEQR9NIDMzHNgUdc3qOC/2g X-Received: from ywmv11.prod.google.com ([2002:a81:fa0b:0:b0:71f:ea49:b54f]) (user=zecheng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:690c:6608:b0:722:7324:dc42 with SMTP id 00721157ae682-7227656be12mr189350117b3.47.1756928711497; Wed, 03 Sep 2025 12:45:11 -0700 (PDT) Date: Wed, 3 Sep 2025 19:45:02 +0000 In-Reply-To: <20250903194503.1679687-1-zecheng@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250903194503.1679687-1-zecheng@google.com> X-Mailer: git-send-email 2.51.0.338.gd7d06c2dae-goog Message-ID: <20250903194503.1679687-4-zecheng@google.com> Subject: [PATCH v4 3/3] sched/fair: Allocate both cfs_rq and sched_entity with per-cpu 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 , linux-kernel@vger.kernel.org, Zecheng Li Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- kernel/sched/core.c | 35 +++++++++++----------------- kernel/sched/fair.c | 55 +++++++++++++++++--------------------------- kernel/sched/sched.h | 13 +++++++---- 3 files changed, 43 insertions(+), 60 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 11efddf383ed..cbc97fd5b69c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8675,7 +8675,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 */ @@ -8691,33 +8691,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 @@ -9633,7 +9624,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); @@ -9801,7 +9792,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 8777e288f0e0..4a32ed5411e6 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 @@ -4144,7 +4144,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); } @@ -5878,7 +5878,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) @@ -5949,7 +5949,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; @@ -6425,8 +6425,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)); @@ -6608,7 +6608,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; @@ -6637,7 +6637,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; @@ -9336,7 +9336,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 @@ -13068,7 +13068,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 @@ -13316,42 +13316,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(struct cfs_rq_with_se), - 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->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); @@ -13388,7 +13377,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 @@ -13425,8 +13414,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; @@ -13519,7 +13506,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 2b350c25f116..1bd85a062e19 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -453,7 +453,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 @@ -1581,6 +1581,11 @@ static inline struct task_struct *task_of(struct sch= ed_entity *se) WARN_ON_ONCE(!entity_is_task(se)); return container_of(se, struct task_struct, se); } +/* 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); +} =20 static inline struct sched_entity *tg_se(struct task_group *tg, int cpu) { @@ -1588,7 +1593,7 @@ static inline struct sched_entity *tg_se(struct task_= group *tg, int cpu) 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->se; } =20 @@ -2168,8 +2173,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.51.0.338.gd7d06c2dae-goog