diff options
author | Tejun Heo <tj@kernel.org> | 2011-01-09 17:32:15 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2011-01-11 09:33:01 -0500 |
commit | e159489baa717dbae70f9903770a6a4990865887 (patch) | |
tree | 6e2ae803ff6ebed558ebbe03bf3ae5bda1dd6ebc /kernel | |
parent | 0c21e3aaf6ae85bee804a325aa29c325209180fd (diff) |
workqueue: relax lockdep annotation on flush_work()
Currently, the lockdep annotation in flush_work() requires exclusive
access on the workqueue the target work is queued on and triggers
warning if a work is trying to flush another work on the same
workqueue; however, this is no longer true as workqueues can now
execute multiple works concurrently.
This patch adds lock_map_acquire_read() and make process_one_work()
hold read access to the workqueue while executing a work and
start_flush_work() check for write access if concurrnecy level is one
or the workqueue has a rescuer (as only one execution resource - the
rescuer - is guaranteed to be available under memory pressure), and
read access if higher.
This better represents what's going on and removes spurious lockdep
warnings which are triggered by fake dependency chain created through
flush_work().
* Peter pointed out that flushing another work from a WQ_MEM_RECLAIM
wq breaks forward progress guarantee under memory pressure.
Condition check accordingly updated.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: "Rafael J. Wysocki" <rjw@sisk.pl>
Tested-by: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: stable@kernel.org
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/workqueue.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 8ee6ec82f88a..930c2390b77e 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -1840,7 +1840,7 @@ __acquires(&gcwq->lock) | |||
1840 | spin_unlock_irq(&gcwq->lock); | 1840 | spin_unlock_irq(&gcwq->lock); |
1841 | 1841 | ||
1842 | work_clear_pending(work); | 1842 | work_clear_pending(work); |
1843 | lock_map_acquire(&cwq->wq->lockdep_map); | 1843 | lock_map_acquire_read(&cwq->wq->lockdep_map); |
1844 | lock_map_acquire(&lockdep_map); | 1844 | lock_map_acquire(&lockdep_map); |
1845 | trace_workqueue_execute_start(work); | 1845 | trace_workqueue_execute_start(work); |
1846 | f(work); | 1846 | f(work); |
@@ -2384,8 +2384,18 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr, | |||
2384 | insert_wq_barrier(cwq, barr, work, worker); | 2384 | insert_wq_barrier(cwq, barr, work, worker); |
2385 | spin_unlock_irq(&gcwq->lock); | 2385 | spin_unlock_irq(&gcwq->lock); |
2386 | 2386 | ||
2387 | lock_map_acquire(&cwq->wq->lockdep_map); | 2387 | /* |
2388 | * If @max_active is 1 or rescuer is in use, flushing another work | ||
2389 | * item on the same workqueue may lead to deadlock. Make sure the | ||
2390 | * flusher is not running on the same workqueue by verifying write | ||
2391 | * access. | ||
2392 | */ | ||
2393 | if (cwq->wq->saved_max_active == 1 || cwq->wq->flags & WQ_RESCUER) | ||
2394 | lock_map_acquire(&cwq->wq->lockdep_map); | ||
2395 | else | ||
2396 | lock_map_acquire_read(&cwq->wq->lockdep_map); | ||
2388 | lock_map_release(&cwq->wq->lockdep_map); | 2397 | lock_map_release(&cwq->wq->lockdep_map); |
2398 | |||
2389 | return true; | 2399 | return true; |
2390 | already_gone: | 2400 | already_gone: |
2391 | spin_unlock_irq(&gcwq->lock); | 2401 | spin_unlock_irq(&gcwq->lock); |