sched/topology: Introduce NUMA identity node sched domain
RFC PATCH 1/1 sched/topology: Introduce NUMA identity node sched domain
On AMD Family17h-based (EPYC) system, a NUMA node can contain upto 8 cores (16 threads) with the following topology.
----------------------------
C0 | T0 T1 | || | T0 T1 | C4
--------| || |--------
C1 | T0 T1 | L3 || L3 | T0 T1 | C5
--------| || |--------
C2 | T0 T1 | #0 || #1 | T0 T1 | C6
--------| || |--------
C3 | T0 T1 | || | T0 T1 | C7
----------------------------Here, there are 2 last-level (L3) caches per NUMA node. A socket can contain upto 4 NUMA nodes, and a system can support upto 2 sockets. With full system configuration, current scheduler creates 4 sched domains:
domain0 SMT (span a core) domain1 MC (span a last-level-cache) domain2 NUMA (span a socket: 4 nodes) domain3 NUMA (span a system: 8 nodes)
Note that there is no domain to represent cpus spaning a NUMA node. With this hierachy of sched domains, the scheduler does not balance properly in the following cases:
Case1:
When running 8 tasks, a properly balanced system should schedule a task per NUMA node. This is not the case for the current scheduler.
Case2:
When running 'taskset -c 0-7 <a_program_with_8_independent_threads>', a properly balanced system should schedule 8 threads on 8 cpus (e.g. T0 of C0-C7). However, current scheduler would schedule some threads on the same cpu, while others are idle.
Introducing NUMA identity node sched domain, which is based on how SRAT/SLIT table define a NUMA node. This results in the following hierachy of sched domains on the same system described above.
domain0 SMT (span a core)
domain1 MC (span a last-level-cache)
domain2 NUMA_IDEN (span a NUMA node)
domain3 NUMA (span a socket: 4 nodes)
domain4 NUMA (span a system: 8 nodes)
This fixes the improper load balancing cases mentioned above.
--- kernel/sched/topology.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
kernel/sched/topology.c +21 -3
@@ -1335,6 +1335,10 @@ void sched_init_numa(void)if (!sched_domains_numa_distance)return ; +/* Includes NUMA identity node at level 0. */ + sched_domains_numa_distance[level++] = curr_distance; + sched_domains_numa_levels = level; +/* * O(nr_nodes^2) deduplicating selection sort -- in order to find the * unique distances in the node_distance() table.
@@ -1382,8 +1386,7 @@ void sched_init_numa(void)return ;/* -* 'level' contains the number of unique distances, excluding the -* identity distance node_distance(i,i). +* 'level' contains the number of unique distances * * The sched_domains_numa_distance[] array includes the actual distance * numbers.
@@ -1445,9 +1448,24 @@ void sched_init_numa(void) tl[i] = sched_domain_topology[i];/* +* Ignore the NUMA identity level if it has the same cpumask +* as previous level. This is the case for: +* - System with last-level-cache (MC) sched domain span a NUMA node. +* - System with DIE sched domain span a NUMA node. +* +* Assume all NUMA nodes are identical, so only check node 0. +*/ +if (!cpumask_equal (sched_domains_numa_masks[0 ][0 ], tl[i-1 ].mask (0 ))) + tl[i++] = (struct sched_domain_topology_level ){ + .mask = sd_numa_mask, + .numa_level =0 , +SD_INIT_NAME (NUMA_IDEN ) + }; + +/* * .. and append 'j' levels of NUMA goodness. */ -for (j =0 ; j < level; i++, j++) { +for (j =1 ; j < level; i++, j++) { tl[i] = (struct sched_domain_topology_level ){ .mask = sd_numa_mask, .sd_flags = cpu_numa_flags,
Signature · 1 line
2.7.4
Peter Zijlstra
maintainerQuoted 13 lines · Suravee Suthikulpanit
On AMD Family17h-based (EPYC) system, a NUMA node can contain upto 8 cores (16 threads) with the following topology.
---------------------------- C0 | T0 T1 | || | T0 T1 | C4 --------| || |-------- C1 | T0 T1 | L3 || L3 | T0 T1 | C5 --------| || |-------- C2 | T0 T1 | #0 || #1 | T0 T1 | C6 --------| || |-------- C3 | T0 T1 | || | T0 T1 | C7 ----------------------------
Quoted 7 lines
Here, there are 2 last-level (L3) caches per NUMA node. A socket can contain upto 4 NUMA nodes, and a system can support upto 2 sockets. With full system configuration, current scheduler creates 4 sched domains:
domain0 SMT (span a core)
domain1 MC (span a last-level-cache)
Right, so traditionally we'd have the DIE level do that, but because x86_has_numa_in_package we don't generate that, right?
Quoted 12 lines
domain2 NUMA (span a socket: 4 nodes)
domain3 NUMA (span a system: 8 nodes)Note that there is no domain to represent cpus spaning a NUMA node. With this hierachy of sched domains, the scheduler does not balance properly in the following cases:
Case1:
When running 8 tasks, a properly balanced system should schedule a task per NUMA node. This is not the case for the current scheduler.
Quoted 5 lines
Case2:
When running 'taskset -c 0-7 <a_program_with_8_independent_threads>', a properly balanced system should schedule 8 threads on 8 cpus (e.g. T0 of C0-C7). However, current scheduler would schedule some threads on the same cpu, while others are idle.
Sure.. could you amend with a few actual performance numbers?
Quoted 7 lines
Introducing NUMA identity node sched domain, which is based on how SRAT/SLIT table define a NUMA node. This results in the following hierachy of sched domains on the same system described above.
domain0 SMT (span a core)
domain1 MC (span a last-level-cache)
domain2NUMA_IDEN(span a NUMA node)
Hate that name though..
Quoted 41 lines
domain3 NUMA (span a socket: 4 nodes)
domain4 NUMA (span a system: 8 nodes)This fixes the improper load balancing cases mentioned above.
Signed-off-by Suravee Suthikulpanit <[email protected]>--- kernel/sched/topology.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)kernel/sched/topology.c +7
-2@@ -1335,6 +1335,10 @@ void sched_init_numa(void)if (!sched_domains_numa_distance)return ; +/* Includes NUMA identity node at level 0. */ + sched_domains_numa_distance[level++] = curr_distance; + sched_domains_numa_levels = level; +/* * O(nr_nodes^2) deduplicating selection sort -- in order to find the * unique distances in the node_distance() table. @@ -1382,8 +1386,7 @@ void sched_init_numa(void)return ;/* -* 'level' contains the number of unique distances, excluding the -* identity distance node_distance(i,i). +* 'level' contains the number of unique distances * * The sched_domains_numa_distance[] array includes the actual distance * numbers. @@ -1445,9 +1448,24 @@ void sched_init_numa(void) tl[i] = sched_domain_topology[i];/* +* Ignore the NUMA identity level if it has the same cpumask +* as previous level. This is the case for:
kernel/sched/topology.c void sched_init_numa(void) · line 1462
Quoted 10 lines
kernel/sched/topology.c +10
-0+* - System with last-level-cache (MC) sched domain span a NUMA node. +* - System with DIE sched domain span a NUMA node. +* +* Assume all NUMA nodes are identical, so only check node 0. +*/ +if (!cpumask_equal (sched_domains_numa_masks[0 ][0 ], tl[i-1 ].mask (0 ))) + tl[i++] = (struct sched_domain_topology_level ){ + .mask = sd_numa_mask, + .numa_level =0 , +SD_INIT_NAME (NUMA_IDEN )
Shall we make that:
SD_INIT_NAME(NODE),
instead?
kernel/sched/topology.c void sched_init_numa(void) · line 1463
Quoted 1 line
kernel/sched/topology.c +1
-0+ };
This misses a set of '{}'. While C doesn't require it, out coding style warrants blocks around any multi-line statement.
So what you've forgotten to mention is that for those systems where the LLC == NODE this now superfluous level gets removed by the degenerate code. Have you verified that does the right thing?
Quoted 12 lines
kernel/sched/topology.c +3
-1+ +/* * .. and append 'j' levels of NUMA goodness. */ -for (j =0 ; j < level; i++, j++) { +for (j =1 ; j < level; i++, j++) { tl[i] = (struct sched_domain_topology_level ){ .mask = sd_numa_mask, .sd_flags = cpu_numa_flags,Signature · 1 line
2.7.4
Quoted 19 lines · Peter Zijlstra
Quoted 18 lines · Suravee Suthikulpanit
On AMD Family17h-based (EPYC) system, a NUMA node can contain upto 8 cores (16 threads) with the following topology.
---------------------------- C0 | T0 T1 | || | T0 T1 | C4 --------| || |-------- C1 | T0 T1 | L3 || L3 | T0 T1 | C5 --------| || |-------- C2 | T0 T1 | #0 || #1 | T0 T1 | C6 --------| || |-------- C3 | T0 T1 | || | T0 T1 | C7 ----------------------------Here, there are 2 last-level (L3) caches per NUMA node. A socket can contain upto 4 NUMA nodes, and a system can support upto 2 sockets. With full system configuration, current scheduler creates 4 sched domains:
Quoted 5 lines
Quoted 2 lines
domain0 SMT (span a core)
domain1 MC (span a last-level-cache)Right, so traditionally we'd have the DIE level do that, but because
x86_has_numa_in_packagewe don't generate that, right?
That's correct.
Quoted 13 lines
Quoted 13 lines
domain2 NUMA (span a socket: 4 nodes)
domain3 NUMA (span a system: 8 nodes)Note that there is no domain to represent cpus spaning a NUMA node. With this hierachy of sched domains, the scheduler does not balance properly in the following cases:
Case1:
When running 8 tasks, a properly balanced system should schedule a task per NUMA node. This is not the case for the current scheduler.
Quoted 7 lines
Quoted 5 lines
Case2:
When running 'taskset -c 0-7 <a_program_with_8_independent_threads>', a properly balanced system should schedule 8 threads on 8 cpus (e.g. T0 of C0-C7). However, current scheduler would schedule some threads on the same cpu, while others are idle.Sure.. could you amend with a few actual performance numbers?
Sure.
Quoted 20 lines
Quoted 7 lines
[...]
kernel/sched/topology.c +2
-0@@ -1445,9 +1448,24 @@ void sched_init_numa(void) tl[i] = sched_domain_topology[i];/* +* Ignore the NUMA identity level if it has the same cpumask +* as previous level. This is the case for: kernel/sched/topology.c void sched_init_numa(void) · line 1462
Quoted 10 lines
kernel/sched/topology.c +10
-0+* - System with last-level-cache (MC) sched domain span a NUMA node. +* - System with DIE sched domain span a NUMA node. +* +* Assume all NUMA nodes are identical, so only check node 0. +*/ +if (!cpumask_equal (sched_domains_numa_masks[0 ][0 ], tl[i-1 ].mask (0 ))) + tl[i++] = (struct sched_domain_topology_level ){ + .mask = sd_numa_mask, + .numa_level =0 , +SD_INIT_NAME (NUMA_IDEN )Shall we make that:
Quoted 3 lines
SD_INIT_NAME(NODE),instead?
Sounds good.
Quoted 8 lines
kernel/sched/topology.c void sched_init_numa(void) · line 1463
Quoted 1 line
kernel/sched/topology.c +1
-0+ };This misses a set of '{}'. While C doesn't require it, out coding style warrants blocks around any multi-line statement.
So what you've forgotten to mention is that for those systems where the LLC == NODE this now superfluous level gets removed by the degenerate code. Have you verified that does the right thing?
Let me check with that one and get back.
Thanks,
Suravee
Quoted 24 lines · Suravee Suthikulpanit
Quoted 15 lines
Quoted 15 lines
[...]
kernel/sched/topology.c +9
-0@@ -1445,9 +1448,24 @@ void sched_init_numa(void) tl[i] = sched_domain_topology[i];/* +* Ignore the NUMA identity level if it has the same cpumask +* as previous level. This is the case for: +* - System with last-level-cache (MC) sched domain span a NUMA node. +* - System with DIE sched domain span a NUMA node. +* +* Assume all NUMA nodes are identical, so only check node 0. +*/ +if (!cpumask_equal (sched_domains_numa_masks[0 ][0 ], tl[i-1 ].mask (0 ))) + tl[i++] = (struct sched_domain_topology_level ){Quoted 8 lines
kernel/sched/topology.c void sched_init_numa(void) · line 1463
Quoted 4 lines
kernel/sched/topology.c +4
-0+ .mask = sd_numa_mask, + .numa_level = 0, + SD_INIT_NAME(NODE) + };So what you've forgotten to mention is that for those systems where the LLC == NODE this now superfluous level gets removed by the degenerate code. Have you verified that does the right thing?
Quoted 1 line
Let me check with that one and get back.
Actually, it is not removed by the degenerate code. That is what this logic is for. It checks for LCC == NODE or DIE == NODE before setting up the NODE sched level. I can update the comment. This has also been tested on system w/ LLC == NODE.
Thanks,
Suravee
Peter Zijlstra
maintainerQuoted 27 lines · Suravee Suthikulpanit
Quoted 24 lines · Suravee Suthikulpanit
Quoted 23 lines
Quoted 9 lines
[...]
kernel/sched/topology.c +3
-0@@ -1445,9 +1448,24 @@ void sched_init_numa(void) tl[i] = sched_domain_topology[i];/* +* Ignore the NUMA identity level if it has the same cpumask +* as previous level. This is the case for: +* - System with last-level-cache (MC) sched domain span a NUMA node. kernel/sched/topology.c void sched_init_numa(void) · line 1463
Quoted 10 lines
kernel/sched/topology.c +10
-0+* - System with DIE sched domain span a NUMA node. +* +* Assume all NUMA nodes are identical, so only check node 0. +*/ +if (!cpumask_equal (sched_domains_numa_masks[0 ][0 ], tl[i-1 ].mask (0 ))) + tl[i++] = (struct sched_domain_topology_level ){ + .mask = sd_numa_mask, + .numa_level =0 , +SD_INIT_NAME (NODE ) + };So what you've forgotten to mention is that for those systems where the LLC == NODE this now superfluous level gets removed by the degenerate code. Have you verified that does the right thing?
Quoted 6 lines
Quoted 1 line
Let me check with that one and get back.
Actually, it is not removed by the degenerate code. That is what this logic is for. It checks for LCC == NODE or DIE == NODE before setting up the NODE sched level. I can update the comment. This has also been tested on system w/ LLC == NODE.
Why does the degenerate code fail to remove things?
Quoted 28 lines · Peter Zijlstra
Quoted 27 lines · Suravee Suthikulpanit
Quoted 24 lines · Suravee Suthikulpanit
Quoted 23 lines
Quoted 9 lines
[...]
kernel/sched/topology.c +3
-0@@ -1445,9 +1448,24 @@ void sched_init_numa(void) tl[i] = sched_domain_topology[i];/* +* Ignore the NUMA identity level if it has the same cpumask +* as previous level. This is the case for: +* - System with last-level-cache (MC) sched domain span a NUMA node. kernel/sched/topology.c void sched_init_numa(void) · line 1463
Quoted 10 lines
kernel/sched/topology.c +10
-0+* - System with DIE sched domain span a NUMA node. +* +* Assume all NUMA nodes are identical, so only check node 0. +*/ +if (!cpumask_equal (sched_domains_numa_masks[0 ][0 ], tl[i-1 ].mask (0 ))) + tl[i++] = (struct sched_domain_topology_level ){ + .mask = sd_numa_mask, + .numa_level =0 , +SD_INIT_NAME (NODE ) + };So what you've forgotten to mention is that for those systems where the LLC == NODE this now superfluous level gets removed by the degenerate code. Have you verified that does the right thing?
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
Let me check with that one and get back.
Actually, it is not removed by the degenerate code. That is what this logic is for. It checks for LCC == NODE or DIE == NODE before setting up the NODE sched level. I can update the comment. This has also been tested on system w/ LLC == NODE.
Why does the degenerate code fail to remove things?
Sorry for confusion. Actually, the degenerate code does remove the duplicate NODE sched-domain.
The logic above is taking a different approach. Instead of depending on the degenerate code during cpu_attach_domain() at a later time, it would exclude the NODE sched-domain during sched_init_numa(). The difference is, without !cpumask_equal(), now the MC sched-domain would have the SD_PREFER_SIBLING flag set by the degenerate code since the flag got transferred down from the NODE to MC sched-domain. Would this be the preferred behavior for MC sched-domain?
Regards,
Suravee
Hi Peter,
Quoted 51 lines · Suravee Suthikulpanit
Quoted 28 lines · Peter Zijlstra
Quoted 27 lines · Suravee Suthikulpanit
Quoted 24 lines · Suravee Suthikulpanit
Quoted 23 lines
Quoted 9 lines
[...]
kernel/sched/topology.c +3
-0@@ -1445,9 +1448,24 @@ void sched_init_numa(void) tl[i] = sched_domain_topology[i];/* +* Ignore the NUMA identity level if it has the same cpumask +* as previous level. This is the case for: +* - System with last-level-cache (MC) sched domain span a NUMA node. kernel/sched/topology.c void sched_init_numa(void) · line 1463
Quoted 10 lines
kernel/sched/topology.c +10
-0+* - System with DIE sched domain span a NUMA node. +* +* Assume all NUMA nodes are identical, so only check node 0. +*/ +if (!cpumask_equal (sched_domains_numa_masks[0 ][0 ], tl[i-1 ].mask (0 ))) + tl[i++] = (struct sched_domain_topology_level ){ + .mask = sd_numa_mask, + .numa_level =0 , +SD_INIT_NAME (NODE ) + };So what you've forgotten to mention is that for those systems where the LLC == NODE this now superfluous level gets removed by the degenerate code. Have you verified that does the right thing?
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
Let me check with that one and get back.
Actually, it is not removed by the degenerate code. That is what this logic is for. It checks for LCC == NODE or DIE == NODE before setting up the NODE sched level. I can update the comment. This has also been tested on system w/ LLC == NODE.
Why does the degenerate code fail to remove things?
Sorry for confusion. Actually, the degenerate code does remove the duplicate NODE sched-domain.
The logic above is taking a different approach. Instead of depending on the degenerate code during
cpu_attach_domain()at a later time, it would exclude the NODE sched-domain duringsched_init_numa(). The difference is, without !cpumask_equal(), now the MC sched-domain would have theSD_PREFER_SIBLINGflag set by the degenerate code since the flag got transferred down from the NODE to MC sched-domain. Would this be the preferred behavior for MC sched-domain?
Quoted 2 lines
Regards,
Suravee
Any feedback on this part?
Thanks,
Suravee
Peter Zijlstra
maintainerSorry, lost track of this thing..
Quoted 10 lines · Suravee Suthikulpanit
Quoted 2 lines
Why does the degenerate code fail to remove things?
Sorry for confusion. Actually, the degenerate code does remove the duplicate NODE sched-domain.
The difference is, without !cpumask_equal(), now the MC sched-domain would have the
SD_PREFER_SIBLINGflag set by the degenerate code since the flag got transferred down from the NODE to MC sched-domain. Would this be the preferred behavior for MC sched-domain?
Right, but the 'normal' x86_topology setup will have SD_PREFER_SIBLING set on the MC domain by virtue of merging the MC and CPU domains. So the first layer of NUMA spreads.
Now, that appears not be the case for x86_numa_in_package_topology, since that doesn't do the CPU domain, but your patch would effectively 'fix' that if it were to not have that conditional. But it would keep the PREFER_SIBLING at the NODE level, MC would not get it.
But I'm wondering if we're not doing this all a bit backwards. Having SD_PREFER_SIBLING on the L3 makes sense in that it will spread workload across the machine and maximize cache utilization. But we don't set it directly, instead we inherit it through merging.
So commit 8e7fbcbc22c1 ("sched: Remove stale power aware scheduling remnants and dysfunctional knobs") made a fail by not preserving the SD_PREFER_SIBLING for the !power_saving case on both CPU and MC.
Then commit 6956dc568f34 ("sched/numa: Add SD_PERFER_SIBLING to CPU domain") adds it back to the CPU but not MC.
So I'm thinking it makes sense restore the explicit MC one and make your NODE domain unconditional.
That would make behaviour consistent between the various modes; something like the below. I'll go try and update your Changelog so we can get this merged.
kernel/sched/topology.c +16 -3
@@ -1157,6 +1157,7 @@ sd_init(struct sched_domain_topology_lev sd->smt_gain =1178 ;/* ~15% */ }else if (sd->flags &SD_SHARE_PKG_RESOURCES ) { + sd->flags |=SD_PREFER_SIBLING ; sd->imbalance_pct =117 ; sd->cache_nice_tries =1 ; sd->busy_idx =2 ;
@@ -1331,6 +1332,10 @@ void sched_init_numa(void)if (!sched_domains_numa_distance)return ; +/* Includes NUMA identity node at level 0. */ + sched_domains_numa_distance[level++] = curr_distance; + sched_domains_numa_levels = level; +/* * O(nr_nodes^2) deduplicating selection sort -- in order to find the * unique distances in the node_distance() table.
@@ -1378,8 +1383,7 @@ void sched_init_numa(void)return ;/* -* 'level' contains the number of unique distances, excluding the -* identity distance node_distance(i,i). +* 'level' contains the number of unique distances * * The sched_domains_numa_distance[] array includes the actual distance * numbers.
@@ -1441,9 +1445,18 @@ void sched_init_numa(void) tl[i] = sched_domain_topology[i];/* +* Add the NUMA identity distance, aka single NODE. +*/ + tl[i++] = (struct sched_domain_topology_level ){ + .mask = sd_numa_mask, + .numa_level =0 , +SD_INIT_NAME (NODE ) + }; + +/* * .. and append 'j' levels of NUMA goodness. */ -for (j =0 ; j < level; i++, j++) { +for (j =1 ; j < level; i++, j++) { tl[i] = (struct sched_domain_topology_level ){ .mask = sd_numa_mask, .sd_flags = cpu_numa_flags,