diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-12-17 00:57:37 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-01 11:47:44 -0500 |
commit | eb6863598a9dff88bdb4483cc09a3ec8e1150b48 (patch) | |
tree | 9a0c38c706b2fe95a5885299b71ddb9e1fb0e706 /fs/bcachefs/btree_iter.c | |
parent | 0c99e17d3bd3b60ee7461cb8e87ff6badf228422 (diff) | |
download | linux-stable-eb6863598a9dff88bdb4483cc09a3ec8e1150b48.tar.gz linux-stable-eb6863598a9dff88bdb4483cc09a3ec8e1150b48.tar.bz2 linux-stable-eb6863598a9dff88bdb4483cc09a3ec8e1150b48.zip |
bcachefs: bch2_btree_trans_peek_updates
refactoring the BTREE_ITER_WITH_UPDATES code, prep for removing the flag
and making it always-on
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/btree_iter.c')
-rw-r--r-- | fs/bcachefs/btree_iter.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 596fbb9a611f..1d2be541d5a2 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -1888,6 +1888,23 @@ inline bool bch2_btree_iter_rewind(struct btree_iter *iter) } static noinline +void bch2_btree_trans_peek_updates(struct btree_trans *trans, struct btree_iter *iter, + struct bkey_s_c *k) +{ + struct btree_path *path = btree_iter_path(trans, iter); + struct bpos end = path_l(path)->b->key.k.p; + + trans_for_each_update(trans, i) + if (!i->key_cache_already_flushed && + i->btree_id == iter->btree_id && + bpos_ge(i->k->k.p, path->pos) && + bpos_le(i->k->k.p, k->k ? k->k->p : end)) { + iter->k = i->k->k; + *k = bkey_i_to_s_c(i->k); + } +} + +static noinline struct bkey_i *__bch2_btree_trans_peek_updates(struct btree_iter *iter) { struct btree_trans *trans = iter->trans; @@ -2012,7 +2029,6 @@ struct bkey_s_c btree_trans_peek_key_cache(struct btree_iter *iter, struct bpos static struct bkey_s_c __bch2_btree_iter_peek(struct btree_iter *iter, struct bpos search_key) { struct btree_trans *trans = iter->trans; - struct bkey_i *next_update; struct bkey_s_c k, k2; int ret; @@ -2062,14 +2078,9 @@ static struct bkey_s_c __bch2_btree_iter_peek(struct btree_iter *iter, struct bp if (unlikely(iter->flags & BTREE_ITER_WITH_JOURNAL)) k = btree_trans_peek_journal(trans, iter, k); - next_update = btree_trans_peek_updates(iter); - - if (next_update && - bpos_le(next_update->k.p, - k.k ? k.k->p : l->b->key.k.p)) { - iter->k = next_update->k; - k = bkey_i_to_s_c(next_update); - } + if (unlikely((iter->flags & BTREE_ITER_WITH_UPDATES) && + trans->nr_updates)) + bch2_btree_trans_peek_updates(trans, iter, &k); if (k.k && bkey_deleted(k.k)) { /* |