Skip to content

Commit 4ede80a

Browse files
author
Kent Overstreet
committed
bcachefs: Allocator now copes with unaligned buckets
We had a buggy release of bcachefs-tools that wasn't properly aligning bucket sizes. We can't ask users to reformat - and it's easy to teach the allocator to make sure writes are properly aligned. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 387df33 commit 4ede80a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

fs/bcachefs/alloc_foreground.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,8 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
14251425
open_bucket_for_each(c, &wp->ptrs, ob, i)
14261426
wp->sectors_free = min(wp->sectors_free, ob->sectors_free);
14271427

1428+
wp->sectors_free = rounddown(wp->sectors_free, block_sectors(c));
1429+
14281430
BUG_ON(!wp->sectors_free || wp->sectors_free == UINT_MAX);
14291431

14301432
return 0;

fs/bcachefs/alloc_foreground.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ static inline void bch2_alloc_sectors_done_inlined(struct bch_fs *c, struct writ
110110
unsigned i;
111111

112112
open_bucket_for_each(c, &wp->ptrs, ob, i)
113-
ob_push(c, !ob->sectors_free ? &ptrs : &keep, ob);
113+
ob_push(c, ob->sectors_free < block_sectors(c)
114+
? &ptrs
115+
: &keep, ob);
114116
wp->ptrs = keep;
115117

116118
mutex_unlock(&wp->lock);

0 commit comments

Comments
 (0)