bcachefs: Clean up btree_trans

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-12-11 02:31:12 -05:00
parent 398c98347d
commit 6474b70610
6 changed files with 42 additions and 41 deletions

View 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;
}

View 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)

View 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;
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)

View 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) {

View 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;

View 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,