Skip to content

Commit 9f734cd

Browse files
author
Kent Overstreet
committed
bcachefs: Fix want_new_bset() so we write until the end of the btree node
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>
1 parent 1e690ef commit 9f734cd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/bcachefs/btree_update_interior.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ static inline struct btree_node_entry *want_new_bset(struct bch_fs *c, struct bt
278278
{
279279
struct bset_tree *t = bset_tree_last(b);
280280
struct btree_node_entry *bne = max(write_block(b),
281-
(void *) btree_bkey_last(b, bset_tree_last(b)));
281+
(void *) btree_bkey_last(b, t));
282282
ssize_t remaining_space =
283283
__bch2_btree_u64s_remaining(b, bne->keys.start);
284284

285285
if (unlikely(bset_written(b, bset(b, t)))) {
286-
if (remaining_space > (ssize_t) (block_bytes(c) >> 3))
286+
if (b->written + block_sectors(c) <= btree_sectors(c))
287287
return bne;
288288
} else {
289289
if (unlikely(bset_u64s(t) * sizeof(u64) > btree_write_set_buffer(b)) &&

0 commit comments

Comments
 (0)