bcachefs: Change btree split threshold to be in u64s
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 15 Jan 2020 20:11:22 +0000 (15:11 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:34 +0000 (17:08 -0400)
This fixes a bug with very small btree nodes where splitting would end
up with one of the new nodes empty.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_cache.h
fs/bcachefs/btree_update_interior.c

index 4598a4c57aa14827986a1ec1abe62fa5d3d219ba..adacb0a067036b5aac6fbc292667689e8518761f 100644 (file)
@@ -75,7 +75,7 @@ static inline unsigned btree_blocks(struct bch_fs *c)
        return c->opts.btree_node_size >> c->block_bits;
 }
 
-#define BTREE_SPLIT_THRESHOLD(c)               (btree_blocks(c) * 3 / 4)
+#define BTREE_SPLIT_THRESHOLD(c)               (btree_max_u64s(c) * 3 / 4)
 
 #define BTREE_FOREGROUND_MERGE_THRESHOLD(c)    (btree_max_u64s(c) * 1 / 3)
 #define BTREE_FOREGROUND_MERGE_HYSTERESIS(c)                   \
index cb7566bbc1fcd5bb88f052fa2685b6682c3a16bd..713f2d41e6c993e126acd7c5325e7560e05f8767 100644 (file)
@@ -1385,7 +1385,7 @@ static void btree_split(struct btree_update *as, struct btree *b,
        if (keys)
                btree_split_insert_keys(as, n1, iter, keys);
 
-       if (vstruct_blocks(n1->data, c->block_bits) > BTREE_SPLIT_THRESHOLD(c)) {
+       if (bset_u64s(&n1->set[0]) > BTREE_SPLIT_THRESHOLD(c)) {
                trace_btree_split(c, b);
 
                n2 = __btree_split_node(as, n1, iter);