diff options
Diffstat (limited to 'libbcachefs/btree_update_interior.h')
-rw-r--r-- | libbcachefs/btree_update_interior.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libbcachefs/btree_update_interior.h b/libbcachefs/btree_update_interior.h index 3a17de5c..e6f05071 100644 --- a/libbcachefs/btree_update_interior.h +++ b/libbcachefs/btree_update_interior.h @@ -199,14 +199,17 @@ void bch2_btree_root_alloc(struct bch_fs *, enum btree_id); static inline unsigned btree_update_reserve_required(struct bch_fs *c, struct btree *b) { - unsigned depth = btree_node_root(c, b)->level - b->level + 1; + unsigned depth = btree_node_root(c, b)->level + 1; /* * Number of nodes we might have to allocate in a worst case btree * split operation - we split all the way up to the root, then allocate - * a new root. + * a new root, unless we're already at max depth: */ - return depth * 2 + 1; + if (depth < BTREE_MAX_DEPTH) + return (depth - b->level) * 2 + 1; + else + return (depth - b->level) * 2 - 1; } static inline void btree_node_reset_sib_u64s(struct btree *b) |