From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 33/36] xfs: move allocation accounting to xfs_alloc_vextent_set_fsbno()
Date: Fri, 3 Dec 2021 11:01:08 +1100 [thread overview]
Message-ID: <20211203000111.2800982-34-david@fromorbit.com> (raw)
In-Reply-To: <20211203000111.2800982-1-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
Move it from xfs_alloc_ag_vextent() so we can get rid of that layer.
Rename xfs_alloc_vextent_set_fsbno() to xfs_alloc_vextent_finish()
to indicate that it's function is finishing off the allocation that
we've run now that it contains much more functionality.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
fs/xfs/libxfs/xfs_alloc.c | 127 +++++++++++++++++++-------------------
1 file changed, 62 insertions(+), 65 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index d2595dada0e2..a1f391a44fe5 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -1149,36 +1149,6 @@ xfs_alloc_ag_vextent(
ASSERT(0);
/* NOTREACHED */
}
-
- if (error || args->agbno == NULLAGBLOCK)
- return error;
-
- ASSERT(args->len >= args->minlen);
- ASSERT(args->len <= args->maxlen);
- ASSERT(args->agbno % args->alignment == 0);
-
- /* if not file data, insert new block into the reverse map btree */
- if (!xfs_rmap_should_skip_owner_update(&args->oinfo)) {
- error = xfs_rmap_alloc(args->tp, args->agbp, args->pag,
- args->agbno, args->len, &args->oinfo);
- if (error)
- return error;
- }
-
- if (!args->wasfromfl) {
- error = xfs_alloc_update_counters(args->tp, args->agbp,
- -((long)(args->len)));
- if (error)
- return error;
-
- ASSERT(!xfs_extent_busy_search(args->mp, args->pag,
- args->agbno, args->len));
- }
-
- xfs_ag_resv_alloc_extent(args->pag, args->resv, args);
-
- XFS_STATS_INC(args->mp, xs_allocx);
- XFS_STATS_ADD(args->mp, xs_allocb, args->len);
return error;
}
@@ -3221,31 +3191,56 @@ xfs_alloc_vextent_prepare_ag(
}
/*
- * Post-process allocation results to set the allocated block number correctly
- * for the caller.
+ * Post-process allocation results to account for the allocation if it succeed
+ * and set the allocated block number correctly for the caller.
*
- * XXX: xfs_alloc_vextent() should really be returning ENOSPC for ENOSPC, not
+ * XXX: we should really be returning ENOSPC for ENOSPC, not
* hiding it behind a "successful" NULLFSBLOCK allocation.
*/
-static void
-xfs_alloc_vextent_set_fsbno(
+static int
+xfs_alloc_vextent_finish(
struct xfs_alloc_arg *args)
{
- struct xfs_mount *mp = args->mp;
+ int error = 0;
/* Allocation failed with ENOSPC if NULLAGBLOCK was returned. */
if (args->agbno == NULLAGBLOCK) {
args->fsbno = NULLFSBLOCK;
- return;
+ return 0;
}
- args->fsbno = XFS_AGB_TO_FSB(mp, args->agno, args->agbno);
-#ifdef DEBUG
+ args->fsbno = XFS_AGB_TO_FSB(args->mp, args->agno, args->agbno);
+
ASSERT(args->len >= args->minlen);
ASSERT(args->len <= args->maxlen);
ASSERT(args->agbno % args->alignment == 0);
- XFS_AG_CHECK_DADDR(mp, XFS_FSB_TO_DADDR(mp, args->fsbno), args->len);
-#endif
+ XFS_AG_CHECK_DADDR(args->mp, XFS_FSB_TO_DADDR(args->mp, args->fsbno),
+ args->len);
+
+ /* if not file data, insert new block into the reverse map btree */
+ if (!xfs_rmap_should_skip_owner_update(&args->oinfo)) {
+ error = xfs_rmap_alloc(args->tp, args->agbp, args->pag,
+ args->agbno, args->len, &args->oinfo);
+ if (error)
+ return error;
+ }
+
+ if (!args->wasfromfl) {
+ error = xfs_alloc_update_counters(args->tp, args->agbp,
+ -((long)(args->len)));
+ if (error)
+ return error;
+
+ ASSERT(!xfs_extent_busy_search(args->mp, args->pag,
+ args->agbno, args->len));
+ }
+
+ xfs_ag_resv_alloc_extent(args->pag, args->resv, args);
+
+ XFS_STATS_INC(args->mp, xs_allocx);
+ XFS_STATS_ADD(args->mp, xs_allocb, args->len);
+
+ return 0;
}
/*
@@ -3282,8 +3277,7 @@ xfs_alloc_vextent_this_ag(
return error;
}
- xfs_alloc_vextent_set_fsbno(args);
- return 0;
+ return xfs_alloc_vextent_finish(args);
}
/*
@@ -3371,8 +3365,10 @@ xfs_alloc_vextent_iterate_ags(
xfs_perag_put(args->pag);
args->pag = NULL;
}
- xfs_perag_put(args->pag);
- args->pag = NULL;
+ /*
+ * On success, perag is left referenced in args for the caller to clean
+ * up after they've finished the allocation.
+ */
return error;
}
@@ -3418,8 +3414,12 @@ xfs_alloc_vextent_start_ag(
error = xfs_alloc_vextent_iterate_ags(args, start_agno,
XFS_ALLOC_FLAG_TRYLOCK);
- if (error)
- return error;
+ if (!error)
+ error = xfs_alloc_vextent_finish(args);
+ if (args->pag) {
+ xfs_perag_put(args->pag);
+ args->pag = NULL;
+ }
if (bump_rotor) {
if (args->agno == start_agno)
@@ -3430,8 +3430,7 @@ xfs_alloc_vextent_start_ag(
(mp->m_sb.sb_agcount * rotorstep);
}
- xfs_alloc_vextent_set_fsbno(args);
- return 0;
+ return error;
}
/*
@@ -3458,10 +3457,13 @@ xfs_alloc_vextent_first_ag(
args->fsbno = target;
error = xfs_alloc_vextent_iterate_ags(args,
XFS_FSB_TO_AGNO(mp, args->fsbno), 0);
- if (error)
- return error;
- xfs_alloc_vextent_set_fsbno(args);
- return 0;
+ if (!error)
+ error = xfs_alloc_vextent_finish(args);
+ if (args->pag) {
+ xfs_perag_put(args->pag);
+ args->pag = NULL;
+ }
+ return error;
}
/*
@@ -3492,14 +3494,11 @@ xfs_alloc_vextent_exact_bno(
if (error)
return error;
- if (args->agbp) {
+ if (args->agbp)
error = xfs_alloc_ag_vextent(args);
- if (error)
- return error;
- }
-
- xfs_alloc_vextent_set_fsbno(args);
- return 0;
+ if (!error)
+ error = xfs_alloc_vextent_finish(args);
+ return error;
}
/*
@@ -3534,13 +3533,11 @@ xfs_alloc_vextent_near_bno(
if (args->agbp)
error = xfs_alloc_ag_vextent(args);
+ if (!error)
+ error = xfs_alloc_vextent_finish(args);
if (need_pag)
xfs_perag_put(args->pag);
- if (error)
- return error;
-
- xfs_alloc_vextent_set_fsbno(args);
- return 0;
+ return error;
}
/* Ensure that the freelist is at full capacity. */
--
2.33.0
next prev parent reply other threads:[~2021-12-03 0:01 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-03 0:00 [RFC] [PATCH 00/36] xfs: more work towards shrinking Dave Chinner
2021-12-03 0:00 ` [PATCH 01/36] xfs: make last AG grow/shrink perag centric Dave Chinner
2021-12-03 0:00 ` [PATCH 02/36] xfs: kill xfs_ialloc_pagi_init() Dave Chinner
2021-12-03 0:00 ` [PATCH 03/36] xfs: pass perag to xfs_ialloc_read_agi() Dave Chinner
2021-12-03 0:00 ` [PATCH 04/36] xfs: kill xfs_alloc_pagf_init() Dave Chinner
2021-12-03 0:00 ` [PATCH 05/36] xfs: pass perag to xfs_alloc_read_agf() Dave Chinner
2021-12-03 5:37 ` kernel test robot
2021-12-03 7:10 ` [RFC PATCH] xfs: xfs_reflink_find_shared can be static kernel test robot
2021-12-03 7:19 ` [PATCH 05/36] xfs: pass perag to xfs_alloc_read_agf() kernel test robot
2021-12-03 7:19 ` kernel test robot
2021-12-03 0:00 ` [PATCH 06/36] xfs: pass perag to xfs_read_agi Dave Chinner
2021-12-03 0:00 ` [PATCH 07/36] xfs: pass perag to xfs_read_agf Dave Chinner
2021-12-03 0:00 ` [PATCH 08/36] xfs: pass perag to xfs_alloc_get_freelist Dave Chinner
2021-12-03 0:00 ` [PATCH 09/36] xfs: pass perag to xfs_alloc_put_freelist Dave Chinner
2021-12-03 0:00 ` [PATCH 10/36] xfs: pass perag to xfs_alloc_read_agfl Dave Chinner
2021-12-03 0:00 ` [PATCH 11/36] xfs: Pre-calculate per-AG agbno geometry Dave Chinner
2021-12-03 0:00 ` [PATCH 12/36] xfs: Pre-calculate per-AG agino geometry Dave Chinner
2021-12-03 0:00 ` [PATCH 13/36] xfs: replace xfs_ag_block_count() with perag accesses Dave Chinner
2021-12-03 0:00 ` [PATCH 14/36] xfs: make is_log_ag() a first class helper Dave Chinner
2021-12-03 0:00 ` [PATCH 15/36] xfs: active perag reference counting Dave Chinner
2021-12-03 0:00 ` [PATCH 16/36] xfs: rework the perag trace points to be perag centric Dave Chinner
2021-12-03 0:00 ` [PATCH 17/36] xfs: convert xfs_imap() to take a perag Dave Chinner
2021-12-03 0:00 ` [PATCH 18/36] xfs: use active perag references for inode allocation Dave Chinner
2021-12-03 0:00 ` [PATCH 19/36] xfs: inobt can use perags in many more places than it does Dave Chinner
2021-12-03 0:00 ` [PATCH 20/36] xfs: convert xfs_ialloc_next_ag() to an atomic Dave Chinner
2021-12-03 0:00 ` [PATCH 21/36] xfs: perags need atomic operational state Dave Chinner
2021-12-03 0:00 ` [PATCH 22/36] xfs: introduce xfs_for_each_perag_wrap() Dave Chinner
2021-12-03 0:00 ` [PATCH 23/36] xfs: rework xfs_alloc_vextent() Dave Chinner
2021-12-03 0:00 ` [PATCH 24/36] xfs: use xfs_alloc_vextent_this_ag() in _iterate_ags() Dave Chinner
2021-12-03 0:01 ` [PATCH 25/36] xfs: combine __xfs_alloc_vextent_this_ag and xfs_alloc_ag_vextent Dave Chinner
2021-12-03 0:01 ` [PATCH 26/36] xfs: use xfs_alloc_vextent_this_ag() where appropriate Dave Chinner
2021-12-03 0:01 ` [PATCH 27/36] xfs: factor xfs_bmap_btalloc() Dave Chinner
2021-12-03 0:01 ` [PATCH 28/36] xfs: use xfs_alloc_vextent_first_ag() where appropriate Dave Chinner
2021-12-03 0:01 ` [PATCH 29/36] xfs: use xfs_alloc_vextent_start_bno() " Dave Chinner
2021-12-03 0:01 ` [PATCH 30/36] xfs: introduce xfs_alloc_vextent_near_bno() Dave Chinner
2021-12-03 0:01 ` [PATCH 31/36] xfs: introduce xfs_alloc_vextent_exact_bno() Dave Chinner
2021-12-03 0:01 ` [PATCH 32/36] xfs: introduce xfs_alloc_vextent_prepare() Dave Chinner
2021-12-03 0:01 ` Dave Chinner [this message]
2021-12-03 0:01 ` [PATCH 34/36] xfs: fold xfs_alloc_ag_vextent() into callers Dave Chinner
2021-12-03 0:01 ` [PATCH 35/36] xfs: convert xfs_alloc_vextent_iterate_ags() to use perag walker Dave Chinner
2021-12-03 0:01 ` [PATCH 36/36] xfs: convert trim to use for_each_perag_range Dave Chinner
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=20211203000111.2800982-34-david@fromorbit.com \
--to=david@fromorbit.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