summaryrefslogtreecommitdiff
path: root/fs/bcachefs/btree_iter.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-12-04 00:20:42 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-01-01 11:47:40 -0500
commit6e92d15546944d9e2af8e7248a3a399dbd6fce0e (patch)
treeda6c9b7ca99884f098ac1fb9a09d1c27c88b9187 /fs/bcachefs/btree_iter.h
parent0d963a635d20a3a48e5a1b12e91925f868f5f9de (diff)
bcachefs: Refactor trans->paths_allocated to be standard bitmap
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/btree_iter.h')
-rw-r--r--fs/bcachefs/btree_iter.h23
1 files changed, 5 insertions, 18 deletions
diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h
index 3859c0b27d2b..2a657205572a 100644
--- a/fs/bcachefs/btree_iter.h
+++ b/fs/bcachefs/btree_iter.h
@@ -66,17 +66,10 @@ static inline void btree_trans_sort_paths(struct btree_trans *trans)
static inline struct btree_path *
__trans_next_path(struct btree_trans *trans, unsigned idx)
{
- u64 l;
-
+ idx = find_next_bit(trans->paths_allocated, BTREE_ITER_MAX, idx);
if (idx == BTREE_ITER_MAX)
return NULL;
-
- l = trans->paths_allocated >> idx;
- if (!l)
- return NULL;
-
- idx += __ffs64(l);
- EBUG_ON(idx >= BTREE_ITER_MAX);
+ EBUG_ON(idx > BTREE_ITER_MAX);
EBUG_ON(trans->paths[idx].idx != idx);
return &trans->paths[idx];
}
@@ -92,17 +85,11 @@ __trans_next_path(struct btree_trans *trans, unsigned idx)
static inline struct btree_path *
__trans_next_path_safe(struct btree_trans *trans, unsigned *idx)
{
- u64 l;
-
+ *idx = find_next_bit(trans->paths_allocated, BTREE_ITER_MAX, *idx);
if (*idx == BTREE_ITER_MAX)
return NULL;
- l = trans->paths_allocated >> *idx;
- if (!l)
- return NULL;
-
- *idx += __ffs64(l);
- EBUG_ON(*idx >= BTREE_ITER_MAX);
+ EBUG_ON(*idx > BTREE_ITER_MAX);
return &trans->paths[*idx];
}
@@ -631,7 +618,7 @@ int __bch2_btree_trans_too_many_iters(struct btree_trans *);
static inline int btree_trans_too_many_iters(struct btree_trans *trans)
{
- if (hweight64(trans->paths_allocated) > BTREE_ITER_MAX - 8)
+ if (bitmap_weight(trans->paths_allocated, BTREE_ITER_MAX) > BTREE_ITER_MAX - 8)
return __bch2_btree_trans_too_many_iters(trans);
return 0;