]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bcachefs: Kill __bch2_accounting_mem_mod()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 12 Aug 2024 06:35:10 +0000 (02:35 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 14 Aug 2024 03:00:50 +0000 (23:00 -0400)
The next patch will be adding a disk accounting counter type which is
not kept in the in-memory eytzinger tree.

As prep, fold __bch2_accounting_mem_mod() into
bch2_accounting_mem_mod_locked() so that we can check for that counter
type and bail out without calling bpos_to_disk_accounting_pos() twice.

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

index 1a1e9d2036da7add948de0eea3c4cf0ffad14903..a0101d9c5d83f6b8a9f06a07d4215cb36d85a651 100644 (file)
@@ -712,7 +712,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
                                a->k.version = journal_pos_to_bversion(&trans->journal_res,
                                                                (u64 *) entry - (u64 *) trans->journal_entries);
                                BUG_ON(bversion_zero(a->k.version));
-                               ret = bch2_accounting_mem_mod_locked(trans, accounting_i_to_s_c(a), false);
+                               ret = bch2_accounting_mem_mod_locked(trans, accounting_i_to_s_c(a), false, false);
                                if (ret)
                                        goto revert_fs_usage;
                        }
@@ -798,7 +798,7 @@ revert_fs_usage:
                        struct bkey_s_accounting a = bkey_i_to_s_accounting(entry2->start);
 
                        bch2_accounting_neg(a);
-                       bch2_accounting_mem_mod_locked(trans, a.c, false);
+                       bch2_accounting_mem_mod_locked(trans, a.c, false, false);
                        bch2_accounting_neg(a);
                }
        percpu_up_read(&c->mark_lock);
index f059cbffdf2307c4466f49f33dd37ef9ab69411b..e57b40623cd98b54c944e3d28c38d6f8da56a4e3 100644 (file)
@@ -566,7 +566,7 @@ int bch2_gc_accounting_done(struct bch_fs *c)
                                        struct { __BKEY_PADDED(k, BCH_ACCOUNTING_MAX_COUNTERS); } k_i;
 
                                        accounting_key_init(&k_i.k, &acc_k, src_v, nr);
-                                       bch2_accounting_mem_mod_locked(trans, bkey_i_to_s_c_accounting(&k_i.k), false);
+                                       bch2_accounting_mem_mod_locked(trans, bkey_i_to_s_c_accounting(&k_i.k), false, false);
 
                                        preempt_disable();
                                        struct bch_fs_usage_base *dst = this_cpu_ptr(c->usage);
@@ -595,7 +595,7 @@ static int accounting_read_key(struct btree_trans *trans, struct bkey_s_c k)
                return 0;
 
        percpu_down_read(&c->mark_lock);
-       int ret = __bch2_accounting_mem_mod(c, bkey_s_c_to_accounting(k), false);
+       int ret = bch2_accounting_mem_mod_locked(trans, bkey_s_c_to_accounting(k), false, true);
        percpu_up_read(&c->mark_lock);
 
        if (bch2_accounting_key_is_zero(bkey_s_c_to_accounting(k)) &&
index b92f8c2e305411b31cd756774ea8d149be65f85b..653090667aaa4dc2fdb3892df123495e4c9ab711 100644 (file)
@@ -106,41 +106,17 @@ static inline int accounting_pos_cmp(const void *_l, const void *_r)
 int bch2_accounting_mem_insert(struct bch_fs *, struct bkey_s_c_accounting, bool);
 void bch2_accounting_mem_gc(struct bch_fs *);
 
-static inline int __bch2_accounting_mem_mod(struct bch_fs *c, struct bkey_s_c_accounting a, bool gc)
-{
-       struct bch_accounting_mem *acc = &c->accounting;
-       unsigned idx;
-
-       EBUG_ON(gc && !acc->gc_running);
-
-       while ((idx = eytzinger0_find(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]),
-                                     accounting_pos_cmp, &a.k->p)) >= acc->k.nr) {
-               int ret = bch2_accounting_mem_insert(c, a, gc);
-               if (ret)
-                       return ret;
-       }
-
-       struct accounting_mem_entry *e = &acc->k.data[idx];
-
-       EBUG_ON(bch2_accounting_counters(a.k) != e->nr_counters);
-
-       for (unsigned i = 0; i < bch2_accounting_counters(a.k); i++)
-               this_cpu_add(e->v[gc][i], a.v->d[i]);
-       return 0;
-}
-
 /*
  * Update in memory counters so they match the btree update we're doing; called
  * from transaction commit path
  */
-static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, struct bkey_s_c_accounting a, bool gc)
+static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, struct bkey_s_c_accounting a, bool gc, bool read)
 {
        struct bch_fs *c = trans->c;
+       struct disk_accounting_pos acc_k;
+       bpos_to_disk_accounting_pos(&acc_k, a.k->p);
 
-       if (!gc) {
-               struct disk_accounting_pos acc_k;
-               bpos_to_disk_accounting_pos(&acc_k, a.k->p);
-
+       if (!gc && !read) {
                switch (acc_k.type) {
                case BCH_DISK_ACCOUNTING_persistent_reserved:
                        trans->fs_usage_delta.reserved += acc_k.persistent_reserved.nr_replicas * a.v->d[0];
@@ -161,13 +137,31 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, stru
                }
        }
 
-       return __bch2_accounting_mem_mod(c, a, gc);
+       struct bch_accounting_mem *acc = &c->accounting;
+       unsigned idx;
+
+       EBUG_ON(gc && !acc->gc_running);
+
+       while ((idx = eytzinger0_find(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]),
+                                     accounting_pos_cmp, &a.k->p)) >= acc->k.nr) {
+               int ret = bch2_accounting_mem_insert(c, a, gc);
+               if (ret)
+                       return ret;
+       }
+
+       struct accounting_mem_entry *e = &acc->k.data[idx];
+
+       EBUG_ON(bch2_accounting_counters(a.k) != e->nr_counters);
+
+       for (unsigned i = 0; i < bch2_accounting_counters(a.k); i++)
+               this_cpu_add(e->v[gc][i], a.v->d[i]);
+       return 0;
 }
 
 static inline int bch2_accounting_mem_add(struct btree_trans *trans, struct bkey_s_c_accounting a, bool gc)
 {
        percpu_down_read(&trans->c->mark_lock);
-       int ret = bch2_accounting_mem_mod_locked(trans, a, gc);
+       int ret = bch2_accounting_mem_mod_locked(trans, a, gc, false);
        percpu_up_read(&trans->c->mark_lock);
        return ret;
 }