From 6474b706108bac9e531a71ddeb8150f8fa17163c Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 11 Dec 2023 02:31:12 -0500 Subject: [PATCH] bcachefs: Clean up btree_trans Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_iter.c | 12 ++++--- fs/bcachefs/btree_trans_commit.c | 4 +-- fs/bcachefs/btree_types.h | 59 ++++++++++++++++---------------- fs/bcachefs/btree_update.c | 4 +-- fs/bcachefs/btree_update.h | 2 +- fs/bcachefs/fsck.c | 2 +- 6 files changed, 42 insertions(+), 41 deletions(-) diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index cfe81db883cc..ced13bbc52f7 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -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; } diff --git a/fs/bcachefs/btree_trans_commit.c b/fs/bcachefs/btree_trans_commit.c index 0e3603d367f9..7e6ba3061e7c 100644 --- a/fs/bcachefs/btree_trans_commit.c +++ b/fs/bcachefs/btree_trans_commit.c @@ -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) diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h index 54156a05ebf5..c1baece14120 100644 --- a/fs/bcachefs/btree_types.h +++ b/fs/bcachefs/btree_types.h @@ -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; - u16 journal_entries_u64s; - u16 journal_entries_size; - - 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]; + 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: */ - struct btree_trans_commit_hook *hooks; + u16 journal_entries_u64s; + u16 journal_entries_size; struct jset_entry *journal_entries; + + struct btree_insert_entry updates[BTREE_ITER_MAX]; + struct btree_trans_commit_hook *hooks; 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) diff --git a/fs/bcachefs/btree_update.c b/fs/bcachefs/btree_update.c index a5a99c3cb32e..37d4039dd0fe 100644 --- a/fs/bcachefs/btree_update.c +++ b/fs/bcachefs/btree_update.c @@ -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) { diff --git a/fs/bcachefs/btree_update.h b/fs/bcachefs/btree_update.h index fbb83e1aa2b2..b9382b7b288b 100644 --- a/fs/bcachefs/btree_update.h +++ b/fs/bcachefs/btree_update.h @@ -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; diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index f89d1029366b..796e1a8447d6 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -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,