]> git.apps.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs: Reduce unnecessary searches when searching for the best extents
authorChi Zhiling <chizhiling@kylinos.cn>
Thu, 14 Nov 2024 23:53:23 +0000 (15:53 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:03:44 +0000 (16:03 -0800)
Source kernel commit: 3ef22684038aa577c10972ee9c6a2455f5fac941

Recently, we found that the CPU spent a lot of time in
xfs_alloc_ag_vextent_size when the filesystem has millions of fragmented
spaces.

The reason is that we conducted much extra searching for extents that
could not yield a better result, and these searches would cost a lot of
time when there were millions of extents to search through. Even if we
get the same result length, we don't switch our choice to the new one,
so we can definitely terminate the search early.

Since the result length cannot exceed the found length, when the found
length equals the best result length we already have, we can conclude
the search.

We did a test in that filesystem:
[root@localhost ~]# xfs_db -c freesp /dev/vdb
from      to extents  blocks    pct
1       1     215     215   0.01
2       3  994476 1988952  99.99

Before this patch:
0)               |  xfs_alloc_ag_vextent_size [xfs]() {
0) * 15597.94 us |  }

After this patch:
0)               |  xfs_alloc_ag_vextent_size [xfs]() {
0)   19.176 us    |  }

Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_alloc.c

index 61453709ae515cf54075df85f081cdb296181671..f0635b17f18548d97cb097f7ae46d80f4f32b2eb 100644 (file)
@@ -1919,7 +1919,7 @@ restart:
                                error = -EFSCORRUPTED;
                                goto error0;
                        }
-                       if (flen < bestrlen)
+                       if (flen <= bestrlen)
                                break;
                        busy = xfs_alloc_compute_aligned(args, fbno, flen,
                                        &rbno, &rlen, &busy_gen);