bcachefs: Switch ec_stripes_heap_lock to a mutex
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 19 Feb 2023 01:49:37 +0000 (20:49 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:53 +0000 (17:09 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bcachefs.h
fs/bcachefs/buckets.c
fs/bcachefs/ec.c
fs/bcachefs/super.c

index 5dc4b0c133add38fefdd793c9a642404f17b7845..c9c7ffa9fa719debb24f6d994c77501eeaa270ec 100644 (file)
@@ -941,7 +941,7 @@ struct bch_fs {
        GENRADIX(struct gc_stripe) gc_stripes;
 
        ec_stripes_heap         ec_stripes_heap;
-       spinlock_t              ec_stripes_heap_lock;
+       struct mutex            ec_stripes_heap_lock;
 
        /* ERASURE CODING */
        struct list_head        ec_stripe_head_list;
index 2e1751eeaef4428fb54f50c2f43729171eafa4ae..ddbf88a759f9a99f1935a00ff848556b48ef1c94 100644 (file)
@@ -907,10 +907,10 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans,
                return -ENOMEM;
        }
 
-       spin_lock(&c->ec_stripes_heap_lock);
+       mutex_lock(&c->ec_stripes_heap_lock);
 
        if (!m || !m->alive) {
-               spin_unlock(&c->ec_stripes_heap_lock);
+               mutex_unlock(&c->ec_stripes_heap_lock);
                bch_err_ratelimited(c, "pointer to nonexistent stripe %llu",
                                    (u64) p.idx);
                bch2_inconsistent_error(c);
@@ -920,7 +920,7 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans,
        m->block_sectors[p.block] += sectors;
 
        r = m->r;
-       spin_unlock(&c->ec_stripes_heap_lock);
+       mutex_unlock(&c->ec_stripes_heap_lock);
 
        r.e.data_type = data_type;
        update_replicas(c, k, &r.e, sectors, trans->journal_res.seq, true);
@@ -1047,9 +1047,9 @@ int bch2_mark_stripe(struct btree_trans *trans,
                }
 
                if (!new_s) {
-                       spin_lock(&c->ec_stripes_heap_lock);
+                       mutex_lock(&c->ec_stripes_heap_lock);
                        bch2_stripes_heap_del(c, m, idx);
-                       spin_unlock(&c->ec_stripes_heap_lock);
+                       mutex_unlock(&c->ec_stripes_heap_lock);
 
                        memset(m, 0, sizeof(*m));
                } else {
@@ -1063,9 +1063,9 @@ int bch2_mark_stripe(struct btree_trans *trans,
                        for (i = 0; i < new_s->nr_blocks; i++)
                                m->blocks_nonempty += !!stripe_blockcount_get(new_s, i);
 
-                       spin_lock(&c->ec_stripes_heap_lock);
+                       mutex_lock(&c->ec_stripes_heap_lock);
                        bch2_stripes_heap_update(c, m, idx);
-                       spin_unlock(&c->ec_stripes_heap_lock);
+                       mutex_unlock(&c->ec_stripes_heap_lock);
                }
        } else {
                struct gc_stripe *m =
index 6d0a49000bef208fb0b6ab54ee3de7d3dde83808..7a6b962ae1fc561ff93098659f22ffaf4c3c203b 100644 (file)
@@ -549,13 +549,13 @@ static int __ec_stripe_mem_alloc(struct bch_fs *c, size_t idx, gfp_t gfp)
                if (!init_heap(&n, max(1024UL, roundup_pow_of_two(idx + 1)), gfp))
                        return -ENOMEM;
 
-               spin_lock(&c->ec_stripes_heap_lock);
+               mutex_lock(&c->ec_stripes_heap_lock);
                if (n.size > h->size) {
                        memcpy(n.data, h->data, h->used * sizeof(h->data[0]));
                        n.used = h->used;
                        swap(*h, n);
                }
-               spin_unlock(&c->ec_stripes_heap_lock);
+               mutex_unlock(&c->ec_stripes_heap_lock);
 
                free_heap(&n);
        }
@@ -695,15 +695,15 @@ static void ec_stripe_delete_work(struct work_struct *work)
        ssize_t idx;
 
        while (1) {
-               spin_lock(&c->ec_stripes_heap_lock);
+               mutex_lock(&c->ec_stripes_heap_lock);
                idx = stripe_idx_to_delete(c);
                if (idx < 0) {
-                       spin_unlock(&c->ec_stripes_heap_lock);
+                       mutex_unlock(&c->ec_stripes_heap_lock);
                        break;
                }
 
                bch2_stripes_heap_del(c, genradix_ptr(&c->stripes, idx), idx);
-               spin_unlock(&c->ec_stripes_heap_lock);
+               mutex_unlock(&c->ec_stripes_heap_lock);
 
                if (ec_stripe_delete(c, idx))
                        break;
@@ -1013,12 +1013,13 @@ static void ec_stripe_create(struct ec_stripe_new *s)
                bch_err(c, "error creating stripe: error updating pointers: %s",
                        bch2_err_str(ret));
 
-       spin_lock(&c->ec_stripes_heap_lock);
+
+       mutex_lock(&c->ec_stripes_heap_lock);
        m = genradix_ptr(&c->stripes, s->new_stripe.key.k.p.offset);
 
        BUG_ON(m->on_heap);
        bch2_stripes_heap_insert(c, m, s->new_stripe.key.k.p.offset);
-       spin_unlock(&c->ec_stripes_heap_lock);
+       mutex_unlock(&c->ec_stripes_heap_lock);
 err_put_writes:
        bch2_write_ref_put(c, BCH_WRITE_REF_stripe_create);
 err:
@@ -1398,7 +1399,7 @@ static s64 get_existing_stripe(struct bch_fs *c,
        if (may_create_new_stripe(c))
                return -1;
 
-       spin_lock(&c->ec_stripes_heap_lock);
+       mutex_lock(&c->ec_stripes_heap_lock);
        for (heap_idx = 0; heap_idx < h->used; heap_idx++) {
                /* No blocks worth reusing, stripe will just be deleted: */
                if (!h->data[heap_idx].blocks_nonempty)
@@ -1416,12 +1417,11 @@ static s64 get_existing_stripe(struct bch_fs *c,
                        break;
                }
        }
-       spin_unlock(&c->ec_stripes_heap_lock);
+       mutex_unlock(&c->ec_stripes_heap_lock);
        return ret;
 }
 
-static int __bch2_ec_stripe_head_reuse(struct bch_fs *c,
-                                                  struct ec_stripe_head *h)
+static int __bch2_ec_stripe_head_reuse(struct bch_fs *c, struct ec_stripe_head *h)
 {
        unsigned i;
        s64 idx;
@@ -1464,8 +1464,7 @@ static int __bch2_ec_stripe_head_reuse(struct bch_fs *c,
        return 0;
 }
 
-static int __bch2_ec_stripe_head_reserve(struct bch_fs *c,
-                                                       struct ec_stripe_head *h)
+static int __bch2_ec_stripe_head_reserve(struct bch_fs *c, struct ec_stripe_head *h)
 {
        return bch2_disk_reservation_get(c, &h->s->res,
                                         h->blocksize,
@@ -1606,9 +1605,9 @@ int bch2_stripes_read(struct bch_fs *c)
                for (i = 0; i < s->nr_blocks; i++)
                        m->blocks_nonempty += !!stripe_blockcount_get(s, i);
 
-               spin_lock(&c->ec_stripes_heap_lock);
+               mutex_lock(&c->ec_stripes_heap_lock);
                bch2_stripes_heap_update(c, m, k.k->p.offset);
-               spin_unlock(&c->ec_stripes_heap_lock);
+               mutex_unlock(&c->ec_stripes_heap_lock);
        }
        bch2_trans_iter_exit(&trans, &iter);
 
@@ -1626,7 +1625,7 @@ void bch2_stripes_heap_to_text(struct printbuf *out, struct bch_fs *c)
        struct stripe *m;
        size_t i;
 
-       spin_lock(&c->ec_stripes_heap_lock);
+       mutex_lock(&c->ec_stripes_heap_lock);
        for (i = 0; i < min_t(size_t, h->used, 20); i++) {
                m = genradix_ptr(&c->stripes, h->data[i].idx);
 
@@ -1635,7 +1634,7 @@ void bch2_stripes_heap_to_text(struct printbuf *out, struct bch_fs *c)
                       m->nr_blocks - m->nr_redundant,
                       m->nr_redundant);
        }
-       spin_unlock(&c->ec_stripes_heap_lock);
+       mutex_unlock(&c->ec_stripes_heap_lock);
 }
 
 void bch2_new_stripes_to_text(struct printbuf *out, struct bch_fs *c)
index f703e41c7560affbeb48cb50dc796948c68a5c30..b030d0bb26e709cfd40cb17b0e44a25ee7f75f65 100644 (file)
@@ -706,7 +706,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
        INIT_LIST_HEAD(&c->data_progress_list);
        mutex_init(&c->data_progress_lock);
 
-       spin_lock_init(&c->ec_stripes_heap_lock);
+       mutex_init(&c->ec_stripes_heap_lock);
 
        seqcount_init(&c->gc_pos_lock);