All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Galbraith <umgwanakikbuti@gmail.com>
To: Tejun Heo <tj@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michal Hocko <mhocko@kernel.org>, Jiri Slaby <jslaby@suse.cz>,
	Thomas Gleixner <tglx@linutronix.de>,
	Petr Mladek <pmladek@suse.com>, Jan Kara <jack@suse.cz>,
	Ben Hutchings <ben@decadent.org.uk>,
	Sasha Levin <sasha.levin@oracle.com>, Shaohua Li <shli@fb.com>,
	LKML <linux-kernel@vger.kernel.org>,
	stable <stable@vger.kernel.org>,
	Daniel Bilik <daniel.bilik@neosystem.cz>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: Crashes with 874bbfe600a6 in 3.18.25
Date: Tue, 09 Feb 2016 18:04:04 +0100	[thread overview]
Message-ID: <1455037444.3604.3.camel@gmail.com> (raw)
In-Reply-To: <20160209165024.GA3741@mtj.duckdns.org>

On Tue, 2016-02-09 at 11:50 -0500, Tejun Heo wrote:
> Hello,
> 
> On Tue, Feb 09, 2016 at 08:39:15AM -0800, Linus Torvalds wrote:
> > > A niggling question remaining is when is it gonna be killed?
> > 
> > It probably should be killed sooner rather than later.
> > 
> > Just document that if you need something to run on a _particular_
> > cpu,
> > you need to use "schedule_delayed_work_on()" and "add_timer_on()".
> 
> I'll queue a patch to put unbound work items on foreign cpus (maybe
> every Nth to reduce perf impact).  Wanted to align it to rc1 and then
> let it get tested during the devel cycle but missed this window.  It's
> a bit late in devel cycle but we can still do it in this cycle.

Or do something like the below, and get guinea pigs for free. 

workqueue: schedule WORK_CPU_UNBOUND work on wq_unbound_cpumask CPUs

WORK_CPU_UNBOUND work items queued to a bound workqueue always run
locally.  This is a good thing normally, but not when the user has
asked us to keep unbound work away from certain CPUs.  Round robin
these to wq_unbound_cpumask CPUs instead, as perturbation avoidance
trumps performance.

Signed-off-by: Mike Galbraith <umgwanakikbuti@gmail.com>
---
 kernel/workqueue.c |   27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -303,6 +303,9 @@ static bool workqueue_freezing;		/* PL:
 
 static cpumask_var_t wq_unbound_cpumask; /* PL: low level cpumask for all unbound wqs */
 
+/* CPU where WORK_CPU_UNBOUND work was last round robin scheduled from this CPU */
+static DEFINE_PER_CPU(unsigned int, wq_unbound_rr_cpu_last);
+
 /* the per-cpu worker pools */
 static DEFINE_PER_CPU_SHARED_ALIGNED(struct worker_pool [NR_STD_WORKER_POOLS],
 				     cpu_worker_pools);
@@ -1298,6 +1301,28 @@ static bool is_chained_work(struct workq
 	return worker && worker->current_pwq->wq == wq;
 }
 
