linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched: Fix nr_uninterruptible race causing increasing load average
@ 2021-07-07 19:04 Phil Auld
  2021-07-08  7:26 ` Peter Zijlstra
  0 siblings, 1 reply; 12+ messages in thread
From: Phil Auld @ 2021-07-07 19:04 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, Waiman Long, Ingo Molnar, Juri Lelli,
	Vincent Guittot, stable, Phil Auld

On systems with weaker memory ordering (e.g. power) commit dbfb089d360b
("sched: Fix loadavg accounting race") causes increasing values of load
average (via rq->calc_load_active and calc_load_tasks) due to the wakeup
CPU not always seeing the write to task->sched_contributes_to_load in
__schedule(). Missing that we fail to decrement nr_uninterruptible when
waking up a task which incremented nr_uninterruptible when it slept.

The rq->lock serialization is insufficient across different rq->locks.

Add smp_wmb() to schedule and smp_rmb() before the read in
ttwu_do_activate().

Fixes: dbfb089d360b ("sched: Fix loadavg accounting race")
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Waiman Long <longman@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Phil Auld <pauld@redhat.com>
---
 kernel/sched/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 4ca80df205ce..ced7074716eb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2992,6 +2992,8 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
 
 	lockdep_assert_held(&rq->lock);
 
+	/* Pairs with smp_wmb in __schedule() */
+	smp_rmb();
 	if (p->sched_contributes_to_load)
 		rq->nr_uninterruptible--;
 
@@ -5084,6 +5086,11 @@ static void __sched notrace __schedule(bool preempt)
 				!(prev_state & TASK_NOLOAD) &&
 				!(prev->flags & PF_FROZEN);
 
+			/*
+			 * Make sure the previous write is ordered before p->on_rq etc so
+			 * that it is visible to other cpus in the wakeup path (ttwu_do_activate()).
+			 */
+			smp_wmb();
 			if (prev->sched_contributes_to_load)
 				rq->nr_uninterruptible++;
 
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-07-28 15:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-07 19:04 [PATCH] sched: Fix nr_uninterruptible race causing increasing load average Phil Auld
2021-07-08  7:26 ` Peter Zijlstra
2021-07-08  7:48   ` Peter Zijlstra
2021-07-08  7:54     ` Peter Zijlstra
2021-07-08 14:54       ` Phil Auld
2021-07-09 12:57         ` Peter Zijlstra
2021-07-11 13:19           ` Phil Auld
2021-07-08 13:25   ` Phil Auld
2021-07-09 11:38     ` Peter Zijlstra
2021-07-11 12:57       ` Phil Auld
2021-07-23 13:38       ` Phil Auld
2021-07-28 15:45         ` Phil Auld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).