]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Assorted preemption fixes
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 25 Dec 2022 03:44:56 +0000 (22:44 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:19 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/btree_gc.c
fs/bcachefs/buckets.c
fs/bcachefs/journal.c

index 3549f0f54624413aafd257b897e2e7be6c96eaf2..b5f5c223e00880626c83446c888bc769868c109e 100644 (file)
@@ -291,8 +291,10 @@ int bch2_alloc_read(struct bch_fs *c, struct list_head *journal_replay_list)
                                bch2_alloc_read_key(c, bkey_i_to_s_c(k));
        }
 
+       percpu_down_write(&c->mark_lock);
        for_each_member_device(ca, c, i)
                bch2_dev_usage_from_buckets(c, ca);
+       percpu_up_write(&c->mark_lock);
 
        mutex_lock(&c->bucket_clock[READ].lock);
        for_each_member_device(ca, c, i) {
index b5a4ac9a4176b91042de8f7c40828e23d84bce4c..6ae03254c281193e5d4e64e2dabeb5cdc46f77be 100644 (file)
@@ -354,8 +354,6 @@ void bch2_mark_dev_superblock(struct bch_fs *c, struct bch_dev *ca,
        if (c) {
                lockdep_assert_held(&c->sb_lock);
                percpu_down_read(&c->mark_lock);
-       } else {
-               preempt_disable();
        }
 
        for (i = 0; i < layout->nr_superblocks; i++) {
@@ -377,11 +375,8 @@ void bch2_mark_dev_superblock(struct bch_fs *c, struct bch_dev *ca,
                                          gc_phase(GC_PHASE_SB), flags);
        }
 
-       if (c) {
+       if (c)
                percpu_up_read(&c->mark_lock);
-       } else {
-               preempt_enable();
-       }
 }
 
 static void bch2_mark_superblocks(struct bch_fs *c)
index 2fbcd85d9e754df9c1c9a78608e8caefe8237262..ecb0ca3f3a8f3a5bd29ee3d4994ed2e909b07a73 100644 (file)
@@ -393,14 +393,19 @@ void bch2_dev_usage_from_buckets(struct bch_fs *c, struct bch_dev *ca)
        struct bucket_array *buckets;
        struct bucket *g;
 
-       percpu_down_read(&c->mark_lock);
+       /*
+        * This is only called during startup, before there's any multithreaded
+        * access to c->usage:
+        */
+       preempt_disable();
        fs_usage = this_cpu_ptr(c->usage[0]);
+       preempt_enable();
+
        buckets = bucket_array(ca);
 
        for_each_bucket(g, buckets)
                if (g->mark.data_type)
                        bch2_dev_usage_update(c, ca, fs_usage, old, g->mark, false);
-       percpu_up_read(&c->mark_lock);
 }
 
 #define bucket_data_cmpxchg(c, ca, fs_usage, g, new, expr)     \
@@ -513,8 +518,12 @@ void bch2_mark_alloc_bucket(struct bch_fs *c, struct bch_dev *ca,
                            size_t b, bool owned_by_allocator,
                            struct gc_pos pos, unsigned flags)
 {
+       preempt_disable();
+
        do_mark_fn(__bch2_mark_alloc_bucket, c, pos, flags,
                   ca, b, owned_by_allocator);
+
+       preempt_enable();
 }
 
 static int bch2_mark_alloc(struct bch_fs *c, struct bkey_s_c k,
index c0dcc0ff65ce4480121172f0749c127e08e3c3e4..dbecb4072af00fa245eb7c0b800b3b621f97fec5 100644 (file)
@@ -835,8 +835,6 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
                if (c) {
                        percpu_down_read(&c->mark_lock);
                        spin_lock(&c->journal.lock);
-               } else {
-                       preempt_disable();
                }
 
                pos = ja->nr ? (ja->cur_idx + 1) % ja->nr : 0;
@@ -866,8 +864,6 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
                if (c) {
                        spin_unlock(&c->journal.lock);
                        percpu_up_read(&c->mark_lock);
-               } else {
-                       preempt_enable();
                }
 
                if (!new_fs)