linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Cc: john.g.garry@oracle.com
Subject: [PATCH 1/9] xfs: split xfs_bmap_btalloc_at_eof()
Date: Wed,  4 Oct 2023 11:19:35 +1100	[thread overview]
Message-ID: <20231004001943.349265-2-david@fromorbit.com> (raw)
In-Reply-To: <20231004001943.349265-1-david@fromorbit.com>

From: Dave Chinner <dchinner@redhat.com>

This function is really implementing two policies. The first is
trying to create contiguous extents at file extension. Failing that,
it attempts to perform aligned allocation. These are really two
separate policies, and it is further complicated by filestream
allocation having different aligned allocation constraints than
the normal bmap allocation.

Split xfs_bmap_btalloc_at_eof() into two parts so we can start to
align the two different allocator policies more closely.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 fs/xfs/libxfs/xfs_bmap.c | 147 +++++++++++++++++++++------------------
 1 file changed, 80 insertions(+), 67 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 30c931b38853..e14671414afb 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3451,81 +3451,81 @@ xfs_bmap_exact_minlen_extent_alloc(
 
 #endif
 
-/*
- * If we are not low on available data blocks and we are allocating at
- * EOF, optimise allocation for contiguous file extension and/or stripe
- * alignment of the new extent.
- *
- * NOTE: ap->aeof is only set if the allocation length is >= the
- * stripe unit and the allocation offset is at the end of file.
- */
+ /*
+ * Attempt contiguous allocation for file extension.
+  */
+ static int
+ xfs_bmap_btalloc_at_eof(
+	struct xfs_bmalloca	*ap,
+	struct xfs_alloc_arg	*args,
+	xfs_extlen_t		blen,
+	int			stripe_align)
+{
+	struct xfs_mount	*mp = args->mp;
+	struct xfs_perag        *caller_pag = args->pag;
+	xfs_extlen_t		nextminlen = 0;
+	int			error;
+
+	/*
+	 * Compute the minlen+alignment for the next case.  Set slop so
+	 * that the value of minlen+alignment+slop doesn't go up between
+	 * the calls.
+	 */
+	args->alignment = 1;
+	if (blen > stripe_align && blen <= args->maxlen)
+		nextminlen = blen - stripe_align;
+	else
+		nextminlen = args->minlen;
+	if (nextminlen + stripe_align > args->minlen + 1)
+		args->minalignslop = nextminlen + stripe_align -
+				args->minlen - 1;
+	else
+		args->minalignslop = 0;
+
+	if (!caller_pag)
+		args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ap->blkno));
+	error = xfs_alloc_vextent_exact_bno(args, ap->blkno);
+	if (!caller_pag) {
+		xfs_perag_put(args->pag);
+		args->pag = NULL;
+	}
+	if (error)
+		return error;
+
+	if (args->fsbno != NULLFSBLOCK)
+		return 0;
+	/*
+	 * Exact allocation failed. Reset to try an aligned allocation
+	 * according to the original allocation specification.
+	 */
+	args->minlen = nextminlen;
+	return 0;
+}
+
 static int
