From nobody Sat Feb 7 07:10:31 2026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.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 6D9A61E32CF for ; Mon, 19 Jan 2026 03:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768795081; cv=none; b=cerMWW7inzHPMFffa9aMlSd+zbYzaSEPESlmoMS/9UT9SZhFdSzMaDeG5gaff309u3tV+lHVp3Vk91iLKFaxYR3Dee3rAWSo22ga33jF9yO6u8HEJSmMGXv3ByCW/2YOVcXjrny/mD6TIDQ2FhXfv2Dxf/SvqJrUWs/NK3fP76Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768795081; c=relaxed/simple; bh=6vh46ee1T1vepkTmqE6hgg3/td4HcoX8jcui/atfhkg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EJQ7nAU5UcFpS/vQVGjJc7ElMt0xiZXXZGP4yb5I9bY+l9tsYH+XU2WFDTEVui5W6KhoGe7JnJIembxD6LyXkIxZAlyDLO+CB7uDdKXMzWgWB/Q5WZrVDaEM3NaXs/q1IiSWSDl7GZCtDB1z10AjtQ3s0mw8xOzlP9ma9FBeH/c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bo1n3R13; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bo1n3R13" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-81f4f4d4822so1591642b3a.3 for ; Sun, 18 Jan 2026 19:58:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768795080; x=1769399880; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TMHYJNAqCL4nreiq+wlixHTxjLKzEa3QYPznJjCZEyk=; b=bo1n3R13VLgr6ETdQ9dWUKDdP9GrEsUFjuBnSWZtS1ey7qBQ6xnBrCeYxJXoL028yx wedNKjP39eDHU2PyhETl6FbmvylSq6h+WDjcnOSP1gJNxuWmTmdxGomc6j2CPBIhKvQi zSm2Fw9NS0xhSFLNYu8hTUkKZaevKs6rm9kmVK6uo6XHcO5qWqPSgbjLBJZvylgMTOf0 QFLRV7/4nfNBcGdx01qkrl/Gk28POtCtooqVJ/1Voa4zfWIp5LKoeodvOZLyzNJnJY+9 WfWVAkc8NcDyoiqVMRws/X7iXFLkcw/H+N4KWj84kzULF4B+2C7rwYzBjjUDbl1WeIdl SdXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768795080; x=1769399880; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TMHYJNAqCL4nreiq+wlixHTxjLKzEa3QYPznJjCZEyk=; b=MYPEj2gn7qJJKX4+RtvC4uh0jOovKmZrvTHMajuTF9t+Ncy1PoSbCVRFGDe64MSkbR naKvzHhb9jc5DqGpcWm5djBecOC3hRQaUBXf3QHf0M/Lf8T45ZrfA3mas0+9jJUjDq5R Q+aLg++OsTcxcNDB6TaxvRe3liWAryOB0lQicBwYYRQrf2wAlf+IyYpgWF4Lj+vQt8Gv IbJbSnrC4EidEIdg3tw5eNtSzVQsSJ1mH3s9oialX1ZfjeCaVkLEB/3ms6GqGpLaA+7p nWSM7h3ccst3B5mEGXV4oftxvnDzEYGaxr/kzJyweSaTqx1G8sHJq4cQWRwOVeSxR8Pn qKfg== X-Gm-Message-State: AOJu0Yw5WMuGD4OMsuX/2mtZURW+59dgFqZfLkKsXVUTlDgUh2kyRBau wEKKhYsEiWZSOAPMGFQ2v4z3KOITvhL15F72Au5G15lER4bS56wfnRtQ X-Gm-Gg: AY/fxX6oWXvroo2/e/EJO7jb7b6vMgZPLAEdhSzGvuqfcZ5ObGgqzGS99qDSWcBJvOA QRp2IA4KY5DY0TFv3NmovWeIDr5L9RamjPatqKfsUoJlCoMdN0omXcafZX5J1gtyRULhY3W1ThT P+uwzcU06g96JGTDC+CTQcNhQBOQHoRy7rwMKODAV9tJZS8+w0eLaVOfxEDZaPuU/oEU30gQjS/ OIcSRg6ekbu929Q7UGzOMWNnguJk0g5loYWFg8sDO4SYaETBla19e7D0EJ9iP8GEfC8vM8LfjWh lxRHspvEeh7Ew/gEXQJVz2+XxO7c5gXqjx3UccsY4lPQ7O9nbZi4VN1wxAGcGIP8h1RDTWq/wR7 rH9MJiKcgmDLKH+z5Xkro3bxxUywRrLR304GBAp4eXlGNgzlG+0gYWOuG3VCpo0V9jX4tXqWe0B i6eeauzs9KjzS442oPtuUa/N4kuLotQKezuFb+MrTZkfo= X-Received: by 2002:a05:6a00:1d03:b0:81f:852b:a922 with SMTP id d2e1a72fcca58-81fa0340a8dmr7617541b3a.67.1768795079655; Sun, 18 Jan 2026 19:57:59 -0800 (PST) Received: from localhost.localdomain ([117.88.121.68]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-81fa108b21fsm7743366b3a.13.2026.01.18.19.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jan 2026 19:57:59 -0800 (PST) From: Tianxiang Peng X-Google-Original-From: Tianxiang Peng To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com Cc: linux-kernel@vger.kernel.org, flyingpeng@tencent.com, Tianxiang Peng Subject: [PATCH] sched/topology: delay imb_numa_nr calculation until after domain degeneration Date: Mon, 19 Jan 2026 11:57:27 +0800 Message-ID: <20260119035727.2867477-1-txpeng@tencent.com> X-Mailer: git-send-email 2.43.5 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" Currently, imb_numa_nr is calculated before sched_domain degeneration in cpu_attach_domain(), which might reflect a transient topology that no longer exists. This is observed on our Kunpeng 920 systems (4 NUMA nodes, 80 cores per node, 8 cores per cluster), where the initial PKG domain is redundant with the MC domain and subsequently removed. Observed topology data on Kunpeng 920: Topology order: Child -> Parent [Before Patch] (before degeneration) Domains: CLS(8) -> MC(80) -> PKG(80) Flags: [LLC] [LLC] [!LLC] imb_numa_nr: 0 0 10 (after degeneration) Domains: CLS(8) -> MC(80) -> NUMA(160) Flags: [LLC] [LLC] [!LLC] imb_numa_nr: 0 0 10 [After Patch] (before degeneration) Domains: CLS(8) -> MC(80) -> PKG(80) Flags: [LLC] [LLC] [!LLC] (after degeneration) Domains: CLS(8) -> MC(80) -> NUMA(160) Flags: [LLC] [LLC] [!LLC] imb_numa_nr: 0 0 2 Move the calculation to cpu_attach_domain() after degeneration to ensure it always reflects the effective topology. Signed-off-by: Tianxiang Peng Reviewed-by: Hao Peng --- kernel/sched/topology.c | 115 ++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index cf643a5ddedd..e8774e587f15 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -717,6 +717,8 @@ cpu_attach_domain(struct sched_domain *sd, struct root_= domain *rd, int cpu) { struct rq *rq =3D cpu_rq(cpu); struct sched_domain *tmp; + unsigned int imb =3D 0; + unsigned int imb_span =3D 1; =20 /* Remove the sched domains which do not contribute to scheduling. */ for (tmp =3D sd; tmp; ) { @@ -764,6 +766,61 @@ cpu_attach_domain(struct sched_domain *sd, struct root= _domain *rd, int cpu) } } =20 + /* + * Calculate an allowed NUMA imbalance such that LLCs do not get + * imbalanced. + * Perform this calculation after domain degeneration so that + * sd->imb_numa_nr reflects the final effective topology. + */ + for (tmp =3D sd; tmp; tmp =3D tmp->parent) { + struct sched_domain *child =3D tmp->child; + + if (!(tmp->flags & SD_SHARE_LLC) && child && + (child->flags & SD_SHARE_LLC)) { + struct sched_domain __rcu *top_p; + unsigned int nr_llcs; + + /* + * For a single LLC per node, allow an + * imbalance up to 12.5% of the node. This is + * arbitrary cutoff based two factors -- SMT and + * memory channels. For SMT-2, the intent is to + * avoid premature sharing of HT resources but + * SMT-4 or SMT-8 *may* benefit from a different + * cutoff. For memory channels, this is a very + * rough estimate of how many channels may be + * active and is based on recent CPUs with + * many cores. + * + * For multiple LLCs, allow an imbalance + * until multiple tasks would share an LLC + * on one node while LLCs on another node + * remain idle. This assumes that there are + * enough logical CPUs per LLC to avoid SMT + * factors and that there is a correlation + * between LLCs and memory channels. + */ + nr_llcs =3D tmp->span_weight / child->span_weight; + if (nr_llcs =3D=3D 1) + imb =3D tmp->span_weight >> 3; + else + imb =3D nr_llcs; + imb =3D max(1U, imb); + tmp->imb_numa_nr =3D imb; + + /* Set span based on the first NUMA domain. */ + top_p =3D tmp->parent; + while (top_p && !(top_p->flags & SD_NUMA)) { + top_p =3D top_p->parent; + } + imb_span =3D top_p ? top_p->span_weight : tmp->span_weight; + } else { + int factor =3D max(1U, (tmp->span_weight / imb_span)); + + tmp->imb_numa_nr =3D imb * factor; + } + } + sched_domain_debug(sd, cpu); =20 rq_attach_root(rq, rd); @@ -2600,64 +2657,6 @@ build_sched_domains(const struct cpumask *cpu_map, s= truct sched_domain_attr *att } } =20 - /* - * Calculate an allowed NUMA imbalance such that LLCs do not get - * imbalanced. - */ - for_each_cpu(i, cpu_map) { - unsigned int imb =3D 0; - unsigned int imb_span =3D 1; - - for (sd =3D *per_cpu_ptr(d.sd, i); sd; sd =3D sd->parent) { - struct sched_domain *child =3D sd->child; - - if (!(sd->flags & SD_SHARE_LLC) && child && - (child->flags & SD_SHARE_LLC)) { - struct sched_domain __rcu *top_p; - unsigned int nr_llcs; - - /* - * For a single LLC per node, allow an - * imbalance up to 12.5% of the node. This is - * arbitrary cutoff based two factors -- SMT and - * memory channels. For SMT-2, the intent is to - * avoid premature sharing of HT resources but - * SMT-4 or SMT-8 *may* benefit from a different - * cutoff. For memory channels, this is a very - * rough estimate of how many channels may be - * active and is based on recent CPUs with - * many cores. - * - * For multiple LLCs, allow an imbalance - * until multiple tasks would share an LLC - * on one node while LLCs on another node - * remain idle. This assumes that there are - * enough logical CPUs per LLC to avoid SMT - * factors and that there is a correlation - * between LLCs and memory channels. - */ - nr_llcs =3D sd->span_weight / child->span_weight; - if (nr_llcs =3D=3D 1) - imb =3D sd->span_weight >> 3; - else - imb =3D nr_llcs; - imb =3D max(1U, imb); - sd->imb_numa_nr =3D imb; - - /* Set span based on the first NUMA domain. */ - top_p =3D sd->parent; - while (top_p && !(top_p->flags & SD_NUMA)) { - top_p =3D top_p->parent; - } - imb_span =3D top_p ? top_p->span_weight : sd->span_weight; - } else { - int factor =3D max(1U, (sd->span_weight / imb_span)); - - sd->imb_numa_nr =3D imb * factor; - } - } - } - /* Calculate CPU capacity for physical packages and nodes */ for (i =3D nr_cpumask_bits-1; i >=3D 0; i--) { if (!cpumask_test_cpu(i, cpu_map)) --=20 2.43.5