Skip to contentSkip to conversation

workqueue: Better document teardown for delayed_work

PATCH Applied Philipp Stanner 2 participants 2 messages Apr 4, 2025 Workqueue

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 workqueue: Better document teardown for delayed_work

destroy_workqueue() does not ensure that non-pending work submitted with queue_delayed_work() gets cancelled. The caller has to ensure that manually.

Add this information about delayed_work in destroy_workqueue()'s docstring.

Add a TODO for destroy_workqueue() to wait for all delayed_work.

---
Changes in v2:
- Make it explicit what the problem is and tell the user what to do to work around it. (Tejun)
- Add a TODO for handling delayed_work in the future. (Me)

---
 kernel/workqueue.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
kernel/workqueue.c +11 -0
index bfe030b443e2..a4d23c102f9f 100644
@@ -5837,6 +5837,17 @@ static bool pwq_busy(struct pool_workqueue *pwq)
  * @wq: target workqueue
  *
  * Safely destroy a workqueue. All work currently pending will be done first.
+ *
+ * This function does NOT guarantee that non-pending work that has been
+ * submitted with queue_delayed_work() and similar functions will be done
+ * before destroying the workqueue. The fundamental problem is that, currently,
+ * the workqueue has no way of accessing non-pending delayed_work. delayed_work
+ * is only linked on the timer-side. All delayed_work must, therefore, be
+ * canceled before calling this function.
+ *
+ * TODO: It would be better if the problem described above wouldn't exist and
+ * destroy_workqueue() would cleanly cancel all pending and non-pending
+ * delayed_work.
  */
 void destroy_workqueue(struct workqueue_struct *wq)
 {
Signature · 1 line
2.48.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Philipp Stanner

destroy_workqueue() does not ensure that non-pending work submitted with queue_delayed_work() gets cancelled. The caller has to ensure that manually.

Add this information about delayed_work in destroy_workqueue()'s docstring.

Add a TODO for destroy_workqueue() to wait for all delayed_work.

Applied to wq/for-6.15-fixes.

Thanks.

Signature · 1 line
tejun