]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcache: WQ_PERCPU added to alloc_workqueue users
authorMarco Crivellari <marco.crivellari@suse.com>
Thu, 13 Nov 2025 05:36:29 +0000 (13:36 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 13 Nov 2025 16:18:06 +0000 (09:18 -0700)
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 continues the effort to refactor worqueue APIs, which has begun
with the change introducing new workqueues and a new alloc_workqueue flag:

commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")
commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")

This change adds a new WQ_PERCPU flag to explicitly request
alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified.

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.

Once migration is complete, WQ_UNBOUND can be removed and unbound will
become the implicit default.

Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
Signed-off-by: Coly Li <colyli@fnnas.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/btree.c
drivers/md/bcache/super.c
drivers/md/bcache/writeback.c

index 24ddc353cb3052564c88dadb98b24c1a1a6aa9d3..3ed39c823826461f8aeceecf080a5e3c6e6b1685 100644 (file)
@@ -2822,7 +2822,8 @@ void bch_btree_exit(void)
 
 int __init bch_btree_init(void)
 {
-       btree_io_wq = alloc_workqueue("bch_btree_io", WQ_MEM_RECLAIM, 0);
+       btree_io_wq = alloc_workqueue("bch_btree_io",
+                                     WQ_MEM_RECLAIM | WQ_PERCPU, 0);
        if (!btree_io_wq)
                return -ENOMEM;
 
index 92ced6b28cb2c41070cffd2f092ded2d325ad785..c17d4517af22c802bdb6f1f25eb6a5004720b9c6 100644 (file)
@@ -1939,7 +1939,8 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
        if (!c->uuids)
                goto err;
 
-       c->moving_gc_wq = alloc_workqueue("bcache_gc", WQ_MEM_RECLAIM, 0);
+       c->moving_gc_wq = alloc_workqueue("bcache_gc",
+                                         WQ_MEM_RECLAIM | WQ_PERCPU, 0);
        if (!c->moving_gc_wq)
                goto err;
 
@@ -2902,7 +2903,7 @@ static int __init bcache_init(void)
        if (bch_btree_init())
                goto err;
 
-       bcache_wq = alloc_workqueue("bcache", WQ_MEM_RECLAIM, 0);
+       bcache_wq = alloc_workqueue("bcache", WQ_MEM_RECLAIM | WQ_PERCPU, 0);
        if (!bcache_wq)
                goto err;
 
@@ -2915,11 +2916,12 @@ static int __init bcache_init(void)
         *
         * We still want to user our own queue to not congest the `system_percpu_wq`.
         */
-       bch_flush_wq = alloc_workqueue("bch_flush", 0, 0);
+       bch_flush_wq = alloc_workqueue("bch_flush", WQ_PERCPU, 0);
        if (!bch_flush_wq)
                goto err;
 
-       bch_journal_wq = alloc_workqueue("bch_journal", WQ_MEM_RECLAIM, 0);
+       bch_journal_wq = alloc_workqueue("bch_journal",
+                                        WQ_MEM_RECLAIM | WQ_PERCPU, 0);
        if (!bch_journal_wq)
                goto err;
 
index cffef33b4acf3455b51efc85d5ba45e30c5bdc0c..4b237074f453e3272e6a30c838c6e96fcd8492ad 100644 (file)
@@ -1075,7 +1075,7 @@ void bch_cached_dev_writeback_init(struct cached_dev *dc)
 int bch_cached_dev_writeback_start(struct cached_dev *dc)
 {
        dc->writeback_write_wq = alloc_workqueue("bcache_writeback_wq",
-                                               WQ_MEM_RECLAIM, 0);
+                                               WQ_MEM_RECLAIM | WQ_PERCPU, 0);
        if (!dc->writeback_write_wq)
                return -ENOMEM;