Commit e0ba3b64 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Replace bch2_btree_iter_next() calls with bch2_btree_iter_advance

The way btree iterators work internally has been changing, particularly
with the iter->real_pos changes, and bch2_btree_iter_next() is no longer
hyper optimized - it's just advance followed by peek, so it's more
efficient to just call advance where we're not using the return value of
bch2_btree_iter_next().
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent cb16bfaa
...@@ -1208,7 +1208,7 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id) ...@@ -1208,7 +1208,7 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id)
} }
} }
bch2_btree_iter_next(iter); bch2_btree_iter_advance(iter);
} }
bch2_trans_iter_put(&trans, iter); bch2_trans_iter_put(&trans, iter);
......
...@@ -1501,7 +1501,7 @@ void bch2_btree_iter_set_pos(struct btree_iter *iter, struct bpos new_pos) ...@@ -1501,7 +1501,7 @@ void bch2_btree_iter_set_pos(struct btree_iter *iter, struct bpos new_pos)
btree_iter_set_search_pos(iter, btree_iter_search_key(iter)); btree_iter_set_search_pos(iter, btree_iter_search_key(iter));
} }
inline bool bch2_btree_iter_advance_pos(struct btree_iter *iter) inline bool bch2_btree_iter_advance(struct btree_iter *iter)
{ {
struct bpos pos = iter->k.p; struct bpos pos = iter->k.p;
bool ret = bkey_cmp(pos, POS_MAX) != 0; bool ret = bkey_cmp(pos, POS_MAX) != 0;
...@@ -1512,7 +1512,7 @@ inline bool bch2_btree_iter_advance_pos(struct btree_iter *iter) ...@@ -1512,7 +1512,7 @@ inline bool bch2_btree_iter_advance_pos(struct btree_iter *iter)
return ret; return ret;
} }
inline bool bch2_btree_iter_rewind_pos(struct btree_iter *iter) inline bool bch2_btree_iter_rewind(struct btree_iter *iter)
{ {
struct bpos pos = bkey_start_pos(&iter->k); struct bpos pos = bkey_start_pos(&iter->k);
bool ret = bkey_cmp(pos, POS_MIN) != 0; bool ret = bkey_cmp(pos, POS_MIN) != 0;
...@@ -1637,7 +1637,7 @@ struct bkey_s_c bch2_btree_iter_peek(struct btree_iter *iter) ...@@ -1637,7 +1637,7 @@ struct bkey_s_c bch2_btree_iter_peek(struct btree_iter *iter)
*/ */
struct bkey_s_c bch2_btree_iter_next(struct btree_iter *iter) struct bkey_s_c bch2_btree_iter_next(struct btree_iter *iter)
{ {
if (!bch2_btree_iter_advance_pos(iter)) if (!bch2_btree_iter_advance(iter))
return bkey_s_c_null; return bkey_s_c_null;
return bch2_btree_iter_peek(iter); return bch2_btree_iter_peek(iter);
...@@ -1691,7 +1691,7 @@ struct bkey_s_c bch2_btree_iter_peek_with_updates(struct btree_iter *iter) ...@@ -1691,7 +1691,7 @@ struct bkey_s_c bch2_btree_iter_peek_with_updates(struct btree_iter *iter)
k = __bch2_btree_iter_peek_with_updates(iter); k = __bch2_btree_iter_peek_with_updates(iter);
if (k.k && bkey_deleted(k.k)) { if (k.k && bkey_deleted(k.k)) {
if (!bch2_btree_iter_advance_pos(iter)) if (!bch2_btree_iter_advance(iter))
return bkey_s_c_null; return bkey_s_c_null;
continue; continue;
} }
...@@ -1716,7 +1716,7 @@ struct bkey_s_c bch2_btree_iter_peek_with_updates(struct btree_iter *iter) ...@@ -1716,7 +1716,7 @@ struct bkey_s_c bch2_btree_iter_peek_with_updates(struct btree_iter *iter)
struct bkey_s_c bch2_btree_iter_next_with_updates(struct btree_iter *iter) struct bkey_s_c bch2_btree_iter_next_with_updates(struct btree_iter *iter)
{ {
if (!bch2_btree_iter_advance_pos(iter)) if (!bch2_btree_iter_advance(iter))
return bkey_s_c_null; return bkey_s_c_null;
return bch2_btree_iter_peek_with_updates(iter); return bch2_btree_iter_peek_with_updates(iter);
...@@ -1793,7 +1793,7 @@ struct bkey_s_c bch2_btree_iter_peek_prev(struct btree_iter *iter) ...@@ -1793,7 +1793,7 @@ struct bkey_s_c bch2_btree_iter_peek_prev(struct btree_iter *iter)
*/ */
struct bkey_s_c bch2_btree_iter_prev(struct btree_iter *iter) struct bkey_s_c bch2_btree_iter_prev(struct btree_iter *iter)
{ {
if (!bch2_btree_iter_rewind_pos(iter)) if (!bch2_btree_iter_rewind(iter))
return bkey_s_c_null; return bkey_s_c_null;
return bch2_btree_iter_peek_prev(iter); return bch2_btree_iter_peek_prev(iter);
...@@ -1885,7 +1885,7 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) ...@@ -1885,7 +1885,7 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
struct bkey_s_c bch2_btree_iter_next_slot(struct btree_iter *iter) struct bkey_s_c bch2_btree_iter_next_slot(struct btree_iter *iter)
{ {
if (!bch2_btree_iter_advance_pos(iter)) if (!bch2_btree_iter_advance(iter))
return bkey_s_c_null; return bkey_s_c_null;
return bch2_btree_iter_peek_slot(iter); return bch2_btree_iter_peek_slot(iter);
...@@ -1893,7 +1893,7 @@ struct bkey_s_c bch2_btree_iter_next_slot(struct btree_iter *iter) ...@@ -1893,7 +1893,7 @@ struct bkey_s_c bch2_btree_iter_next_slot(struct btree_iter *iter)
struct bkey_s_c bch2_btree_iter_prev_slot(struct btree_iter *iter) struct bkey_s_c bch2_btree_iter_prev_slot(struct btree_iter *iter)
{ {
if (!bch2_btree_iter_rewind_pos(iter)) if (!bch2_btree_iter_rewind(iter))
return bkey_s_c_null; return bkey_s_c_null;
return bch2_btree_iter_peek_slot(iter); return bch2_btree_iter_peek_slot(iter);
......
...@@ -175,8 +175,8 @@ struct bkey_s_c bch2_btree_iter_prev_slot(struct btree_iter *); ...@@ -175,8 +175,8 @@ struct bkey_s_c bch2_btree_iter_prev_slot(struct btree_iter *);
struct bkey_s_c bch2_btree_iter_peek_cached(struct btree_iter *); struct bkey_s_c bch2_btree_iter_peek_cached(struct btree_iter *);
bool bch2_btree_iter_advance_pos(struct btree_iter *); bool bch2_btree_iter_advance(struct btree_iter *);
bool bch2_btree_iter_rewind_pos(struct btree_iter *); bool bch2_btree_iter_rewind(struct btree_iter *);
void bch2_btree_iter_set_pos(struct btree_iter *, struct bpos); void bch2_btree_iter_set_pos(struct btree_iter *, struct bpos);
/* Sort order for locking btree iterators: */ /* Sort order for locking btree iterators: */
......
...@@ -356,7 +356,7 @@ static ssize_t bch2_read_bfloat_failed(struct file *file, char __user *buf, ...@@ -356,7 +356,7 @@ static ssize_t bch2_read_bfloat_failed(struct file *file, char __user *buf,
if (err) if (err)
break; break;
bch2_btree_iter_next(iter); bch2_btree_iter_advance(iter);
i->from = iter->pos; i->from = iter->pos;
err = flush_buf(i); err = flush_buf(i);
......
...@@ -842,13 +842,13 @@ static int ec_stripe_update_ptrs(struct bch_fs *c, ...@@ -842,13 +842,13 @@ static int ec_stripe_update_ptrs(struct bch_fs *c,
struct bch_extent_ptr *ptr, *ec_ptr = NULL; struct bch_extent_ptr *ptr, *ec_ptr = NULL;
if (extent_has_stripe_ptr(k, s->key.k.p.offset)) { if (extent_has_stripe_ptr(k, s->key.k.p.offset)) {
bch2_btree_iter_next(iter); bch2_btree_iter_advance(iter);
continue; continue;
} }
block = bkey_matches_stripe(&s->key.v, k); block = bkey_matches_stripe(&s->key.v, k);
if (block < 0) { if (block < 0) {
bch2_btree_iter_next(iter); bch2_btree_iter_advance(iter);
continue; continue;
} }
......
...@@ -914,7 +914,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info, ...@@ -914,7 +914,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
if (!bkey_extent_is_data(k.k) && if (!bkey_extent_is_data(k.k) &&
k.k->type != KEY_TYPE_reservation) { k.k->type != KEY_TYPE_reservation) {
bch2_btree_iter_next(iter); bch2_btree_iter_advance(iter);
continue; continue;
} }
......
...@@ -547,7 +547,7 @@ static int check_extents(struct bch_fs *c) ...@@ -547,7 +547,7 @@ static int check_extents(struct bch_fs *c)
i_sectors += k.k->size; i_sectors += k.k->size;
bch2_bkey_buf_reassemble(&prev, c, k); bch2_bkey_buf_reassemble(&prev, c, k);
bch2_btree_iter_advance_pos(iter); bch2_btree_iter_advance(iter);
} }
fsck_err: fsck_err:
if (ret == -EINTR) if (ret == -EINTR)
...@@ -703,7 +703,7 @@ static int check_dirents(struct bch_fs *c) ...@@ -703,7 +703,7 @@ static int check_dirents(struct bch_fs *c)
} }
bch2_btree_iter_advance_pos(iter); bch2_btree_iter_advance(iter);
} }
hash_stop_chain(&trans, &h); hash_stop_chain(&trans, &h);
...@@ -762,7 +762,7 @@ static int check_xattrs(struct bch_fs *c) ...@@ -762,7 +762,7 @@ static int check_xattrs(struct bch_fs *c)
if (ret) if (ret)
break; break;
bch2_btree_iter_advance_pos(iter); bch2_btree_iter_advance(iter);
} }
fsck_err: fsck_err:
if (ret == -EINTR) if (ret == -EINTR)
...@@ -1389,7 +1389,7 @@ peek_nlinks: link = genradix_iter_peek(&nlinks_iter, links); ...@@ -1389,7 +1389,7 @@ peek_nlinks: link = genradix_iter_peek(&nlinks_iter, links);
if (nlinks_pos == iter->pos.offset) if (nlinks_pos == iter->pos.offset)
genradix_iter_advance(&nlinks_iter, links); genradix_iter_advance(&nlinks_iter, links);
bch2_btree_iter_advance_pos(iter); bch2_btree_iter_advance(iter);
bch2_trans_cond_resched(&trans); bch2_trans_cond_resched(&trans);
} }
fsck_err: fsck_err:
......
...@@ -53,7 +53,7 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags ...@@ -53,7 +53,7 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags
while ((k = bch2_btree_iter_peek(iter)).k && while ((k = bch2_btree_iter_peek(iter)).k &&
!(ret = bkey_err(k))) { !(ret = bkey_err(k))) {
if (!bch2_bkey_has_device(k, dev_idx)) { if (!bch2_bkey_has_device(k, dev_idx)) {
bch2_btree_iter_next(iter); bch2_btree_iter_advance(iter);
continue; continue;
} }
......
...@@ -638,7 +638,7 @@ static int __bch2_move_data(struct bch_fs *c, ...@@ -638,7 +638,7 @@ static int __bch2_move_data(struct bch_fs *c,
atomic64_add(k.k->size * bch2_bkey_nr_ptrs_allocated(k), atomic64_add(k.k->size * bch2_bkey_nr_ptrs_allocated(k),
&stats->sectors_seen); &stats->sectors_seen);
next_nondata: next_nondata:
bch2_btree_iter_next(iter); bch2_btree_iter_advance(iter);
bch2_trans_cond_resched(&trans); bch2_trans_cond_resched(&trans);
} }
out: out:
......
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