Skip to content

Commit afe78ab

Browse files
kakraaxboe
authored andcommitted
bcache: Move journal work to new flush wq
This is potentially long running and not latency sensitive, let's get it out of the way of other latency sensitive events. As observed in the previous commit, the `system_wq` comes easily congested by bcache, and this fixes a few more stalls I was observing every once in a while. Let's not make this `WQ_MEM_RECLAIM` as it showed to reduce performance of boot and file system operations in my tests. Also, without `WQ_MEM_RECLAIM`, I no longer see desktop stalls. This matches the previous behavior as `system_wq` also does no memory reclaim: > // workqueue.c: > system_wq = alloc_workqueue("events", 0, 0); Cc: Coly Li <colyli@suse.de> Cc: stable@vger.kernel.org # 5.4+ Signed-off-by: Kai Krakow <kai@kaishome.de> Signed-off-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d797bd9 commit afe78ab

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎drivers/md/bcache/bcache.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent);
10051005

10061006
extern struct workqueue_struct *bcache_wq;
10071007
extern struct workqueue_struct *bch_journal_wq;
1008+
extern struct workqueue_struct *bch_flush_wq;
10081009
extern struct mutex bch_register_lock;
10091010
extern struct list_head bch_cache_sets;
10101011

‎drivers/md/bcache/journal.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,8 @@ atomic_t *bch_journal(struct cache_set *c,
932932
journal_try_write(c);
933933
} else if (!w->dirty) {
934934
w->dirty = true;
935-
schedule_delayed_work(&c->journal.work,
936-
msecs_to_jiffies(c->journal_delay_ms));
935+
queue_delayed_work(bch_flush_wq, &c->journal.work,
936+
msecs_to_jiffies(c->journal_delay_ms));
937937
spin_unlock(&c->journal.lock);
938938
} else {
939939
spin_unlock(&c->journal.lock);

‎drivers/md/bcache/super.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static int bcache_major;
4949
static DEFINE_IDA(bcache_device_idx);
5050
static wait_queue_head_t unregister_wait;
5151
struct workqueue_struct *bcache_wq;
52+
struct workqueue_struct *bch_flush_wq;
5253
struct workqueue_struct *bch_journal_wq;
5354

5455

@@ -2821,6 +2822,8 @@ static void bcache_exit(void)
28212822
destroy_workqueue(bcache_wq);
28222823
if (bch_journal_wq)
28232824
destroy_workqueue(bch_journal_wq);
2825+
if (bch_flush_wq)
2826+
destroy_workqueue(bch_flush_wq);
28242827
bch_btree_exit();
28252828

28262829
if (bcache_major)
@@ -2884,6 +2887,19 @@ static int __init bcache_init(void)
28842887
if (!bcache_wq)
28852888
goto err;
28862889

2890+
/*
2891+
* Let's not make this `WQ_MEM_RECLAIM` for the following reasons:
2892+
*
2893+
* 1. It used `system_wq` before which also does no memory reclaim.
2894+
* 2. With `WQ_MEM_RECLAIM` desktop stalls, increased boot times, and
2895+
* reduced throughput can be observed.
2896+
*
2897+
* We still want to user our own queue to not congest the `system_wq`.
2898+
*/
2899+
bch_flush_wq = alloc_workqueue("bch_flush", 0, 0);
2900+
if (!bch_flush_wq)
2901+
goto err;
2902+
28872903
bch_journal_wq = alloc_workqueue("bch_journal", WQ_MEM_RECLAIM, 0);
28882904
if (!bch_journal_wq)
28892905
goto err;

0 commit comments

Comments
 (0)