Skip to content

Commit 69635d7

Browse files
DispatchCodebrauner
authored andcommitted
fs: WQ_PERCPU added to alloc_workqueue users
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND. This lack of consistentcy cannot be addressed without refactoring the API. alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND. This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they’re needed and reducing noise when CPUs are isolated. This patch adds a new WQ_PERCPU flag to all the fs subsystem users to explicitly request the use of the per-CPU behavior. Both flags coexist for one release cycle to allow callers to transition their calls. Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default. With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU. All existing users have been updated accordingly. Suggested-by: Tejun Heo <tj@kernel.org> Signed-off-by: Marco Crivellari <marco.crivellari@suse.com> Link: https://lore.kernel.org/20250916082906.77439-4-marco.crivellari@suse.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 4ef64db commit 69635d7

19 files changed

Lines changed: 51 additions & 37 deletions

File tree

fs/afs/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ static int __init afs_init(void)
169169

170170
printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
171171

172-
afs_wq = alloc_workqueue("afs", 0, 0);
172+
afs_wq = alloc_workqueue("afs", WQ_PERCPU, 0);
173173
if (!afs_wq)
174174
goto error_afs_wq;
175175
afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM | WQ_UNBOUND, 0);
176176
if (!afs_async_calls)
177177
goto error_async;
178-
afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
178+
afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM | WQ_PERCPU, 0);
179179
if (!afs_lock_manager)
180180
goto error_lockmgr;
181181

fs/bcachefs/super.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -801,13 +801,13 @@ int bch2_fs_init_rw(struct bch_fs *c)
801801
if (!(c->btree_update_wq = alloc_workqueue("bcachefs",
802802
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_UNBOUND, 512)) ||
803803
!(c->btree_write_complete_wq = alloc_workqueue("bcachefs_btree_write_complete",
804-
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM, 1)) ||
804+
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_PERCPU, 1)) ||
805805
!(c->copygc_wq = alloc_workqueue("bcachefs_copygc",
806-
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE, 1)) ||
806+
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE|WQ_PERCPU, 1)) ||
807807
!(c->btree_write_submit_wq = alloc_workqueue("bcachefs_btree_write_sumit",
808-
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM, 1)) ||
808+
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_PERCPU, 1)) ||
809809
!(c->write_ref_wq = alloc_workqueue("bcachefs_write_ref",
810-
WQ_FREEZABLE, 0)))
810+
WQ_FREEZABLE|WQ_PERCPU, 0)))
811811
return bch_err_throw(c, ENOMEM_fs_other_alloc);
812812

813813
int ret = bch2_fs_btree_interior_update_init(c) ?:
@@ -975,7 +975,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts *opts,
975975
sizeof(struct sort_iter_set);
976976

977977
if (!(c->btree_read_complete_wq = alloc_workqueue("bcachefs_btree_read_complete",
978-
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM, 512)) ||
978+
WQ_HIGHPRI|WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_PERCPU, 512)) ||
979979
enumerated_ref_init(&c->writes, BCH_WRITE_REF_NR,
980980
bch2_writes_disabled) ||
981981
mempool_init_kmalloc_pool(&c->fill_iter, 1, iter_size) ||

fs/btrfs/disk-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info)
19581958
{
19591959
u32 max_active = fs_info->thread_pool_size;
19601960
unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND;
1961-
unsigned int ordered_flags = WQ_MEM_RECLAIM | WQ_FREEZABLE;
1961+
unsigned int ordered_flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_PERCPU;
19621962

19631963
fs_info->workers =
19641964
btrfs_alloc_workqueue(fs_info, "worker", flags, max_active, 16);

fs/ceph/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
862862
fsc->inode_wq = alloc_workqueue("ceph-inode", WQ_UNBOUND, 0);
863863
if (!fsc->inode_wq)
864864
goto fail_client;
865-
fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1);
865+
fsc->cap_wq = alloc_workqueue("ceph-cap", WQ_PERCPU, 1);
866866
if (!fsc->cap_wq)
867867
goto fail_inode_wq;
868868

