]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: reduce excessive clamping of maxlen in xfs_rtallocate_extent_near
authorDarrick J. Wong <djwong@kernel.org>
Fri, 30 Aug 2024 22:37:05 +0000 (15:37 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Sun, 1 Sep 2024 15:58:19 +0000 (08:58 -0700)
The near rt allocator employs two allocation strategies -- first it
tries to allocate at exactly @start.  If that fails, it will pivot back
and forth around that starting point looking for an appropriately sized
free space.

However, I clamped maxlen ages ago to prevent the exact allocation scan
from running off the end of the rt volume.  This, I realize, was
excessive.  If the allocation request is (say) for 32 rtx but the start
position is 5 rtx from the end of the volume, we clamp maxlen to 5.  If
the exact allocation fails, we then pivot back and forth looking for 5
rtx, even though the original intent was to try to get 32 rtx.

If we then find 5 rtx when we could have gotten 32 rtx, we've not done
as well as we could have.  This may be moot if the caller immediately
comes back for more space, but it might not be.  Either way, we can do
better here.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_rtalloc.c

index af357704895d79ca2d88b90a773604863211df46..d27bfec08ef80d0d34f2f5d64615b2a19ef9730e 100644 (file)
@@ -338,23 +338,29 @@ xfs_rtallocate_extent_exact(
        xfs_rtxlen_t            prod,   /* extent product factor */
        xfs_rtxnum_t            *rtx)   /* out: start rtext allocated */
 {
+       struct xfs_mount        *mp = args->mp;
        xfs_rtxnum_t            next;   /* next rtext to try (dummy) */
        xfs_rtxlen_t            alloclen; /* candidate length */
+       xfs_rtxlen_t            scanlen; /* number of free rtx to look for */
        int                     isfree; /* extent is free */
        int                     error;
 
        ASSERT(minlen % prod == 0);
        ASSERT(maxlen % prod == 0);
-       /*
-        * Check if the range in question (for maxlen) is free.
-        */
-       error = xfs_rtcheck_range(args, start, maxlen, 1, &next, &isfree);
+
+       /* Make sure we don't run off the end of the rt volume. */
+       scanlen = xfs_rtallocate_clamp_len(mp, start, maxlen, prod);
+       if (scanlen < minlen)
+               return -ENOSPC;
+
+       /* Check if the range in question (for scanlen) is free. */
+       error = xfs_rtcheck_range(args, start, scanlen, 1, &next, &isfree);
        if (error)
                return error;
 
        if (isfree) {
-               /* start to maxlen is all free; allocate it. */
-               *len = maxlen;
+               /* start to scanlen is all free; allocate it. */
+               *len = scanlen;
                *rtx = start;
                return 0;
        }
@@ -410,11 +416,6 @@ xfs_rtallocate_extent_near(
        if (start >= mp->m_sb.sb_rextents)
                start = mp->m_sb.sb_rextents - 1;
 
-       /* Make sure we don't run off the end of the rt volume. */
-       maxlen = xfs_rtallocate_clamp_len(mp, start, maxlen, prod);
-       if (maxlen < minlen)
-               return -ENOSPC;
-
        /*
         * Try the exact allocation first.
         */