Skip to content

Commit 5de7a03

Browse files
committed
workqueue: Factor out clearing of workqueue-only attrs fields
workqueue_attrs can be used for both workqueues and worker_pools. However, some fields, currently only ->ordered, only apply to workqueues and should be cleared to the default / invalid values. Currently, an unbound workqueue explicitly clears attrs->ordered in get_unbound_pool() after copying the source workqueue attrs, while per-cpu workqueues rely on the fact that zeroing on allocation gives us the desired default value for pool->attrs->ordered. This is fragile. Let's add wqattrs_clear_for_pool() which clears attrs->ordered and is called from both init_worker_pool() and get_unbound_pool(). This will ease adding more workqueue-only attrs fields. In get_unbound_pool(), pool->node initialization is moved upwards for readability. This shouldn't cause any behavior changes. Signed-off-by: Tejun Heo <[email protected]>
1 parent 0f36ee2 commit 5de7a03

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

kernel/workqueue.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3678,6 +3678,15 @@ static void copy_workqueue_attrs(struct workqueue_attrs *to,
36783678
to->ordered = from->ordered;
36793679
}
36803680

3681+
/*
3682+
* Some attrs fields are workqueue-only. Clear them for worker_pool's. See the
3683+
* comments in 'struct workqueue_attrs' definition.
3684+
*/
3685+
static void wqattrs_clear_for_pool(struct workqueue_attrs *attrs)
3686+
{
3687+
attrs->ordered = false;
3688+
}
3689+
36813690
/* hash value of the content of @attr */
36823691
static u32 wqattrs_hash(const struct workqueue_attrs *attrs)
36833692
{
@@ -3752,6 +3761,9 @@ static int init_worker_pool(struct worker_pool *pool)
37523761
pool->attrs = alloc_workqueue_attrs();
37533762
if (!pool->attrs)
37543763
return -ENOMEM;
3764+
3765+
wqattrs_clear_for_pool(pool->attrs);
3766+
37553767
return 0;
37563768
}
37573769

@@ -3942,14 +3954,10 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs)
39423954
if (!pool || init_worker_pool(pool) < 0)
39433955
goto fail;
39443956

3945-
copy_workqueue_attrs(pool->attrs, attrs);
39463957
pool->node = target_pod;
39473958

3948-
/*
3949-
* ordered isn't a worker_pool attribute, always clear it. See
3950-
* 'struct workqueue_attrs' comments for detail.
3951-
*/
3952-
pool->attrs->ordered = false;
3959+
copy_workqueue_attrs(pool->attrs, attrs);
3960+
wqattrs_clear_for_pool(pool->attrs);
39533961

39543962
if (worker_pool_assign_id(pool) < 0)
39553963
goto fail;

0 commit comments

Comments
 (0)