From: Oleg Nesterov <oleg@tv-sign.ru>
To: Gautham R Shenoy <ego@in.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Srivatsa Vaddagiri <vatsa@in.ibm.com>,
Rusty Russel <rusty@rustcorp.com.au>,
Dipankar Sarma <dipankar@in.ibm.com>, Ingo Molnar <mingo@elte.hu>,
Paul E McKenney <paulmck@us.ibm.com>
Subject: Re: [RFC PATCH 4/4] Remove CPU_DEAD/CPU_UP_CANCELLED handling from workqueue.c
Date: Wed, 17 Oct 2007 15:57:23 +0400 [thread overview]
Message-ID: <20071017115723.GA143@tv-sign.ru> (raw)
In-Reply-To: <20071016103721.GD16570@in.ibm.com>
On 10/16, Gautham R Shenoy wrote:
>
> cleanup_workqueue_thread() in the CPU_DEAD and CPU_UP_CANCELLED path
> will cause a deadlock if the worker thread is executing a work item
> which is blocked on get_online_cpus(). This will lead to a irrecoverable
> hang.
>
> Solution is not to cleanup the worker thread. Instead let it remain
> even after the cpu goes offline. Since no one can queue any work
> on an offlined cpu, this thread will be forever sleeping, untill
> someone onlines the cpu.
Imho: not perfect, but acceptable. We can re-introduce cwq->should_stop
flag, so that cwq->thread eventually exits after it flushed ->worklist.
But see below.
> @@ -679,6 +680,7 @@ init_cpu_workqueue(struct workqueue_stru
> spin_lock_init(&cwq->lock);
> INIT_LIST_HEAD(&cwq->worklist);
> init_waitqueue_head(&cwq->more_work);
> + cwq->thread = NULL;
Not needed, cwq->thread == NULL because alloc_percpu() uses GFP_ZERO.
> return cwq;
> }
> @@ -712,7 +714,7 @@ static void start_workqueue_thread(struc
>
> if (p != NULL) {
> if (cpu >= 0)
> - kthread_bind(p, cpu);
> + set_cpus_allowed(p, cpumask_of_cpu(cpu));
OK, this is understandable, but see below...
> wake_up_process(p);
> }
> }
> @@ -848,6 +850,9 @@ static int __devinit workqueue_cpu_callb
>
> switch (action) {
> case CPU_UP_PREPARE:
> + if (likely(cwq->thread != NULL &&
> + !IS_ERR(cwq->thread)))
IS_ERR(cwq->thread) is not possible. cwq->thread is either NULL, or
a valid task_struct.
> + break;
> if (!create_workqueue_thread(cwq, cpu))
> break;
> printk(KERN_ERR "workqueue [%s] for %i failed\n",
> @@ -858,12 +863,6 @@ static int __devinit workqueue_cpu_callb
> case CPU_ONLINE:
> start_workqueue_thread(cwq, cpu);
> break;
> -
> - case CPU_UP_CANCELED:
> - start_workqueue_thread(cwq, -1);
> - case CPU_DEAD:
> - cleanup_workqueue_thread(cwq, cpu);
> - break;
> }
> }
Unfortunately, this approach seem to have a sublte problem.
Suppose that CPU 0 goes down. Let's denote the corresponding cwq->thread as T.
When CPU goes offline, T is not bound to CPU 0 any longer. So far this is OK.
Now suppose that CPU 0 goes online again. There is a window before CPU_ONLINE
(note that CPU 0 is already online at this time) binds T back to CPU 0. It is
possible that another thread running on CPU 0 does schedule_work() in that window,
or it can run on any CPU but calls schedule_delayed_work_on(0).
In this case the work_struct may run on the wrong CPU because T is ready to
execute the work_struct, this is bug. work->func() has all rights to expect
that cwq->thread is bound to the right CPU.
Let's take cache_reap() as an example. It is critical that this function is
really "per cpu", otherwise it can use the wrong per-cpu data, and even the
last schedule_delayed_work() is not reliable.
(Sorry, have no time to read the other patches now, will do on weekend).
Oleg.
next prev parent reply other threads:[~2007-10-17 11:52 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-16 10:33 [RFC PATCH 0/4] Refcount Based Cpu-Hotplug Revisit Gautham R Shenoy
2007-10-16 10:34 ` [RFC PATCH 1/4] Refcount Based Cpu-Hotplug Implementation Gautham R Shenoy
2007-10-17 0:47 ` Rusty Russell
2007-10-17 5:37 ` Gautham R Shenoy
2007-10-17 6:29 ` Rusty Russell
2007-10-18 6:29 ` Gautham R Shenoy
2007-10-21 12:47 ` Oleg Nesterov
2007-10-17 10:53 ` Paul Jackson
2007-10-17 11:27 ` Paul Jackson
2007-10-17 11:50 ` Gautham R Shenoy
2007-10-17 12:04 ` Paul Jackson
2007-10-16 10:35 ` [RFC PATCH 2/4] Rename lock_cpu_hotplug to get_online_cpus Gautham R Shenoy
2007-10-17 16:13 ` Nathan Lynch
2007-10-18 7:57 ` Gautham R Shenoy
2007-10-18 8:22 ` Nathan Lynch
2007-10-18 8:59 ` Gautham R Shenoy
2007-10-18 17:30 ` Nathan Lynch
2007-10-19 5:04 ` Gautham R Shenoy
2007-10-22 0:43 ` Nathan Lynch
2007-10-22 4:51 ` Gautham R Shenoy
2007-10-16 10:36 ` [RFC PATCH 3/4] Replace per-subsystem mutexes with get_online_cpus Gautham R Shenoy
2007-10-21 11:39 ` Oleg Nesterov
2007-10-22 4:58 ` Gautham R Shenoy
2007-10-16 10:37 ` [RFC PATCH 4/4] Remove CPU_DEAD/CPU_UP_CANCELLED handling from workqueue.c Gautham R Shenoy
2007-10-17 11:57 ` Oleg Nesterov [this message]
2007-10-16 17:20 ` [RFC PATCH 0/4] Refcount Based Cpu-Hotplug Revisit Linus Torvalds
2007-10-17 2:11 ` Dipankar Sarma
2007-10-17 2:23 ` Linus Torvalds
2007-10-17 4:17 ` Gautham R Shenoy
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=20071017115723.GA143@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=akpm@linux-foundation.org \
--cc=dipankar@in.ibm.com \
--cc=ego@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulmck@us.ibm.com \
--cc=rusty@rustcorp.com.au \
--cc=torvalds@linux-foundation.org \
--cc=vatsa@in.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®