Skip to content

Commit 8f17218

Browse files
committed
workqueue: Implement workqueue_set_min_active()
Since 5797b1c ("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>
1 parent 516d3dc commit 8f17218

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/linux/workqueue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ extern bool flush_rcu_work(struct rcu_work *rwork);
553553

554554
extern void workqueue_set_max_active(struct workqueue_struct *wq,
555555
int max_active);
556+
extern void workqueue_set_min_active(struct workqueue_struct *wq,
557+
int min_active);
556558
extern struct work_struct *current_work(void);
557559
extern bool current_is_workqueue_rescuer(void);
558560
extern bool workqueue_congested(int cpu, struct workqueue_struct *wq);

kernel/workqueue.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5629,6 +5629,33 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
56295629
}
56305630
EXPORT_SYMBOL_GPL(workqueue_set_max_active);
56315631

5632+
/**
5633+
* workqueue_set_min_active - adjust min_active of an unbound workqueue
5634+
* @wq: target unbound workqueue
5635+
* @min_active: new min_active value
5636+
*
5637+
* Set min_active of an unbound workqueue. Unlike other types of workqueues, an
5638+
* unbound workqueue is not guaranteed to be able to process max_active
5639+
* interdependent work items. Instead, an unbound workqueue is guaranteed to be
5640+
* able to process min_active number of interdependent work items which is
5641+
* %WQ_DFL_MIN_ACTIVE by default.
5642+
*
5643+
* Use this function to adjust the min_active value between 0 and the current
5644+
* max_active.
5645+
*/
5646+
void workqueue_set_min_active(struct workqueue_struct *wq, int min_active)
5647+
{
5648+
/* min_active is only meaningful for non-ordered unbound workqueues */
5649+
if (WARN_ON((wq->flags & (WQ_BH | WQ_UNBOUND | __WQ_ORDERED)) !=
5650+
WQ_UNBOUND))
5651+
return;
5652+
5653+
mutex_lock(&wq->mutex);
5654+
wq->saved_min_active = clamp(min_active, 0, wq->saved_max_active);
5655+
wq_adjust_max_active(wq);
5656+
mutex_unlock(&wq->mutex);
5657+
}
5658+
56325659
/**
56335660
* current_work - retrieve %current task's work struct
56345661
*

0 commit comments

Comments
 (0)