bcachefs: Clean up btree_trans
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 11 Dec 2023 07:31:12 +0000 (02:31 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Jan 2024 16:47:44 +0000 (11:47 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_trans_commit.c
fs/bcachefs/btree_types.h
fs/bcachefs/btree_update.c
fs/bcachefs/btree_update.h
fs/bcachefs/fsck.c

index cfe81db883ccacab0a0c42c028c22ed69597f71a..ced13bbc52f7842a732b4531621bebb2c438b341 100644 (file)
@@ -1493,7 +1493,7 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
 
        printbuf_exit(&buf);
 
-       trans->nr_max_paths = nr;
+       trans->nr_paths_max = nr;
 }
 
 noinline __cold
@@ -1526,13 +1526,11 @@ static inline btree_path_idx_t btree_path_alloc(struct btree_trans *trans,
        if (unlikely(idx == BTREE_ITER_MAX))
                btree_path_overflow(trans);
 
-       BUG_ON(idx > BTREE_ITER_MAX);
-
        /*
         * Do this before marking the new path as allocated, since it won't be
         * initialized yet:
         */
-       if (unlikely(idx > trans->nr_max_paths))
+       if (unlikely(idx > trans->nr_paths_max))
                bch2_trans_update_max_paths(trans);
 
        __set_bit(idx, trans->paths_allocated);
@@ -2918,6 +2916,10 @@ struct btree_trans *__bch2_trans_get(struct bch_fs *c, unsigned fn_idx)
                atomic_inc_not_zero(&c->journal_keys.ref);
        closure_init_stack(&trans->ref);
 
+       trans->paths_allocated  = trans->_paths_allocated;
+       trans->sorted           = trans->_sorted;
+       trans->paths            = trans->_paths;
+
        trans->paths_allocated[0] = 1;
 
        s = btree_trans_stats(trans);
@@ -2935,7 +2937,7 @@ struct btree_trans *__bch2_trans_get(struct bch_fs *c, unsigned fn_idx)
        }
 
        if (s) {
-               trans->nr_max_paths = s->nr_max_paths;
+               trans->nr_paths_max = s->nr_max_paths;
                trans->journal_entries_size = s->journal_entries_size;
        }
 
index 0e3603d367f9d6cd499d58958c1ffdd70b6f67b5..7e6ba3061e7cae644e5937f26e8bc982b8a2fe1a 100644 (file)
@@ -1044,9 +1044,9 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
                        trans->journal_u64s += jset_u64s(i->old_k.u64s);
        }
 
