]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: combine __xfs_alloc_vextent_this_ag and xfs_alloc_ag_vextent
authorDave Chinner <dchinner@redhat.com>
Tue, 9 May 2023 09:29:54 +0000 (11:29 +0200)
committerCarlos Maiolino <cem@kernel.org>
Wed, 10 May 2023 11:48:39 +0000 (13:48 +0200)
Source kernel commit: 4811c933ea1ab7de86507dc9f7c9d3d9d71cafb5

There's a bit of a recursive conundrum around
xfs_alloc_ag_vextent(). We can't first call xfs_alloc_ag_vextent()
without preparing the AGFL for the allocation, and preparing the
AGFL calls xfs_alloc_ag_vextent() to prepare the AGFL for the
allocation. This "double allocation" requirement is not really clear
from the current xfs_alloc_fix_freelist() calls that are sprinkled
through the allocation code.

It's not helped that xfs_alloc_ag_vextent() can actually allocate
from the AGFL itself, but there's special code to prevent AGFL prep
allocations from allocating from the free list it's trying to prep.
The naming is also not consistent: args->wasfromfl is true when we
allocated _from_ the free list, but the indication that we are
allocating _for_ the free list is via checking that (args->resv ==
XFS_AG_RESV_AGFL).

So, lets make this "allocation required for allocation" situation
clear by moving it all inside xfs_alloc_ag_vextent(). The freelist
allocation is a specific XFS_ALLOCTYPE_THIS_AG allocation, which
translated directly to xfs_alloc_ag_vextent_size() allocation.

This enables us to replace __xfs_alloc_vextent_this_ag() with a call
to xfs_alloc_ag_vextent(), and we drive the freelist fixing further
into the per-ag allocation algorithm.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_alloc.c

index 2a3b20ff7e766512168951d5ecc843f49d1de2f0..37f0a296e00e1a99bb978d741384a13f92e13cfb 100644 (file)
@@ -1136,22 +1136,38 @@ error:
  * and of the form k * prod + mod unless there's nothing that large.
  * Return the starting a.g. block, or NULLAGBLOCK if we can't do it.
  */
-STATIC int                     /* error */
+static int
 xfs_alloc_ag_vextent(
-       xfs_alloc_arg_t *args)  /* argument structure for allocation */
+       struct xfs_alloc_arg    *args)
 {
-       int             error=0;
+       struct xfs_mount        *mp = args->mp;
+       int                     error = 0;
 
        ASSERT(args->minlen > 0);
        ASSERT(args->maxlen > 0);
        ASSERT(args->minlen <= args->maxlen);
        ASSERT(args->mod < args->prod);
        ASSERT(args->alignment > 0);
+       ASSERT(args->resv != XFS_AG_RESV_AGFL);
+
+
+       error = xfs_alloc_fix_freelist(args, 0);
+       if (error) {
+               trace_xfs_alloc_vextent_nofix(args);
+               return error;
+       }
+       if (!args->agbp) {
+               /* cannot allocate in this AG at all */
+               trace_xfs_alloc_vextent_noagbp(args);
+               args->agbno = NULLAGBLOCK;
+               return 0;
+       }
+       args->agbno = XFS_FSB_TO_AGBNO(mp, args->fsbno);
+       args->wasfromfl = 0;
 
        /*
         * Branch to correct routine based on the type.
         */
-       args->wasfromfl = 0;
        switch (args->type) {
        case XFS_ALLOCTYPE_THIS_AG:
                error = xfs_alloc_ag_vextent_size(args);
@@ -1172,7 +1188,6 @@ xfs_alloc_ag_vextent(
 
        ASSERT(args->len >= args->minlen);
        ASSERT(args->len <= args->maxlen);
-       ASSERT(!args->wasfromfl || args->resv != XFS_AG_RESV_AGFL);
        ASSERT(args->agbno % args->alignment == 0);
 
        /* if not file data, insert new block into the reverse map btree */
@@ -2717,7 +2732,7 @@ xfs_alloc_fix_freelist(
                targs.resv = XFS_AG_RESV_AGFL;
 
                /* Allocate as many blocks as possible at once. */
-               error = xfs_alloc_ag_vextent(&targs);
+               error = xfs_alloc_ag_vextent_size(&targs);
                if (error)
                        goto out_agflbp_relse;
 
@@ -2731,6 +2746,18 @@ xfs_alloc_fix_freelist(
                                break;
                        goto out_agflbp_relse;
                }
+
+               if (!xfs_rmap_should_skip_owner_update(&targs.oinfo)) {
+                       error = xfs_rmap_alloc(tp, agbp, pag,
+                                      targs.agbno, targs.len, &targs.oinfo);
+                       if (error)
+                               goto out_agflbp_relse;
+               }
+               error = xfs_alloc_update_counters(tp, agbp,
+                                                 -((long)(targs.len)));
+               if (error)
+                       goto out_agflbp_relse;
+
                /*
                 * Put each allocated block on the list.
                 */
@@ -3240,28 +3267,6 @@ xfs_alloc_vextent_set_fsbno(
 /*
  * Allocate within a single AG only.
  */
-static int
-__xfs_alloc_vextent_this_ag(
-       struct xfs_alloc_arg    *args)
-{
-       struct xfs_mount        *mp = args->mp;
-       int                     error;
-
-       error = xfs_alloc_fix_freelist(args, 0);
-       if (error) {
-               trace_xfs_alloc_vextent_nofix(args);
-               return error;
-       }
-       if (!args->agbp) {
-               /* cannot allocate in this AG at all */
-               trace_xfs_alloc_vextent_noagbp(args);
-               args->agbno = NULLAGBLOCK;
-               return 0;
-       }
-       args->agbno = XFS_FSB_TO_AGBNO(mp, args->fsbno);
-       return xfs_alloc_ag_vextent(args);
-}
-
 static int
 xfs_alloc_vextent_this_ag(
        struct xfs_alloc_arg    *args,
@@ -3285,7 +3290,7 @@ xfs_alloc_vextent_this_ag(
        }
 
        args->pag = xfs_perag_get(mp, args->agno);
-       error = __xfs_alloc_vextent_this_ag(args);
+       error = xfs_alloc_ag_vextent(args);
 
        xfs_alloc_vextent_set_fsbno(args, minimum_agno);
        xfs_perag_put(args->pag);
@@ -3325,7 +3330,7 @@ xfs_alloc_vextent_iterate_ags(
        args->agno = start_agno;
        for (;;) {
                args->pag = xfs_perag_get(mp, args->agno);
-               error = __xfs_alloc_vextent_this_ag(args);
+               error = xfs_alloc_ag_vextent(args);
                if (error) {
                        args->agbno = NULLAGBLOCK;
                        break;