Commit 3324b21
sched/fair: Skip sched_balance_running cmpxchg when balance is not due
The NUMA sched domain sets the SD_SERIALIZE flag by default, allowing
only one NUMA load balancing operation to run system-wide at a time.
Currently, each sched group leader directly under NUMA domain attempts
to acquire the global sched_balance_running flag via cmpxchg() before
checking whether load balancing is due or whether it is the designated
load balancer for that NUMA domain. On systems with a large number
of cores, this causes significant cache contention on the shared
sched_balance_running flag.
This patch reduces unnecessary cmpxchg() operations by first checking
that the balancer is the designated leader for a NUMA domain from
should_we_balance(), and the balance interval has expired before
trying to acquire sched_balance_running to load balance a NUMA
domain.
On a 2-socket Granite Rapids system with sub-NUMA clustering enabled,
running an OLTP workload, 7.8% of total CPU cycles were previously spent
in sched_balance_domain() contending on sched_balance_running before
this change.
: 104 static __always_inline int arch_atomic_cmpxchg(atomic_t *v, int old, int new)
: 105 {
: 106 return arch_cmpxchg(&v->counter, old, new);
0.00 : ffffffff81326e6c: xor %eax,%eax
0.00 : ffffffff81326e6e: mov $0x1,%ecx
0.00 : ffffffff81326e73: lock cmpxchg %ecx,0x2394195(%rip) # ffffffff836bb010 <sched_balance_running>
: 110 sched_balance_domains():
: 12234 if (atomic_cmpxchg_acquire(&sched_balance_running, 0, 1))
99.39 : ffffffff81326e7b: test %eax,%eax
0.00 : ffffffff81326e7d: jne ffffffff81326e99 <sched_balance_domains+0x209>
: 12238 if (time_after_eq(jiffies, sd->last_balance + interval)) {
0.00 : ffffffff81326e7f: mov 0x14e2b3a(%rip),%rax # ffffffff828099c0 <jiffies_64>
0.00 : ffffffff81326e86: sub 0x48(%r14),%rax
0.00 : ffffffff81326e8a: cmp %rdx,%rax
After applying this fix, sched_balance_domain() is gone from the profile
and there is a 5% throughput improvement.
[peterz: made it so that redo retains the 'lock' and split out the
CPU_NEWLY_IDLE change to a separate patch]
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Chen Yu <yu.c.chen@intel.com>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Reviewed-by: Srikar Dronamraju <srikar@linux.ibm.com>
Tested-by: Mohini Narkhede <mohini.narkhede@intel.com>
Tested-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Link: https://patch.msgid.link/6fed119b723c71552943bfe5798c93851b30a361.1762800251.git.tim.c.chen@linux.intel.com1 parent 65177ea commit 3324b21
1 file changed
Lines changed: 28 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11680 | 11680 | | |
11681 | 11681 | | |
11682 | 11682 | | |
| 11683 | + | |
| 11684 | + | |
| 11685 | + | |
| 11686 | + | |
| 11687 | + | |
| 11688 | + | |
| 11689 | + | |
| 11690 | + | |
| 11691 | + | |
| 11692 | + | |
| 11693 | + | |
| 11694 | + | |
| 11695 | + | |
| 11696 | + | |
| 11697 | + | |
11683 | 11698 | | |
11684 | 11699 | | |
11685 | 11700 | | |
| |||
11705 | 11720 | | |
11706 | 11721 | | |
11707 | 11722 | | |
| 11723 | + | |
11708 | 11724 | | |
11709 | 11725 | | |
11710 | 11726 | | |
| |||
11716 | 11732 | | |
11717 | 11733 | | |
11718 | 11734 | | |
| 11735 | + | |
| 11736 | + | |
| 11737 | + | |
| 11738 | + | |
| 11739 | + | |
| 11740 | + | |
| 11741 | + | |
| 11742 | + | |
11719 | 11743 | | |
11720 | 11744 | | |
11721 | 11745 | | |
| |||
11956 | 11980 | | |
11957 | 11981 | | |
11958 | 11982 | | |
| 11983 | + | |
| 11984 | + | |
| 11985 | + | |
11959 | 11986 | | |
11960 | 11987 | | |
11961 | 11988 | | |
| |||
12080 | 12107 | | |
12081 | 12108 | | |
12082 | 12109 | | |
12083 | | - | |
12084 | | - | |
12085 | | - | |
12086 | | - | |
12087 | | - | |
12088 | | - | |
12089 | | - | |
12090 | | - | |
12091 | | - | |
12092 | | - | |
12093 | | - | |
12094 | | - | |
12095 | | - | |
12096 | | - | |
12097 | | - | |
12098 | 12110 | | |
12099 | 12111 | | |
12100 | 12112 | | |
| |||
12150 | 12162 | | |
12151 | 12163 | | |
12152 | 12164 | | |
12153 | | - | |
| 12165 | + | |
12154 | 12166 | | |
12155 | 12167 | | |
12156 | 12168 | | |
| |||
12174 | 12186 | | |
12175 | 12187 | | |
12176 | 12188 | | |
12177 | | - | |
12178 | | - | |
12179 | | - | |
12180 | | - | |
12181 | | - | |
12182 | | - | |
12183 | | - | |
12184 | 12189 | | |
12185 | 12190 | | |
12186 | 12191 | | |
| |||
12194 | 12199 | | |
12195 | 12200 | | |
12196 | 12201 | | |
12197 | | - | |
12198 | | - | |
12199 | | - | |
12200 | 12202 | | |
12201 | 12203 | | |
12202 | 12204 | | |
| |||
0 commit comments