]> www.infradead.org Git - linux.git/commitdiff
workqueue: Implement workqueue_set_min_active()
authorTejun Heo <tj@kernel.org>
Fri, 9 Feb 2024 00:11:56 +0000 (14:11 -1000)
committerTejun Heo <tj@kernel.org>
Fri, 9 Feb 2024 21:13:59 +0000 (11:13 -1000)
Since 5797b1c18919 ("workqueue: Implement system-wide nr_active enforcement
for unbound workqueues"), unbound workqueues have separate min_active which
sets the number of interdependent work items that can be handled. This value
is currently initialized to WQ_DFL_MIN_ACTIVE which is 8. This isn't high
enough for some users, let's add an interface to adjust the setting.

Signed-off-by: Tejun Heo <tj@kernel.org>
include/linux/workqueue.h
kernel/workqueue.c

index 4ba33cf07f116544723314ce0dd4bcce7e6f7c4a..1565bab9edc8a83d517cad999c7c388b61b85162 100644 (file)
@@ -553,6 +553,8 @@ extern bool flush_rcu_work(struct rcu_work *rwork);
 
 extern void workqueue_set_max_active(struct workqueue_struct *wq,
                                     int max_active);
+extern void workqueue_set_min_active(struct workqueue_struct *wq,
+                                    int min_active);
 extern struct work_struct *current_work(void);
 extern bool current_is_workqueue_rescuer(void);
 extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);
index ddcdeb7b9f26bb87eb203886777618b711392325..4950bfc2cdcc3ef70c7d5f65a3726c583346c5d7 100644 (file)
@@ -5629,6 +5629,33 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
 }
 EXPORT_SYMBOL_GPL(workqueue_set_max_active);
 
+/**
+ * workqueue_set_min_active - adjust min_active of an unbound workqueue
+ * @wq: target unbound workqueue
+ * @min_active: new min_active value
+ *
+ * Set min_active of an unbound workqueue. Unlike other types of workqueues, an
+ * unbound workqueue is not guaranteed to be able to process max_active
+ * interdependent work items. Instead, an unbound workqueue is guaranteed to be
+ * able to process min_active number of interdependent work items which is
+ * %WQ_DFL_MIN_ACTIVE by default.
+ *
+ * Use this function to adjust the min_active value between 0 and the current
+ * max_active.
+ */
+void workqueue_set_min_active(struct workqueue_struct *wq, int min_active)
+{
+       /* min_active is only meaningful for non-ordered unbound workqueues */
+       if (WARN_ON((wq->flags & (WQ_BH | WQ_UNBOUND | __WQ_ORDERED)) !=
+                   WQ_UNBOUND))
+               return;
+
+       mutex_lock(&wq->mutex);
+       wq->saved_min_active = clamp(min_active, 0, wq->saved_max_active);
+       wq_adjust_max_active(wq);
+       mutex_unlock(&wq->mutex);
+}
+
 /**
  * current_work - retrieve %current task's work struct
  *