fs/dlm/lowcomms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ static int work_start(void)
17031703
return -ENOMEM;
17041704
}
17051705

1706-
process_workqueue = alloc_workqueue("dlm_process", WQ_HIGHPRI | WQ_BH, 0);
1706+
process_workqueue = alloc_workqueue("dlm_process", WQ_HIGHPRI | WQ_BH | WQ_PERCPU, 0);
17071707
if (!process_workqueue) {
17081708
log_print("can't start dlm_process");
17091709
destroy_workqueue(io_workqueue);

fs/dlm/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static int __init init_dlm(void)
5252
if (error)
5353
goto out_user;
5454

55-
dlm_wq = alloc_workqueue("dlm_wq", 0, 0);
55+
dlm_wq = alloc_workqueue("dlm_wq", WQ_PERCPU, 0);
5656
if (!dlm_wq) {
5757
error = -ENOMEM;
5858
goto out_plock;

fs/fs-writeback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ void cgroup_writeback_umount(struct super_block *sb)
11801180

11811181
static int __init cgroup_writeback_init(void)
11821182
{
1183-
isw_wq = alloc_workqueue("inode_switch_wbs", 0, 0);
1183+
isw_wq = alloc_workqueue("inode_switch_wbs", WQ_PERCPU, 0);
11841184
if (!isw_wq)
11851185
return -ENOMEM;
11861186
return 0;

fs/gfs2/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ static int __init init_gfs2_fs(void)
151151

152152
error = -ENOMEM;
153153
gfs2_recovery_wq = alloc_workqueue("gfs2_recovery",
154-
WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
154+
WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_PERCPU,
155+
0);
155156
if (!gfs2_recovery_wq)
156157
goto fail_wq1;
157158

@@ -160,7 +161,7 @@ static int __init init_gfs2_fs(void)
160161
if (!gfs2_control_wq)
161162
goto fail_wq2;
162163

163-
gfs2_freeze_wq = alloc_workqueue("gfs2_freeze", 0, 0);
164+
gfs2_freeze_wq = alloc_workqueue("gfs2_freeze", WQ_PERCPU, 0);
164165

165166
if (!gfs2_freeze_wq)
166167
goto fail_wq3;

fs/gfs2/ops_fstype.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,13 +1193,15 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
11931193

11941194
error = -ENOMEM;
11951195
sdp->sd_glock_wq = alloc_workqueue("gfs2-glock/%s",
1196-
WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_FREEZABLE, 0,
1196+
WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_FREEZABLE | WQ_PERCPU,
1197+
0,
11971198
sdp->sd_fsname);
11981199
if (!sdp->sd_glock_wq)
11991200
goto fail_iput;
12001201

12011202
sdp->sd_delete_wq = alloc_workqueue("gfs2-delete/%s",
1202-
WQ_MEM_RECLAIM | WQ_FREEZABLE, 0, sdp->sd_fsname);
1203+
WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_PERCPU, 0,
1204+
sdp->sd_fsname);
12031205
if (!sdp->sd_delete_wq)
12041206
goto fail_glock_wq;
12051207

fs/ocfs2/dlm/dlmdomain.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,8 @@ static int dlm_join_domain(struct dlm_ctxt *dlm)
18761876
dlm_debug_init(dlm);
18771877

18781878
snprintf(wq_name, O2NM_MAX_NAME_LEN, "dlm_wq-%s", dlm->name);
1879-
dlm->dlm_worker = alloc_workqueue(wq_name, WQ_MEM_RECLAIM, 0);
1879+
dlm->dlm_worker = alloc_workqueue(wq_name, WQ_MEM_RECLAIM | WQ_PERCPU,
1880+
0);
18801881
if (!dlm->dlm_worker) {
18811882
status = -ENOMEM;
18821883
mlog_errno(status);

0 commit comments

Comments
 (0)