summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-08-05 22:34:03 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2018-08-08 15:19:45 -0400
commit5cd3e0785bdcb8b1743710d68cc9402af22ba464 (patch)
tree91c63f91093f60b626006381402f1daddc21a6b9
parente7a00a52b57336c04d1043c6fa0a67a7c8301cfb (diff)
bcachefs: improved rw_aux_tree_bsearch()
shouldn't be any reason for an actual binary search here
-rw-r--r--fs/bcachefs/bset.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/fs/bcachefs/bset.c b/fs/bcachefs/bset.c
index 8c77fc509b55..358ac1f3810b 100644
--- a/fs/bcachefs/bset.c
+++ b/fs/bcachefs/bset.c
@@ -622,28 +622,30 @@ static unsigned rw_aux_tree_bsearch(struct btree *b,
struct bset_tree *t,
unsigned offset)
{
- unsigned l = 0, r = t->size;
+ unsigned bset_offs = offset - btree_bkey_first_offset(t);
+ unsigned bset_u64s = t->end_offset - btree_bkey_first_offset(t);
+ unsigned idx = bset_u64s ? bset_offs * t->size / bset_u64s : 0;
EBUG_ON(bset_aux_tree_type(t) != BSET_RW_AUX_TREE);
+ EBUG_ON(!t->size);
+ EBUG_ON(idx > t->size);
- while (l < r) {
- unsigned m = (l + r) >> 1;
+ while (idx < t->size &&
+ rw_aux_tree(b, t)[idx].offset < offset)
+ idx++;
- if (rw_aux_tree(b, t)[m].offset < offset)
- l = m + 1;
- else
- r = m;
- }
+ while (idx &&
+ rw_aux_tree(b, t)[idx - 1].offset >= offset)
+ idx--;
- EBUG_ON(l < t->size &&
- rw_aux_tree(b, t)[l].offset < offset);
- EBUG_ON(l &&
- rw_aux_tree(b, t)[l - 1].offset >= offset);
-
- EBUG_ON(l > r);
- EBUG_ON(l > t->size);
+ EBUG_ON(idx < t->size &&
+ rw_aux_tree(b, t)[idx].offset < offset);
+ EBUG_ON(idx && rw_aux_tree(b, t)[idx - 1].offset >= offset);
+ EBUG_ON(idx + 1 < t->size &&
+ rw_aux_tree(b, t)[idx].offset ==
+ rw_aux_tree(b, t)[idx + 1].offset);
- return l;
+ return idx;
}
static inline unsigned bfloat_mantissa(const struct bkey_float *f,
@@ -1158,13 +1160,9 @@ static void bch2_bset_fix_lookup_table(struct btree *b,
if (!bset_has_rw_aux_tree(t))
return;
+ /* returns first entry >= where */
l = rw_aux_tree_bsearch(b, t, where);
- /* l is first >= than @where */
-
- EBUG_ON(l < t->size && rw_aux_tree(b, t)[l].offset < where);
- EBUG_ON(l && rw_aux_tree(b, t)[l - 1].offset >= where);
-
if (!l) /* never delete first entry */
l++;
else if (l < t->size &&