bcachefs: Add a workqueue for journal reclaim
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 19 Jan 2019 17:20:00 +0000 (12:20 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:14 +0000 (17:08 -0400)
journal reclaim writes btree nodes, which can end up waiting for in
flight btree writes to complete, and btree write completions run out of
workqueues - so we can't run out of the same workqueue or we risk
deadlock

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bcachefs.h
fs/bcachefs/journal_reclaim.c
fs/bcachefs/super.c

index 244b808688b325f5dfacae4672aacbbc430f79c6..64836a8c69d8cf0bc02b1965def1722c24728b26 100644 (file)
@@ -600,6 +600,7 @@ struct bch_fs {
        struct workqueue_struct *wq;
        /* copygc needs its own workqueue for index updates.. */
        struct workqueue_struct *copygc_wq;
+       struct workqueue_struct *journal_reclaim_wq;
 
        /* ALLOCATION */
        struct delayed_work     pd_controllers_update;
index eaf77c77b2c452905f79d1d6b70651de98e8cfae..f24546dbf3edfa45a5f2652d3237380e0bf21be6 100644 (file)
@@ -336,7 +336,7 @@ void bch2_journal_reclaim_work(struct work_struct *work)
                mutex_unlock(&j->reclaim_lock);
 
        if (!test_bit(BCH_FS_RO, &c->flags))
-               queue_delayed_work(system_freezable_wq, &j->reclaim_work,
+               queue_delayed_work(c->journal_reclaim_wq, &j->reclaim_work,
                                   msecs_to_jiffies(j->reclaim_delay_ms));
 }
 
index 4e811ffdec8e1eb327f29666ee2e39c190bb648c..198f78dbb6d9b70a8051e0d7258c31af8b7a904c 100644 (file)
@@ -388,6 +388,8 @@ static void bch2_fs_free(struct bch_fs *c)
        kfree(c->replicas_gc.entries);
        kfree(rcu_dereference_protected(c->disk_groups, 1));
 
+       if (c->journal_reclaim_wq)
+               destroy_workqueue(c->journal_reclaim_wq);
        if (c->copygc_wq)
                destroy_workqueue(c->copygc_wq);
        if (c->wq)
@@ -602,6 +604,8 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
                                WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_HIGHPRI, 1)) ||
            !(c->copygc_wq = alloc_workqueue("bcache_copygc",
                                WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_HIGHPRI, 1)) ||
+           !(c->journal_reclaim_wq = alloc_workqueue("bcache_journal",
+                               WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_HIGHPRI, 1)) ||
            percpu_ref_init(&c->writes, bch2_writes_disabled, 0, GFP_KERNEL) ||
            mempool_init_kmalloc_pool(&c->btree_reserve_pool, 1,
                                      sizeof(struct btree_reserve)) ||