-       if (trans->extra_journal_res) {
+       if (trans->extra_disk_res) {
                ret = bch2_disk_reservation_add(c, trans->disk_res,
-                               trans->extra_journal_res,
+                               trans->extra_disk_res,
                                (flags & BCH_TRANS_COMMIT_no_enospc)
                                ? BCH_DISK_RESERVATION_NOFAIL : 0);
                if (ret)
index 54156a05ebf568f8065fc1c9818ebb6e23878d22..c1baece14120298b5ddb8b435cf3d6d2053371d2 100644 (file)
@@ -374,21 +374,22 @@ struct btree_trans_commit_hook {
 
 struct btree_trans {
        struct bch_fs           *c;
-       const char              *fn;
-       struct closure          ref;
-       struct list_head        list;
-       u64                     last_begin_time;
 
-       u8                      lock_may_not_fail;
-       u8                      lock_must_abort;
-       struct btree_bkey_cached_common *locking;
-       struct six_lock_waiter  locking_wait;
+       unsigned long           *paths_allocated;
+       u8                      *sorted;
+       struct btree_path       *paths;
 
-       int                     srcu_idx;
+       void                    *mem;
+       unsigned                mem_top;
+       unsigned                mem_max;
+       unsigned                mem_bytes;
 
+       btree_path_idx_t        nr_sorted;
+       btree_path_idx_t        nr_paths_max;
        u8                      fn_idx;
-       u8                      nr_sorted;
        u8                      nr_updates;
+       u8                      lock_must_abort;
+       bool                    lock_may_not_fail:1;
        bool                    srcu_held:1;
        bool                    used_mempool:1;
        bool                    in_traverse_all:1;
@@ -400,40 +401,38 @@ struct btree_trans {
        bool                    write_locked:1;
        enum bch_errcode        restarted:16;
        u32                     restart_count;
+
+       u64                     last_begin_time;
        unsigned long           last_begin_ip;
        unsigned long           last_restarted_ip;
        unsigned long           srcu_lock_time;
 
-       /*
-        * For when bch2_trans_update notices we'll be splitting a compressed
-        * extent:
-        */
-       unsigned                extra_journal_res;
-       btree_path_idx_t        nr_max_paths;
+       const char              *fn;
+       struct closure          ref;
+       struct list_head        list;
+       struct btree_bkey_cached_common *locking;
+       struct six_lock_waiter  locking_wait;
+       int                     srcu_idx;
+
+       /* update path: */
        u16                     journal_entries_u64s;
        u16                     journal_entries_size;
+       struct jset_entry       *journal_entries;
 
-       unsigned long           paths_allocated[BITS_TO_LONGS(BTREE_ITER_MAX)];
-
-       unsigned                mem_top;
-       unsigned                mem_max;
-       unsigned                mem_bytes;
-       void                    *mem;
-
-       u8                      sorted[BTREE_ITER_MAX + 8];
-       struct btree_path       paths[BTREE_ITER_MAX];
        struct btree_insert_entry updates[BTREE_ITER_MAX];
-
-       /* update path: */
        struct btree_trans_commit_hook *hooks;
-       struct jset_entry       *journal_entries;
        struct journal_entry_pin *journal_pin;
 
        struct journal_res      journal_res;
        u64                     *journal_seq;
        struct disk_reservation *disk_res;
        unsigned                journal_u64s;
+       unsigned                extra_disk_res; /* XXX kill */
        struct replicas_delta_list *fs_usage_deltas;
+
+       unsigned long           _paths_allocated[BITS_TO_LONGS(BTREE_ITER_MAX)];
+       u8                      _sorted[BTREE_ITER_MAX + 8];
+       struct btree_path       _paths[BTREE_ITER_MAX];
 };
 
 static inline struct btree_path *btree_iter_path(struct btree_trans *trans, struct btree_iter *iter)
index a5a99c3cb32ee58c798aecd69aa028a146b75461..37d4039dd0fe6f0e85de2aec2da3255502e0dce1 100644 (file)
@@ -200,7 +200,7 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
         */
        if (nr_splits > 1 &&
            (compressed_sectors = bch2_bkey_sectors_compressed(old)))
-               trans->extra_journal_res += compressed_sectors * (nr_splits - 1);
+               trans->extra_disk_res += compressed_sectors * (nr_splits - 1);
 
        if (front_split) {
                update = bch2_bkey_make_mut_noupdate(trans, old);
@@ -386,7 +386,7 @@ bch2_trans_update_by_path(struct btree_trans *trans, btree_path_idx_t path_idx,
 
        struct btree_path *path = trans->paths + path_idx;
        EBUG_ON(!path->should_be_locked);
-       EBUG_ON(trans->nr_updates >= BTREE_ITER_MAX);
+       EBUG_ON(trans->nr_updates >= ARRAY_SIZE(trans->updates));
        EBUG_ON(!bpos_eq(k->k.p, path->pos));
 
        n = (struct btree_insert_entry) {
index fbb83e1aa2b2b5538a46d2dcd3da041a6182dbdc..b9382b7b288b6a6189d191886511a3ee57187634 100644 (file)
@@ -196,10 +196,10 @@ static inline void bch2_trans_reset_updates(struct btree_trans *trans)
        trans_for_each_update(trans, i)
                bch2_path_put(trans, i->path, true);
 
-       trans->extra_journal_res        = 0;
        trans->nr_updates               = 0;
        trans->journal_entries_u64s     = 0;
        trans->hooks                    = NULL;
+       trans->extra_disk_res           = 0;
 
        if (trans->fs_usage_deltas) {
                trans->fs_usage_deltas->used = 0;
index f89d1029366b24a54318374b881583eba2a32664..796e1a8447d6110dffc6742638dd0308de82fd66 100644 (file)
@@ -1186,7 +1186,7 @@ static int overlapping_extents_found(struct btree_trans *trans,
                        swap(k1, k2);
                }
 
-               trans->extra_journal_res += bch2_bkey_sectors_compressed(k2);
+               trans->extra_disk_res += bch2_bkey_sectors_compressed(k2);
 
                ret =   bch2_trans_update_extent_overwrite(trans, old_iter,
                                BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE,