summaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2024-02-09 01:11:56 +0100
committerTejun Heo <tj@kernel.org>2024-02-09 22:13:59 +0100
commit8f172181f24bb5df7675225d9b5b66d059613f50 (patch)
tree1d3d37638d3aa6f2193e68017b69b10f65e55b2f /kernel/workqueue.c
parentworkqueue: Fix kernel-doc comment of unplug_oldest_pwq() (diff)
downloadlinux-8f172181f24bb5df7675225d9b5b66d059613f50.tar.xz
linux-8f172181f24bb5df7675225d9b5b66d059613f50.zip
workqueue: Implement workqueue_set_min_active()
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>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index ddcdeb7b9f26..4950bfc2cdcc 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5630,6 +5630,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
*
* Determine if %current task is a workqueue worker and what it's working on.