+/*
+ * When queueing WORK_CPU_UNBOUND work to a !WQ_UNBOUND queue, round
+ * robin among wq_unbound_cpumask to avoid perturbing sensitive tasks.
+ */
+static unsigned int select_round_robin_cpu(unsigned int cpu)
+{
+	int new_cpu;
+
+	if (cpumask_test_cpu(cpu, wq_unbound_cpumask))
+		return cpu;
+	if (cpumask_empty(wq_unbound_cpumask))
+		return cpu;
+	new_cpu = __this_cpu_read(wq_unbound_rr_cpu_last);
+	new_cpu = cpumask_next_and(new_cpu, wq_unbound_cpumask, cpu_online_mask);
+	if (unlikely(new_cpu >= nr_cpu_ids))
+		new_cpu = cpumask_first_and(wq_unbound_cpumask, cpu_online_mask);
+	if (unlikely(WARN_ON_ONCE(new_cpu >= nr_cpu_ids)))
+		return cpu;
+	__this_cpu_write(wq_unbound_rr_cpu_last, new_cpu);
+	return new_cpu;
+}
+
 static void __queue_work(int cpu, struct workqueue_struct *wq,
 			 struct work_struct *work)
 {
@@ -1323,7 +1348,7 @@ static void __queue_work(int cpu, struct
 		return;
 retry:
 	if (req_cpu == WORK_CPU_UNBOUND)
-		cpu = raw_smp_processor_id();
+		cpu = select_round_robin_cpu(raw_smp_processor_id());
 
 	/* pwq which will be used unless @work is executing elsewhere */
 	if (!(wq->flags & WQ_UNBOUND))

  reply	other threads:[~2016-02-09 17:04 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-20 21:19 Crashes with 874bbfe600a6 in 3.18.25 Jan Kara
2016-01-20 21:39 ` Shaohua Li
2016-01-21  9:52   ` Jan Kara
2016-01-21 13:29     ` Sasha Levin
2016-01-22  1:10     ` Sasha Levin
2016-01-22 16:09       ` Tejun Heo
2016-01-23  2:20         ` Ben Hutchings
2016-01-23 16:11           ` Thomas Gleixner
2016-01-26  9:34             ` Jan Kara
2016-01-26  9:34               ` Jan Kara
2016-01-26  9:49               ` Thomas Gleixner
2016-01-26  9:49                 ` Thomas Gleixner
2016-01-26 11:14               ` Petr Mladek
2016-01-26 11:14                 ` Petr Mladek
2016-01-26 13:09                 ` Thomas Gleixner
2016-01-26 13:09                   ` Thomas Gleixner
2016-02-03  9:35                   ` Jiri Slaby
2016-02-03 10:41                     ` Thomas Gleixner
2016-02-03 12:28                     ` Michal Hocko
2016-02-03 16:24                       ` Tejun Heo
2016-02-03 16:48                         ` Michal Hocko
2016-02-03 16:59                           ` Tejun Heo
2016-02-04  6:37                             ` Michal Hocko
2016-02-04  7:40                               ` Michal Hocko
2016-02-03 17:01                         ` Mike Galbraith
2016-02-03 17:06                           ` Tejun Heo
2016-02-03 17:13                             ` Mike Galbraith
2016-02-03 17:15                               ` Tejun Heo
2016-02-04  2:00                             ` Mike Galbraith
2016-02-05 16:49                               ` Tejun Heo
2016-02-05 20:47                                 ` Mike Galbraith
2016-02-05 20:54                                   ` Tejun Heo
2016-02-05 20:59                                     ` Mike Galbraith
2016-02-05 21:06                                       ` Tejun Heo
2016-02-06 13:07                                         ` Henrique de Moraes Holschuh
2016-02-07  5:19                                           ` Mike Galbraith
2016-02-07  5:59                                             ` Mike Galbraith
2016-02-09 15:31                                         ` Mike Galbraith
2016-02-09 16:39                                           ` Linus Torvalds
2016-02-09 16:50                                             ` Tejun Heo
2016-02-09 17:04                                               ` Mike Galbraith [this message]
2016-02-09 17:54                                                 ` Tejun Heo
2016-02-09 17:56                                                   ` Mike Galbraith
2016-02-09 18:02                                                     ` Mike Galbraith
2016-02-09 18:27                                                       ` Tejun Heo
2016-02-09 17:04                                               ` Linus Torvalds
2016-02-09 17:51                                                 ` Tejun Heo
2016-02-09 18:06                                                   ` Linus Torvalds
2016-02-04 10:04                             ` Mike Galbraith
2016-02-04 10:46                               ` Thomas Gleixner
2016-02-04 11:07                                 ` Mike Galbraith
2016-02-04 11:20                                 ` Jan Kara
2016-02-04 16:39                                   ` Daniel Bilik
2016-02-05  2:40                                     ` Mike Galbraith
2016-02-05  8:11                                       ` Daniel Bilik
2016-02-05  8:33                                         ` Mike Galbraith
2016-02-03 18:46                         ` Thomas Gleixner
2016-02-03 19:01                           ` Tejun Heo
2016-02-03 19:05                             ` Thomas Gleixner
2016-02-03 19:15                               ` Tejun Heo
2016-02-05  5:44                         ` Mike Galbraith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455037444.3604.3.camel@gmail.com \
    --to=umgwanakikbuti@gmail.com \
    --cc=ben@decadent.org.uk \
    --cc=daniel.bilik@neosystem.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@kernel.org \
    --cc=pmladek@suse.com \
    --cc=sasha.levin@oracle.com \
    --cc=shli@fb.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.