diff options
-rw-r--r-- | fs/bcachefs/bkey.h | 31 | ||||
-rw-r--r-- | fs/bcachefs/btree_iter.c | 43 |
2 files changed, 21 insertions, 53 deletions
diff --git a/fs/bcachefs/bkey.h b/fs/bcachefs/bkey.h index 72b4267031d8..904ceb67a029 100644 --- a/fs/bcachefs/bkey.h +++ b/fs/bcachefs/bkey.h @@ -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 *); diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 06379f3e40a6..a856f5e90727 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -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; - - if (best) { - int cmp = bkey_cmp(bpos_diff(best->pos, pos), - bpos_diff(path->pos, pos)); + btree_trans_sort_paths(trans); - if (cmp < 0 || - ((cmp == 0 && (path->ref || path->preserve)))) - continue; - } + trans_for_each_path_inorder(trans, path, i) { + if (__btree_path_cmp(path, + btree_id, + cached, + pos, + level) > 0) + break; - 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; } |