bcachefs: Kill bpos_diff() XXX check for perf regression

This improves the btree iterator lookup code by using
trans_for_each_iter_inorder().

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2021-08-30 15:18:31 -04:00 committed by Kent Overstreet
parent 67e0dd8f0d
commit 807dda8c83
2 changed files with 21 additions and 53 deletions

View File

@ -171,37 +171,6 @@ static inline struct bpos bpos_max(struct bpos l, struct bpos r)
return bpos_cmp(l, r) > 0 ? l : r;
}
#define sbb(a, b, borrow) \
do { \
typeof(a) d1, d2; \
\
d1 = a - borrow; \
borrow = d1 > a; \
\
d2 = d1 - b; \
borrow += d2 > d1; \
a = d2; \
} while (0)
/* returns a - b: */
static inline struct bpos bpos_sub(struct bpos a, struct bpos b)
{
int borrow = 0;
sbb(a.snapshot, b.snapshot, borrow);
sbb(a.offset, b.offset, borrow);
sbb(a.inode, b.inode, borrow);
return a;
}
static inline struct bpos bpos_diff(struct bpos l, struct bpos r)
{
if (bpos_cmp(l, r) > 0)
swap(l, r);
return bpos_sub(r, l);
}
void bch2_bpos_swab(struct bpos *);
void bch2_bkey_swab_key(const struct bkey_format *, struct bkey_packed *);

View File

@ -1739,36 +1739,35 @@ struct btree_path *bch2_path_get(struct btree_trans *trans, bool cached,
unsigned locks_want, unsigned level,
bool intent)
{
struct btree_path *path, *best = NULL;
struct btree_path *path, *path_pos = NULL;
struct bpos pos_min = POS_MIN;
int i;
BUG_ON(trans->restarted);
trans_for_each_path(trans, path) {
if (path->cached != cached ||
path->btree_id != btree_id ||
path->level != level)
continue;
btree_trans_sort_paths(trans);
if (best) {
int cmp = bkey_cmp(bpos_diff(best->pos, pos),
bpos_diff(path->pos, pos));
trans_for_each_path_inorder(trans, path, i) {
if (__btree_path_cmp(path,
btree_id,
cached,
pos,
level) > 0)
break;
if (cmp < 0 ||
((cmp == 0 && (path->ref || path->preserve))))
continue;
}
best = path;
path_pos = path;
}
if (best) {
__btree_path_get(best, intent);
path = btree_path_set_pos(trans, best, pos, intent);
if (path_pos &&
path_pos->cached == cached &&
path_pos->btree_id == btree_id &&
path_pos->level == level) {
__btree_path_get(path_pos, intent);
path = btree_path_set_pos(trans, path_pos, pos, intent);
path->preserve = true;
} else {
path = btree_path_alloc(trans, NULL);
path = btree_path_alloc(trans, path_pos);
path_pos = NULL;
__btree_path_get(path, intent);
path->pos = pos;
@ -1808,9 +1807,9 @@ struct btree_path *bch2_path_get(struct btree_trans *trans, bool cached,
trace_trans_get_path(_RET_IP_, trans->ip, btree_id,
&pos, locks_want, path->uptodate,
best ? &best->pos : &pos_min,
best ? best->locks_want : U8_MAX,
best ? best->uptodate : U8_MAX);
path_pos ? &path_pos->pos : &pos_min,
path_pos ? path_pos->locks_want : U8_MAX,
path_pos ? path_pos->uptodate : U8_MAX);
return path;
}