Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1283274
| From | Tejun Heo <tj@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue |
| Date | 2015-12-03 20:30 +0100 |
| Message-ID | <qBHJL-QO-1@gated-at.bofh.it> (permalink) |
| References | (1 earlier) <qBywN-38I-5@gated-at.bofh.it> <qByZP-3zg-15@gated-at.bofh.it> <qBDmN-6pd-21@gated-at.bofh.it> <qBDGa-6Nq-19@gated-at.bofh.it> <qBDGa-6Nq-17@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Task or work item involved in memory reclaim trying to flush a
non-WQ_MEM_RECLAIM workqueue or one of its work items can lead to
deadlock. Trigger WARN_ONCE() if such conditions are detected.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
---
Hello,
So, something like this. Seems to work fine here. If there's no
objection, I'm gonna push it through wq/for-4.5.
Thanks.
kernel/workqueue.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2330,6 +2330,37 @@ repeat:
goto repeat;
}
+/**
+ * check_flush_dependency - check for flush dependency sanity
+ * @target_wq: workqueue being flushed
+ * @target_work: work item being flushed (NULL for workqueue flushes)
+ *
+ * %current is trying to flush the whole @target_wq or @target_work on it.
+ * If @target_wq doesn't have %WQ_MEM_RECLAIM, verify that %current is not
+ * reclaiming memory or running on a workqueue which doesn't have
+ * %WQ_MEM_RECLAIM as that can break forward-progress guarantee leading to
+ * a deadlock.
+ */
+static void check_flush_dependency(struct workqueue_struct *target_wq,
+ struct work_struct *target_work)
+{
+ work_func_t target_func = target_work ? target_work->func : NULL;
+ struct worker *worker;
+
+ if (target_wq->flags & WQ_MEM_RECLAIM)
+ return;
+
+ worker = current_wq_worker();
+
+ WARN_ONCE(current->flags & PF_MEMALLOC,
+ "workqueue: PF_MEMALLOC task %d(%s) is flushing !WQ_MEM_RECLAIM %s:%pf",
+ current->pid, current->comm, target_wq->name, target_func);
+ WARN_ONCE(worker && (worker->current_pwq->wq->flags & WQ_MEM_RECLAIM),
+ "workqueue: WQ_MEM_RECLAIM %s:%pf is flushing !WQ_MEM_RECLAIM %s:%pf",
+ worker->current_pwq->wq->name, worker->current_func,
+ target_wq->name, target_func);
+}
+
struct wq_barrier {
struct work_struct work;
struct completion done;
@@ -2539,6 +2570,8 @@ void flush_workqueue(struct workqueue_st
list_add_tail(&this_flusher.list, &wq->flusher_overflow);
}
+ check_flush_dependency(wq, NULL);
+
mutex_unlock(&wq->mutex);
wait_for_completion(&this_flusher.done);
@@ -2711,6 +2744,8 @@ static bool start_flush_work(struct work
pwq = worker->current_pwq;
}
+ check_flush_dependency(pwq->wq, work);
+
insert_wq_barrier(pwq, barr, work, worker);
spin_unlock_irq(&pool->lock);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/2] watchdog: introduce touch_softlockup_watchdog_sched() Tejun Heo <tj@kernel.org> - 2015-12-03 01:30 +0100
[PATCH 2/2] workqueue: implement lockup detector Tejun Heo <tj@kernel.org> - 2015-12-03 01:30 +0100
Re: [PATCH 2/2] workqueue: implement lockup detector Tejun Heo <tj@kernel.org> - 2015-12-03 15:50 +0100
Re: [PATCH 2/2] workqueue: implement lockup detector Don Zickus <dzickus@redhat.com> - 2015-12-03 19:00 +0100
Re: [PATCH 2/2] workqueue: implement lockup detector Tejun Heo <tj@kernel.org> - 2015-12-03 20:50 +0100
Re: [PATCH 2/2] workqueue: implement lockup detector Ulrich Obergfell <uobergfe@redhat.com> - 2015-12-03 21:20 +0100
Re: [PATCH 2/2] workqueue: implement lockup detector Tejun Heo <tj@kernel.org> - 2015-12-03 22:00 +0100
Re: [PATCH 2/2] workqueue: implement lockup detector Ingo Molnar <mingo@kernel.org> - 2015-12-04 09:10 +0100
Re: [PATCH 2/2] workqueue: implement lockup detector Don Zickus <dzickus@redhat.com> - 2015-12-04 18:00 +0100
Re: [PATCH 2/2] workqueue: implement lockup detector Ulrich Obergfell <uobergfe@redhat.com> - 2015-12-04 14:30 +0100
[PATCH v2 2/2] workqueue: implement lockup detector Tejun Heo <tj@kernel.org> - 2015-12-07 20:10 +0100
Re: [PATCH v2 2/2] workqueue: implement lockup detector Tejun Heo <tj@kernel.org> - 2015-12-07 22:40 +0100
Re: [PATCH v2 2/2] workqueue: implement lockup detector Don Zickus <dzickus@redhat.com> - 2015-12-08 17:10 +0100
Re: [PATCH v2 2/2] workqueue: implement lockup detector Tejun Heo <tj@kernel.org> - 2015-12-08 17:40 +0100
Re: [PATCH v2 2/2] workqueue: implement lockup detector Don Zickus <dzickus@redhat.com> - 2015-12-07 22:40 +0100
Re: [PATCH 1/2] watchdog: introduce touch_softlockup_watchdog_sched() Peter Zijlstra <peterz@infradead.org> - 2015-12-03 10:40 +0100
Re: [PATCH 1/2] watchdog: introduce touch_softlockup_watchdog_sched() Peter Zijlstra <peterz@infradead.org> - 2015-12-03 11:10 +0100
Re: [PATCH 1/2] watchdog: introduce touch_softlockup_watchdog_sched() Tejun Heo <tj@kernel.org> - 2015-12-03 15:50 +0100
Re: [PATCH 1/2] watchdog: introduce touch_softlockup_watchdog_sched() Tejun Heo <tj@kernel.org> - 2015-12-03 16:10 +0100
[PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue Tejun Heo <tj@kernel.org> - 2015-12-03 20:30 +0100
Re: [PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue Peter Zijlstra <peterz@infradead.org> - 2015-12-03 21:50 +0100
Re: [PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue Tejun Heo <tj@kernel.org> - 2015-12-03 22:00 +0100
Re: [PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue Peter Zijlstra <peterz@infradead.org> - 2015-12-03 22:10 +0100
Re: [PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue Tejun Heo <tj@kernel.org> - 2015-12-03 23:10 +0100
Re: [PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue Peter Zijlstra <peterz@infradead.org> - 2015-12-04 14:00 +0100
Re: [PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue Tejun Heo <tj@kernel.org> - 2015-12-07 17:00 +0100
Re: [PATCH 1/2] watchdog: introduce touch_softlockup_watchdog_sched() Peter Zijlstra <peterz@infradead.org> - 2015-12-03 16:10 +0100
csiph-web