-xfs_bmap_btalloc_at_eof(
+xfs_bmap_btalloc_aligned(
 	struct xfs_bmalloca	*ap,
 	struct xfs_alloc_arg	*args,
 	xfs_extlen_t		blen,
 	int			stripe_align,
 	bool			ag_only)
 {
-	struct xfs_mount	*mp = args->mp;
-	struct xfs_perag	*caller_pag = args->pag;
+	struct xfs_perag        *caller_pag = args->pag;
 	int			error;
 
 	/*
-	 * If there are already extents in the file, try an exact EOF block
-	 * allocation to extend the file as a contiguous extent. If that fails,
-	 * or it's the first allocation in a file, just try for a stripe aligned
-	 * allocation.
+	 * If we failed an exact EOF allocation already, stripe
+	 * alignment will have already been taken into account in
+	 * args->minlen. Hence we only adjust minlen to try to preserve
+	 * alignment if no slop has been reserved for alignment
 	 */
-	if (ap->offset) {
-		xfs_extlen_t	nextminlen = 0;
-
-		/*
-		 * Compute the minlen+alignment for the next case.  Set slop so
-		 * that the value of minlen+alignment+slop doesn't go up between
-		 * the calls.
-		 */
-		args->alignment = 1;
-		if (blen > stripe_align && blen <= args->maxlen)
-			nextminlen = blen - stripe_align;
-		else
-			nextminlen = args->minlen;
-		if (nextminlen + stripe_align > args->minlen + 1)
-			args->minalignslop = nextminlen + stripe_align -
-					args->minlen - 1;
-		else
-			args->minalignslop = 0;
-
-		if (!caller_pag)
-			args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ap->blkno));
-		error = xfs_alloc_vextent_exact_bno(args, ap->blkno);
-		if (!caller_pag) {
-			xfs_perag_put(args->pag);
-			args->pag = NULL;
-		}
-		if (error)
-			return error;
-
-		if (args->fsbno != NULLFSBLOCK)
-			return 0;
-		/*
-		 * Exact allocation failed. Reset to try an aligned allocation
-		 * according to the original allocation specification.
-		 */
-		args->alignment = stripe_align;
-		args->minlen = nextminlen;
-		args->minalignslop = 0;
-	} else {
-		/*
-		 * Adjust minlen to try and preserve alignment if we
-		 * can't guarantee an aligned maxlen extent.
-		 */
-		args->alignment = stripe_align;
-		if (blen > args->alignment &&
-		    blen <= args->maxlen + args->alignment)
-			args->minlen = blen - args->alignment;
-		args->minalignslop = 0;
+	if (args->minalignslop == 0) {
+		if (blen > stripe_align &&
+		    blen <= args->maxlen + stripe_align)
+			args->minlen = blen - stripe_align;
 	}
+	args->alignment = stripe_align;
+	args->minalignslop = 0;
 
 	if (ag_only) {
 		error = xfs_alloc_vextent_near_bno(args, ap->blkno);
@@ -3612,8 +3612,14 @@ xfs_bmap_btalloc_filestreams(
 	}
 
 	args->minlen = xfs_bmap_select_minlen(ap, args, blen);
+	if (ap->aeof && ap->offset)
+		error = xfs_bmap_btalloc_at_eof(ap, args, blen, stripe_align);
+
+	if (error || args->fsbno != NULLFSBLOCK)
+		goto out_low_space;
+
 	if (ap->aeof)
-		error = xfs_bmap_btalloc_at_eof(ap, args, blen, stripe_align,
+		error = xfs_bmap_btalloc_aligned(ap, args, blen, stripe_align,
 				true);
 
 	if (!error && args->fsbno == NULLFSBLOCK)
@@ -3662,13 +3668,20 @@ xfs_bmap_btalloc_best_length(
 	 * optimal or even aligned allocations in this case, so don't waste time
 	 * trying.
 	 */
-	if (ap->aeof && !(ap->tp->t_flags & XFS_TRANS_LOWMODE)) {
-		error = xfs_bmap_btalloc_at_eof(ap, args, blen, stripe_align,
-				false);
+	if (ap->aeof && ap->offset && !(ap->tp->t_flags & XFS_TRANS_LOWMODE)) {
+		error = xfs_bmap_btalloc_at_eof(ap, args, blen, stripe_align);
 		if (error || args->fsbno != NULLFSBLOCK)
 			return error;
 	}
 
+	/* attempt aligned allocation for new EOF extents */
+	if (ap->aeof)
+		error = xfs_bmap_btalloc_aligned(ap, args, blen, stripe_align,
+				false);
+	if (error || args->fsbno != NULLFSBLOCK)
+		return error;
+
+	/* attempt unaligned allocation */
 	error = xfs_alloc_vextent_start_ag(args, ap->blkno);
 	if (error || args->fsbno != NULLFSBLOCK)
 		return error;
-- 
2.40.1


  reply	other threads:[~2023-10-04  0:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-04  0:19 [RFC PATCH 0/9] xfs: push perags further into allocation routines Dave Chinner
2023-10-04  0:19 ` Dave Chinner [this message]
2023-10-04 23:41   ` [PATCH 1/9] xfs: split xfs_bmap_btalloc_at_eof() Darrick J. Wong
2023-10-05  9:41   ` Christoph Hellwig
2023-10-04  0:19 ` [PATCH 2/9] xfs: contiguous EOF allocation across AGs Dave Chinner
2023-10-05  9:43   ` Christoph Hellwig
2023-10-06  5:27   ` Darrick J. Wong
2023-10-04  0:19 ` [PATCH 3/9] xfs: select the AG with the largest contiguous space Dave Chinner
2023-10-05  9:45   ` Christoph Hellwig
2023-10-05  9:46   ` Christoph Hellwig
2023-10-24 16:25     ` Darrick J. Wong
2023-10-04  0:19 ` [PATCH 4/9] xfs: push the perag outwards in initial allocation Dave Chinner
2023-10-05 11:57   ` Christoph Hellwig
2023-10-04  0:19 ` [PATCH 5/9] xfs: aligned EOF allocations don't need to scan AGs anymore Dave Chinner
2023-10-05 11:59   ` Christoph Hellwig
2023-10-06  5:55   ` Darrick J. Wong
2023-10-04  0:19 ` [PATCH 6/9] xfs: use agno/agbno in xfs_alloc_vextent functions Dave Chinner
2023-10-05 12:02   ` Christoph Hellwig
2023-10-06  5:56   ` Darrick J. Wong
2023-10-04  0:19 ` [PATCH 7/9] xfs: caller perag always supplied to xfs_alloc_vextent_near_bno Dave Chinner
2023-10-05 12:02   ` Christoph Hellwig
2023-10-06  5:59   ` Darrick J. Wong
2023-10-04  0:19 ` [PATCH 8/9] xfs: collapse near and exact bno allocation Dave Chinner
2023-10-05 12:03   ` Christoph Hellwig
2023-10-06  6:01   ` Darrick J. Wong
2023-10-04  0:19 ` [PATCH 9/9] xfs: return -ENOSPC rather than NULLFSBLOCK from allocation functions Dave Chinner
2023-10-05 12:21   ` Christoph Hellwig

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=20231004001943.349265-2-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=john.g.garry@oracle.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).