From: Brian Foster <bfoster@redhat.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH v2 11/11] xfs: condense high level AG allocation functions
Date: Wed, 22 May 2019 14:05:46 -0400 [thread overview]
Message-ID: <20190522180546.17063-12-bfoster@redhat.com> (raw)
In-Reply-To: <20190522180546.17063-1-bfoster@redhat.com>
The higher level allocation code is unnecessarily split across
xfs_alloc_ag_vextent() and xfs_alloc_ag_vextent_type(). Fold the
latter into the former to avoid the unnecessary level of indirection
and reduce the overall amount of code. No functional changes.
Signed-off-by: Brian Foster <bfoster@redhat.com>
---
fs/xfs/libxfs/xfs_alloc.c | 158 ++++++++++++++++----------------------
1 file changed, 66 insertions(+), 92 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 3b0cdb8346c9..434e5e874436 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -1299,76 +1299,6 @@ xfs_alloc_ag_vextent_agfl(
return error;
}
-/*
- * Allocate a variable extent near bno in the allocation group agno.
- * Extent's length (returned in len) will be between minlen and maxlen,
- * 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 */
-xfs_alloc_ag_vextent_type(
- xfs_alloc_arg_t *args) /* allocation argument structure */
-{
- struct xfs_alloc_cur acur = {0,};
- int error; /* error code */
- int i; /* result code, temporary */
-
- /* handle unitialized agbno range so caller doesn't have to */
- if (!args->min_agbno && !args->max_agbno)
- args->max_agbno = args->mp->m_sb.sb_agblocks - 1;
- ASSERT(args->min_agbno <= args->max_agbno);
-
- /* clamp agbno to the range if it's outside */
- if (args->agbno < args->min_agbno)
- args->agbno = args->min_agbno;
- if (args->agbno > args->max_agbno)
- args->agbno = args->max_agbno;
-
-restart:
- /* set up cursors and allocation tracking structure based on args */
- error = xfs_alloc_cur_setup(args, &acur);
- if (error)
- goto out;
-
- if (args->type == XFS_ALLOCTYPE_THIS_AG)
- error = xfs_alloc_ag_vextent_size(args, &acur, &i);
- else
- error = xfs_alloc_ag_vextent_cur(args, &acur, &i);
- if (error)
- goto out;
-
- /*
- * If we got an extent, finish the allocation. Otherwise check for busy
- * extents and retry or attempt a small allocation.
- */
- if (i) {
- error = xfs_alloc_cur_finish(args, &acur);
- if (error)
- goto out;
- } else {
- if (acur.busy) {
- trace_xfs_alloc_ag_busy(args);
- xfs_extent_busy_flush(args->mp, args->pag,
- acur.busy_gen);
- goto restart;
- }
-
- /*
- * We get here if we can't satisfy minlen or the trees are
- * empty.
- */
- error = xfs_alloc_ag_vextent_agfl(args);
- if (error)
- goto out;
- }
-
-out:
- xfs_alloc_cur_close(&acur, error);
- if (error)
- trace_xfs_alloc_ag_error(args);
- return error;
-}
-
/*
* Various AG accounting updates for a successful allocation. This includes
* updating the rmapbt, AG free block accounting and AG reservation accounting.
@@ -1412,44 +1342,88 @@ xfs_alloc_ag_vextent_accounting(
}
/*
- * Allocate a variable extent in the allocation group agno.
- * Type and bno are used to determine where in the allocation group the
- * extent will start.
- * Extent's length (returned in *len) will be between minlen and maxlen,
- * 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.
+ * Allocate a variable extent in the allocation group agno. Type and bno are
+ * used to determine where in the allocation group the extent will start.
+ * Extent's length (returned in *len) will be between minlen and maxlen, 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) /* argument structure for allocation */
{
- int error=0;
+ struct xfs_alloc_cur acur = {0,};
+ int error;
+ int i;
ASSERT(args->minlen > 0);
ASSERT(args->maxlen > 0);
ASSERT(args->minlen <= args->maxlen);
ASSERT(args->mod < args->prod);
ASSERT(args->alignment > 0);
+ ASSERT(args->type == XFS_ALLOCTYPE_THIS_AG ||
+ args->type == XFS_ALLOCTYPE_NEAR_BNO ||
+ args->type == XFS_ALLOCTYPE_THIS_BNO);
+ ASSERT(args->min_agbno <= args->max_agbno);
+
+ args->wasfromfl = 0;
+
+ /* handle unitialized agbno range so caller doesn't have to */
+ if (!args->min_agbno && !args->max_agbno)
+ args->max_agbno = args->mp->m_sb.sb_agblocks - 1;
+
+ /* clamp agbno to the range if it's outside */
+ if (args->agbno < args->min_agbno)
+ args->agbno = args->min_agbno;
+ if (args->agbno > args->max_agbno)
+ args->agbno = args->max_agbno;
+
+restart:
+ /* set up cursors and allocation tracking structure based on args */
+ error = xfs_alloc_cur_setup(args, &acur);
+ if (error)
+ goto out;
+
+ if (args->type == XFS_ALLOCTYPE_THIS_AG)
+ error = xfs_alloc_ag_vextent_size(args, &acur, &i);
+ else
+ error = xfs_alloc_ag_vextent_cur(args, &acur, &i);
+ if (error)
+ goto out;
/*
- * Branch to correct routine based on the type.
+ * If we got an extent, finish the allocation. Otherwise check for busy
+ * extents and retry or attempt a small allocation.
*/
- args->wasfromfl = 0;
- switch (args->type) {
- case XFS_ALLOCTYPE_THIS_AG:
- case XFS_ALLOCTYPE_NEAR_BNO:
- case XFS_ALLOCTYPE_THIS_BNO:
- error = xfs_alloc_ag_vextent_type(args);
- break;
- default:
- ASSERT(0);
- /* NOTREACHED */
+ if (i) {
+ error = xfs_alloc_cur_finish(args, &acur);
+ if (error)
+ goto out;
+ } else {
+ if (acur.busy) {
+ trace_xfs_alloc_ag_busy(args);
+ xfs_extent_busy_flush(args->mp, args->pag,
+ acur.busy_gen);
+ goto restart;
+ }
+
+ /*
+ * We get here if we can't satisfy minlen or the trees are
+ * empty. We don't pass a cursor so this returns an AGFL block
+ * (i == 0) or nothing.
+ */
+ error = xfs_alloc_ag_vextent_agfl(args);
+ if (error)
+ goto out;
}
- if (error)
- return error;
if (args->agbno != NULLAGBLOCK)
error = xfs_alloc_ag_vextent_accounting(args);
+
+out:
+ xfs_alloc_cur_close(&acur, error);
+ if (error)
+ trace_xfs_alloc_ag_error(args);
return error;
}
--
2.17.2
next prev parent reply other threads:[~2019-05-22 18:05 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-22 18:05 [PATCH v2 00/11] xfs: rework extent allocation Brian Foster
2019-05-22 18:05 ` [PATCH v2 01/11] xfs: clean up small allocation helper Brian Foster
2019-06-21 23:57 ` Darrick J. Wong
2019-05-22 18:05 ` [PATCH v2 02/11] xfs: move " Brian Foster
2019-06-21 23:58 ` Darrick J. Wong
2019-05-22 18:05 ` [PATCH v2 03/11] xfs: skip small alloc cntbt logic on NULL cursor Brian Foster
2019-06-21 23:58 ` Darrick J. Wong
2019-05-22 18:05 ` [PATCH v2 04/11] xfs: always update params on small allocation Brian Foster
2019-06-21 23:59 ` Darrick J. Wong
2019-05-22 18:05 ` [PATCH v2 05/11] xfs: track active state of allocation btree cursors Brian Foster
2019-05-22 18:05 ` [PATCH v2 06/11] xfs: use locality optimized cntbt lookups for near mode allocations Brian Foster
2019-05-22 18:05 ` [PATCH v2 07/11] xfs: refactor exact extent allocation mode Brian Foster
2019-05-22 18:05 ` [PATCH v2 08/11] xfs: refactor by-size " Brian Foster
2019-05-22 18:05 ` [PATCH v2 09/11] xfs: replace small allocation logic with agfl only logic Brian Foster
2019-05-22 18:05 ` [PATCH v2 10/11] xfs: refactor successful AG allocation accounting code Brian Foster
2019-05-22 18:05 ` Brian Foster [this message]
2019-05-23 1:56 ` [PATCH v2 00/11] xfs: rework extent allocation Dave Chinner
2019-05-23 12:55 ` Brian Foster
2019-05-23 22:15 ` Dave Chinner
2019-05-24 12:00 ` Brian Foster
2019-05-25 22:43 ` Dave Chinner
2019-05-31 17:11 ` Brian Foster
2019-06-06 15:21 ` Brian Foster
2019-06-06 22:13 ` Dave Chinner
2019-06-07 12:57 ` Brian Foster
2019-06-06 22:05 ` Dave Chinner
2019-06-07 12:56 ` Brian Foster
2019-06-21 15:18 ` Darrick J. Wong
2019-07-01 19:12 ` Brian Foster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190522180546.17063-12-bfoster@redhat.com \
--to=bfoster@redhat.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).