From f33600057f50d3dea5cb3bda05c21ecce7125282 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 10 Dec 2023 17:44:04 -0500 Subject: [PATCH] bcachefs: bch2_trans_node_add no longer uses trans_for_each_path() In the future we'll be making trans->paths resizable and potentially having _many_ more paths (for fsck); we need to start fixing algorithms that walk each path in a transaction where possible. Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_iter.c | 20 ++++++++++++++------ fs/bcachefs/btree_iter.h | 2 +- fs/bcachefs/btree_update_interior.c | 10 +++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 2b0dc0ebbba3..6d6963858a83 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -674,14 +674,22 @@ static void bch2_trans_revalidate_updates_in_node(struct btree_trans *trans, str * A btree node is being replaced - update the iterator to point to the new * node: */ -void bch2_trans_node_add(struct btree_trans *trans, struct btree *b) +void bch2_trans_node_add(struct btree_trans *trans, + struct btree_path *path, + struct btree *b) { - struct btree_path *path; + struct btree_path *prev; - trans_for_each_path(trans, path) - if (path->uptodate == BTREE_ITER_UPTODATE && - !path->cached && - btree_path_pos_in_node(path, b)) { + BUG_ON(!btree_path_pos_in_node(path, b)); + + while ((prev = prev_btree_path(trans, path)) && + btree_path_pos_in_node(prev, b)) + path = prev; + + for (; + path && btree_path_pos_in_node(path, b); + path = next_btree_path(trans, path)) + if (path->uptodate == BTREE_ITER_UPTODATE && !path->cached) { enum btree_node_locked_type t = btree_lock_want(path, b->c.level); diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index 5be3c1a2c820..f7d5f8403940 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -322,7 +322,7 @@ static inline void bch2_btree_path_downgrade(struct btree_trans *trans, void bch2_trans_downgrade(struct btree_trans *); -void bch2_trans_node_add(struct btree_trans *trans, struct btree *); +void bch2_trans_node_add(struct btree_trans *trans, struct btree_path *, struct btree *); void bch2_trans_node_reinit_iter(struct btree_trans *, struct btree *); int __must_check __bch2_btree_iter_traverse(struct btree_iter *iter); diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c index b3f1f7c9a5f4..cffc66cd481f 100644 --- a/fs/bcachefs/btree_update_interior.c +++ b/fs/bcachefs/btree_update_interior.c @@ -1601,10 +1601,10 @@ static int btree_split(struct btree_update *as, struct btree_trans *trans, bch2_btree_node_free_inmem(trans, path, b); if (n3) - bch2_trans_node_add(trans, n3); + bch2_trans_node_add(trans, path, n3); if (n2) - bch2_trans_node_add(trans, n2); - bch2_trans_node_add(trans, n1); + bch2_trans_node_add(trans, path2, n2); + bch2_trans_node_add(trans, path1, n1); if (n3) six_unlock_intent(&n3->c.lock); @@ -1913,7 +1913,7 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans, bch2_btree_node_free_inmem(trans, path, b); bch2_btree_node_free_inmem(trans, sib_path, m); - bch2_trans_node_add(trans, n); + bch2_trans_node_add(trans, path, n); bch2_trans_verify_paths(trans); @@ -1985,7 +1985,7 @@ int bch2_btree_node_rewrite(struct btree_trans *trans, bch2_btree_node_free_inmem(trans, iter->path, b); - bch2_trans_node_add(trans, n); + bch2_trans_node_add(trans, iter->path, n); six_unlock_intent(&n->c.lock); bch2_btree_update_done(as, trans); -- 2.39.5