sched/topology: Count LLCs per node from the sched groups
PATCH 1/1 sched/topology: Count LLCs per node from the sched groups
adjust_numa_imbalance() sets imb_numa_nr from the number of LLCs under the LLC's parent domain, so that tasks spill over to another node only once every LLC of the local node is in use. It estimates that number by dividing the parent's span weight by the LLC's.
The division assumes all LLCs in a node are the same size. On a Hygon C86-4G 7493 each node has four CCXs of 4, 4, 3 and 3 cores, as two core slots per node are fused off, giving LLCs of 8, 8, 6 and 6 CPUs out of
28. CPUs in the larger CCXs compute 28 / 8 = 3 LLCs and the others 28 / 6 = 4, so CPUs of the same node apply different imbalance limits at every NUMA level.
Count the parent's sched groups instead. They are built from the child domains, one per LLC, before imb_numa_nr is computed, and give the same count as the division when all LLCs are the same size.
imb_numa_nr per domain on a KVM guest with that node layout (2 sockets x 2 nodes, SLIT 15/25/27, fused-off core slots offlined), read through a debugfs file added for the test; change is for the 4-core CCXs:
domain (CPUs) before, 4-core CCX before, 3-core CCX after change
NODE (28) 3 4 4 +33% NUMA (56) 3 4 4 +33% NUMA (84) 3 4 4 +33% NUMA (112) 6 8 8 +33%
--- kernel/sched/topology.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
kernel/sched/topology.c +14 -2
@@ -2893,8 +2893,9 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc) {struct sched_domain *parent;unsigned int imb_span =1 ; +unsigned int nr_llcs =0 ; +struct sched_group *sg;unsigned int imb =0 ; -unsigned int nr_llcs;WARN_ON (!(sd_llc->flags &SD_SHARE_LLC ));WARN_ON (!sd_llc->parent);
@@ -2918,8 +2919,19 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc)* enough logical CPUs per LLC to avoid SMT * factors and that there is a correlation * between LLCs and memory channels. +* +* Count the LLCs through the parent's groups, one +* per LLC, rather than dividing the spans: LLCs +* in a node need not be the same size (e.g. when +* some cores of a CCX are fused off), and the +* quotient then depends on which LLC the CPU is in. */ - nr_llcs = sd_llc->parent->span_weight / sd_llc->span_weight; + sg = sd_llc->parent->groups; +do { + nr_llcs++; + sg = sg->next; + }while (sg != sd_llc->parent->groups); +if (nr_llcs ==1 ) imb = sd_llc->parent->span_weight >>3 ;else
---
base-commit: c47af85667065c6dd5b79564203c2d29948ef60e
change-id: 20261125-feat-sched-nr-llcs-a1a82664eac0
Best regards,
Signature · 1 line
Qiliang Yuan <[email protected]>
Hi Qiliang,
Quoted 55 lines · Qiliang Yuan
adjust_numa_imbalance()setsimb_numa_nrfrom the number of LLCs under the LLC's parent domain, so that tasks spill over to another node only once every LLC of the local node is in use. It estimates that number by dividing the parent's span weight by the LLC's.The division assumes all LLCs in a node are the same size. On a Hygon C86-4G 7493 each node has four CCXs of 4, 4, 3 and 3 cores, as two core slots per node are fused off, giving LLCs of 8, 8, 6 and 6 CPUs out of
28. CPUs in the larger CCXs compute 28 / 8 = 3 LLCs and the others 28 / 6 = 4, so CPUs of the same node apply different imbalance limits at every NUMA level.Count the parent's sched groups instead. They are built from the child domains, one per LLC, before
imb_numa_nris computed, and give the same count as the division when all LLCs are the same size.
imb_numa_nrper domain on a KVM guest with that node layout (2 sockets x 2 nodes, SLIT 15/25/27, fused-off core slots offlined), read through a debugfs file added for the test; change is for the 4-core CCXs:domain (CPUs) before, 4-core CCX before, 3-core CCX after change
NODE (28) 3 4 4 +33% NUMA (56) 3 4 4 +33% NUMA (84) 3 4 4 +33% NUMA (112) 6 8 8 +33%Fixes e496132ebedd ("sched/fair: Adjust the allowed NUMA imbalance when SD_NUMA spans multiple LLCs")Signed-off-by Qiliang Yuan <[email protected]>--- kernel/sched/topology.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)kernel/sched/topology.c +6
-1@@ -2893,8 +2893,9 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc) {struct sched_domain *parent;unsigned int imb_span =1 ; +unsigned int nr_llcs =0 ; +struct sched_group *sg;unsigned int imb =0 ; -unsigned int nr_llcs;WARN_ON (!(sd_llc->flags &SD_SHARE_LLC ));WARN_ON (!sd_llc->parent);@@ -2918,8 +2919,19 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc)* enough logical CPUs per LLC to avoid SMT * factors and that there is a correlation * between LLCs and memory channels. +* +* Count the LLCs through the parent's groups, one +* per LLC, rather than dividing the spans: LLCs +* in a node need not be the same size (e.g. when
kernel/sched/topology.c static void adjust_numa_imbalance(struct sched_domain *sd_llc) · line 2934
Quoted 10 lines
kernel/sched/topology.c +8
-1+* some cores of a CCX are fused off), and the +* quotient then depends on which LLC the CPU is in. */ - nr_llcs = sd_llc->parent->span_weight / sd_llc->span_weight; + sg = sd_llc->parent->groups; +do { + nr_llcs++; + sg = sg->next; + }while (sg != sd_llc->parent->groups); +
I have a suggestion: add a static key switch. During scheduling-domain initialization or rebuild, if an asymmetric LLC layout is detected, enable the key and take the new code path. The key is disabled by default, so the original code path is retained.
Quoted 10 lines
kernel/sched/topology.c +0
-1if (nr_llcs ==1 ) imb = sd_llc->parent->span_weight >>3 ;else ---base-commit:
c47af85667065c6dd5b79564203c2d29948ef60e
change-id: 20261125-feat-sched-nr-llcs-a1a82664eac0Best regards,
Signature · 2 lines
thanks, kunyu