]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
bcachefs: Fix want_new_bset() so we write until the end of the btree node
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 10 Feb 2025 22:46:36 +0000 (17:46 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 11 Feb 2025 15:10:32 +0000 (10:10 -0500)
want_new_bset() returns the address of a new bset to initialize if we
wish to do so in a btree node - either because the previous one is too
big, or because it's been written.

The case for 'previous bset was written' was wrong: it's only supposed
to check for if we have space in the node for one more block, but
because it subtracted the header from the space available it would never
initialize a new bset if we were down to the last block in a node.

Fixing this results in fewer btree node splits/compactions, which fixes
a bug with flushing the journal to go read-only sometimes not
terminating or taking excessively long.

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

index 7930ffea3075dc20d7394158e5ae421658f02376..26d646e1275c070e86c5e3fd24eb3bdfa5ae0086 100644 (file)
@@ -278,12 +278,12 @@ static inline struct btree_node_entry *want_new_bset(struct bch_fs *c, struct bt
 {
        struct bset_tree *t = bset_tree_last(b);
        struct btree_node_entry *bne = max(write_block(b),
-                       (void *) btree_bkey_last(b, bset_tree_last(b)));
+                       (void *) btree_bkey_last(b, t));
        ssize_t remaining_space =
                __bch2_btree_u64s_remaining(b, bne->keys.start);
 
        if (unlikely(bset_written(b, bset(b, t)))) {
-               if (remaining_space > (ssize_t) (block_bytes(c) >> 3))
+               if (b->written + block_sectors(c) <= btree_sectors(c))
                        return bne;
        } else {
                if (unlikely(bset_u64s(t) * sizeof(u64) > btree_write_set_buffer(b)) &&