From 825cb15cd8a02a083042cc6fa12767ec1805f92d Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Mon, 4 Mar 2024 02:51:00 -0500 Subject: [PATCH] zygo: btrfs: prefer aligned dev_extent holes when allocating chunks (v3, handle last hole correctly) --- fs/btrfs/volumes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1de26a61ca13..4985407db76c 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1737,7 +1737,11 @@ next: goto again; } - if (hole_size > max_hole_size) { + /* + * If this is a larger hole it might not be aligned. + * Keep the hole we found above if it was large enough. + */ + if (hole_size > max_hole_size && max_hole_size < num_bytes) { max_hole_start = search_start; max_hole_size = hole_size; } -- 2.39.5