summaryrefslogtreecommitdiff
path: root/fs/bcachefs/bset.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-08-05 22:34:03 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2019-04-03 12:43:20 -0400
commit3d9830fedb25c933a3aeea7cf9434859d5df747f (patch)
tree432183f0154e1fb414c1d6b87042f0937f9a0e04 /fs/bcachefs/bset.c
parent91af53fafbabb2356a8f9f9f64d005a649b0dc0c (diff)
bcachefs: improved rw_aux_tree_bsearch()
shouldn't be any reason for an actual binary search here
Diffstat (limited to 'fs/bcachefs/bset.c')
-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 2f2141e7f46c..1d39db1748a5 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 &&