diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-12-10 23:10:31 +0100 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-01 17:47:44 +0100 |
commit | 2c3b0fc3bd0a5db0d10260b08a7139fdb7a4d3a8 (patch) | |
tree | 6509856c9743484aea1bc2a5455137d70b8734d7 /fs/bcachefs/btree_iter.h | |
parent | bcachefs: trans->updates will also be resizable (diff) | |
download | linux-2c3b0fc3bd0a5db0d10260b08a7139fdb7a4d3a8.tar.xz linux-2c3b0fc3bd0a5db0d10260b08a7139fdb7a4d3a8.zip |
bcachefs: trans->nr_paths
Start to plumb through dynamically growable btree_paths; this patch
replaces most BTREE_ITER_MAX references with trans->nr_paths.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/btree_iter.h')
-rw-r--r-- | fs/bcachefs/btree_iter.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index 0fab4952f9f7..573c44d80cc3 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -82,9 +82,25 @@ static inline unsigned long *trans_paths_allocated(struct btree_path *paths) static inline struct btree_path * __trans_next_path(struct btree_trans *trans, unsigned *idx) { - *idx = find_next_bit(trans->paths_allocated, BTREE_ITER_MAX, *idx); + unsigned long *w = trans->paths_allocated + *idx / BITS_PER_LONG; + /* + * Open coded find_next_bit(), because + * - this is fast path, we can't afford the function call + * - and we know that nr_paths is a multiple of BITS_PER_LONG, + */ + while (*idx < trans->nr_paths) { + unsigned long v = *w >> (*idx & (BITS_PER_LONG - 1)); + if (v) { + *idx += __ffs(v); + return trans->paths + *idx; + } + + *idx += BITS_PER_LONG; + *idx &= ~(BITS_PER_LONG - 1); + w++; + } - return *idx < BTREE_ITER_MAX ? &trans->paths[*idx] : NULL; + return NULL; } /* @@ -626,7 +642,7 @@ int __bch2_btree_trans_too_many_iters(struct btree_trans *); static inline int btree_trans_too_many_iters(struct btree_trans *trans) { - if (bitmap_weight(trans->paths_allocated, BTREE_ITER_MAX) > BTREE_ITER_MAX - 8) + if (bitmap_weight(trans->paths_allocated, trans->nr_paths) > BTREE_ITER_MAX - 8) return __bch2_btree_trans_too_many_iters(trans); return 0; |