]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Allocator now copes with unaligned buckets
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 21 Apr 2025 22:37:12 +0000 (18:37 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 21 Apr 2025 23:36:45 +0000 (19:36 -0400)
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 <kent.overstreet@linux.dev>
fs/bcachefs/alloc_foreground.c
fs/bcachefs/alloc_foreground.h

index 7c930ef7738040549c00afe1d23ede99e8fb47ce..effafc3e0ced44a6d138dad20bc02d051c21075d 100644 (file)
@@ -1425,6 +1425,8 @@ alloc_done:
        open_bucket_for_each(c, &wp->ptrs, ob, i)
                wp->sectors_free = min(wp->sectors_free, ob->sectors_free);
 
+       wp->sectors_free = rounddown(wp->sectors_free, block_sectors(c));
+
        BUG_ON(!wp->sectors_free || wp->sectors_free == UINT_MAX);
 
        return 0;
index 69ec6a012898e6efeebe7b89a5f28d793cf6761b..4c1e33cf57c03b775c6ee1d712972ddcda1c314f 100644 (file)
@@ -110,7 +110,9 @@ static inline void bch2_alloc_sectors_done_inlined(struct bch_fs *c, struct writ
        unsigned i;
 
        open_bucket_for_each(c, &wp->ptrs, ob, i)
-               ob_push(c, !ob->sectors_free ? &ptrs : &keep, ob);
+               ob_push(c, ob->sectors_free < block_sectors(c)
+                       ? &ptrs
+                       : &keep, ob);
        wp->ptrs = keep;
 
        mutex_unlock(&wp->lock);