Commit 9b02d1c4 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Optimize calls to bch2_btree_iter_traverse()

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 5a8a52d6
...@@ -955,10 +955,10 @@ static void btree_iter_up(struct btree_iter *iter) ...@@ -955,10 +955,10 @@ static void btree_iter_up(struct btree_iter *iter)
btree_node_unlock(iter, iter->level++); btree_node_unlock(iter, iter->level++);
} }
int __must_check __bch2_btree_iter_traverse(struct btree_iter *); static int btree_iter_traverse_one(struct btree_iter *);
static int __btree_iter_traverse_all(struct btree_trans *trans, static int __btree_iter_traverse_all(struct btree_trans *trans,
struct btree_iter *orig_iter, int ret) struct btree_iter *orig_iter, int ret)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct btree_iter *iter; struct btree_iter *iter;
...@@ -1002,7 +1002,7 @@ static int __btree_iter_traverse_all(struct btree_trans *trans, ...@@ -1002,7 +1002,7 @@ static int __btree_iter_traverse_all(struct btree_trans *trans,
iter = &trans->iters[sorted[i]]; iter = &trans->iters[sorted[i]];
do { do {
ret = __bch2_btree_iter_traverse(iter); ret = btree_iter_traverse_one(iter);
} while (ret == -EINTR); } while (ret == -EINTR);
if (ret) if (ret)
...@@ -1047,7 +1047,7 @@ static unsigned btree_iter_up_until_locked(struct btree_iter *iter, ...@@ -1047,7 +1047,7 @@ static unsigned btree_iter_up_until_locked(struct btree_iter *iter,
* On error, caller (peek_node()/peek_key()) must return NULL; the error is * On error, caller (peek_node()/peek_key()) must return NULL; the error is
* stashed in the iterator and returned from bch2_trans_exit(). * stashed in the iterator and returned from bch2_trans_exit().
*/ */
int __must_check __bch2_btree_iter_traverse(struct btree_iter *iter) static int btree_iter_traverse_one(struct btree_iter *iter)
{ {
unsigned depth_want = iter->level; unsigned depth_want = iter->level;
...@@ -1099,12 +1099,12 @@ int __must_check __bch2_btree_iter_traverse(struct btree_iter *iter) ...@@ -1099,12 +1099,12 @@ int __must_check __bch2_btree_iter_traverse(struct btree_iter *iter)
return 0; return 0;
} }
int __must_check bch2_btree_iter_traverse(struct btree_iter *iter) int __must_check __bch2_btree_iter_traverse(struct btree_iter *iter)
{ {
int ret; int ret;
ret = bch2_trans_cond_resched(iter->trans) ?: ret = bch2_trans_cond_resched(iter->trans) ?:
__bch2_btree_iter_traverse(iter); btree_iter_traverse_one(iter);
if (unlikely(ret)) if (unlikely(ret))
ret = __btree_iter_traverse_all(iter->trans, iter, ret); ret = __btree_iter_traverse_all(iter->trans, iter, ret);
...@@ -1296,11 +1296,9 @@ struct bkey_s_c bch2_btree_iter_peek(struct btree_iter *iter) ...@@ -1296,11 +1296,9 @@ struct bkey_s_c bch2_btree_iter_peek(struct btree_iter *iter)
return btree_iter_peek_uptodate(iter); return btree_iter_peek_uptodate(iter);
while (1) { while (1) {
if (iter->uptodate >= BTREE_ITER_NEED_RELOCK) { ret = bch2_btree_iter_traverse(iter);
ret = bch2_btree_iter_traverse(iter); if (unlikely(ret))
if (unlikely(ret)) return bkey_s_c_err(ret);
return bkey_s_c_err(ret);
}
k = __btree_iter_peek(iter, l); k = __btree_iter_peek(iter, l);
if (likely(k.k)) if (likely(k.k))
...@@ -1564,11 +1562,9 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) ...@@ -1564,11 +1562,9 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
if (iter->uptodate == BTREE_ITER_UPTODATE) if (iter->uptodate == BTREE_ITER_UPTODATE)
return btree_iter_peek_uptodate(iter); return btree_iter_peek_uptodate(iter);
if (iter->uptodate >= BTREE_ITER_NEED_RELOCK) { ret = bch2_btree_iter_traverse(iter);
ret = bch2_btree_iter_traverse(iter); if (unlikely(ret))
if (unlikely(ret)) return bkey_s_c_err(ret);
return bkey_s_c_err(ret);
}
return __bch2_btree_iter_peek_slot(iter); return __bch2_btree_iter_peek_slot(iter);
} }
......
...@@ -134,7 +134,16 @@ void bch2_btree_iter_node_drop(struct btree_iter *, struct btree *); ...@@ -134,7 +134,16 @@ void bch2_btree_iter_node_drop(struct btree_iter *, struct btree *);
void bch2_btree_iter_reinit_node(struct btree_iter *, struct btree *); void bch2_btree_iter_reinit_node(struct btree_iter *, struct btree *);
int __must_check bch2_btree_iter_traverse(struct btree_iter *); int __must_check __bch2_btree_iter_traverse(struct btree_iter *);
static inline int __must_check
bch2_btree_iter_traverse(struct btree_iter *iter)
{
return iter->uptodate >= BTREE_ITER_NEED_RELOCK
? __bch2_btree_iter_traverse(iter)
: 0;
}
int bch2_btree_iter_traverse_all(struct btree_trans *); int bch2_btree_iter_traverse_all(struct btree_trans *);
struct btree *bch2_btree_iter_peek_node(struct btree_iter *); struct btree *bch2_btree_iter_peek_node(struct btree_iter *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment