[RFC PATCH] workqueue: allow rescuer thread to do more work
From: Dongsu Park
Date: Wed Nov 05 2014 - 11:28:07 EST
Original commit message from NeilBrown <neilb@xxxxxxx>:
====
When there is serious memory pressure, all workers in a pool could be
blocked, and a new thread cannot be created because it requires memory
allocation.
In this situation a WQ_MEM_RECLAIM workqueue will wake up the rescuer
thread to do some work.
The rescuer will only handle requests that are already on ->worklist.
If max_requests is 1, that means it will handle a single request.
The rescuer will be woken again in 100ms to handle another max_requests
requests.
I've seen a machine (running a 3.0 based "enterprise" kernel) with
thousands of requests queued for xfslogd, which has a max_requests of 1,
and is needed for retiring all 'xfs' write requests. When one of the
worker pools gets into this state, it progresses extremely slowly and
possibly never recovers (only waited an hour or two).
So if, after handling everything on worklist, there is again something
on worklist (counted in nr_active), and if the queue is still congested,
keep processing instead of waiting for the next wake-up.
====
Dongsu Park: replaced need_more_worker() with need_to_create_worker(),
as suggested by Tejun.
Signed-off-by: Dongsu Park <dongsu.park@xxxxxxxxxxxxxxxx>
Link: https://lkml.org/lkml/2014/10/29/55
Cc: Tejun Heo <tj@xxxxxxxxxx>
Cc: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
Original-by: NeilBrown <neilb@xxxxxxx>
Signed-off-by: NeilBrown <neilb@xxxxxxx>
---
kernel/workqueue.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 09b685d..4d20225 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2244,16 +2244,19 @@ repeat:
spin_lock_irq(&pool->lock);
rescuer->pool = pool;
- /*
- * Slurp in all works issued via this workqueue and
- * process'em.
- */
- WARN_ON_ONCE(!list_empty(&rescuer->scheduled));
- list_for_each_entry_safe(work, n, &pool->worklist, entry)
- if (get_work_pwq(work) == pwq)
- move_linked_works(work, scheduled, &n);
-
- process_scheduled_works(rescuer);
+ do {
+ /*
+ * Slurp in all works issued via this workqueue and
+ * process'em.
+ */
+ WARN_ON_ONCE(!list_empty(&rescuer->scheduled));
+ list_for_each_entry_safe(work, n, &pool->worklist,
+ entry)
+ if (get_work_pwq(work) == pwq)
+ move_linked_works(work, scheduled, &n);
+
+ process_scheduled_works(rescuer);
+ } while (need_to_create_worker(pool) && pwq->nr_active);
/*
* Put the reference grabbed by send_mayday(). @pool won't
--
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/