]> git.hungrycats.org Git - linux/commitdiff
zygo: btrfs: prefer aligned dev_extent holes when allocating chunks (v2, right end...
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 14 Feb 2024 05:10:23 +0000 (00:10 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 15 Feb 2024 22:27:51 +0000 (17:27 -0500)
fs/btrfs/volumes.c

index 20ebe22592b41513e169172d1e88d538a240694c..1de26a61ca13165f731ce4f0850916cd905581bf 100644 (file)
@@ -1690,21 +1690,25 @@ again:
                        dev_extent_hole_check(device, &search_start, &hole_size,
                                              num_bytes);
 
-                       if (hole_size > max_hole_size) {
+                       /*
+                        * Once we find a hole of sufficient size we
+                        * ignore any larger holes that may appear at
+                        * higher device offsets.  If we later find a
+                        * hole that is sufficiently large, but aligned,
+                        * we'll use that instead.
+                        */
+                       if (hole_size > max_hole_size && max_hole_size < num_bytes) {
                                max_hole_start = search_start;
                                max_hole_size = hole_size;
                        }
 
                        /*
-                        * If this free space is greater than which we need,
-                        * it must be the max free space that we have found
-                        * until now, so max_hole_start must point to the start
-                        * of this free space and the length of this free space
-                        * is stored in max_hole_size. Thus, we return
-                        * max_hole_start and max_hole_size and go back to the
-                        * caller.
+                        * If we find a hole that is aligned and as large
+                        * as we need, then exit early with that hole.
                         */
-                       if (hole_size >= num_bytes) {
+                       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;
                        }