From 4ca76de09f5ac2c9354df4effd4bcea41830eb47 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 4 Apr 2024 00:11:35 -0400 Subject: [PATCH] zygo: btrfs: prefer aligned dev_extent holes when allocating chunks (v4, handle last hole correctly when it is aligned) --- fs/btrfs/volumes.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5076156e77a6..f190f6a8dff6 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1745,6 +1745,17 @@ next: max_hole_start = search_start; max_hole_size = hole_size; } + + /* + * The last hole may be aligned and longer than any other, + * so do the aligned check and exit early again. + */ + if (hole_size >= num_bytes && (search_start & (SZ_1G - 1)) == SZ_1M) { + max_hole_start = search_start; + max_hole_size = hole_size; + ret = 0; + goto out; + } } /* See above. */ -- 2.39.5