Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Chandan Babu R <chandan.babu@oracle.com>
Cc: "Darrick J. Wong" <djwong@kernel.org>, linux-xfs@vger.kernel.org
Subject: [PATCH 16/22] xfs: factor out a xfs_rtalloc_sumlevel helper
Date: Mon, 18 Dec 2023 05:57:32 +0100	[thread overview]
Message-ID: <20231218045738.711465-17-hch@lst.de> (raw)
In-Reply-To: <20231218045738.711465-1-hch@lst.de>

xfs_rtallocate_extent_size has two loops with nearly identical logic
in them.  Split that logic into a separate xfs_rtalloc_sumlevel helper.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_rtalloc.c | 153 ++++++++++++++++++++-----------------------
 1 file changed, 70 insertions(+), 83 deletions(-)

diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 85d683550048a0..6b8b657e40dc0b 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -538,6 +538,52 @@ xfs_rtallocate_extent_near(
 	return -ENOSPC;
 }
 
+static int
+xfs_rtalloc_sumlevel(
+	struct xfs_rtalloc_args	*args,
+	int			l,	/* level number */
+	xfs_rtxlen_t		minlen,	/* minimum length to allocate */
+	xfs_rtxlen_t		maxlen,	/* maximum length to allocate */
+	xfs_rtxlen_t		prod,	/* extent product factor */
+	xfs_rtxlen_t		*len,	/* out: actual length allocated */
+	xfs_rtxnum_t		*rtx)	/* out: start rtext allocated */
+{
+	xfs_fileoff_t		i;	/* bitmap block number */
+
+	for (i = 0; i < args->mp->m_sb.sb_rbmblocks; i++) {
+		xfs_suminfo_t	sum;	/* summary information for extents */
+		xfs_rtxnum_t	n;	/* next rtext to be tried */
+		int		error;
+
+		error = xfs_rtget_summary(args, l, i, &sum);
+		if (error)
+			return error;
+
+		/*
+		 * Nothing there, on to the next block.
+		 */
+		if (!sum)
+			continue;
+
+		/*
+		 * Try allocating the extent.
+		 */
+		error = xfs_rtallocate_extent_block(args, i, minlen, maxlen,
+				len, &n, prod, rtx);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * If the "next block to try" returned from the allocator is
+		 * beyond the next bitmap block, skip to that bitmap block.
+		 */
+		if (xfs_rtx_to_rbmblock(args->mp, n) > i + 1)
+			i = xfs_rtx_to_rbmblock(args->mp, n) - 1;
+	}
+
+	return -ENOSPC;
+}
+
 /*
  * Allocate an extent of length minlen<=len<=maxlen, with no position
  * specified.  If we don't get maxlen then use prod to trim
@@ -552,12 +598,8 @@ xfs_rtallocate_extent_size(
 	xfs_rtxlen_t		prod,	/* extent product factor */
 	xfs_rtxnum_t		*rtx)	/* out: start rtext allocated */
 {
-	struct xfs_mount	*mp = args->mp;
 	int			error;
-	xfs_fileoff_t		i;	/* bitmap block number */
 	int			l;	/* level number (loop control) */
-	xfs_rtxnum_t		n;	/* next rtext to be tried */
-	xfs_suminfo_t		sum;	/* summary information for extents */
 
 	ASSERT(minlen % prod == 0);
 	ASSERT(maxlen % prod == 0);
@@ -565,46 +607,23 @@ xfs_rtallocate_extent_size(
 
 	/*
 	 * Loop over all the levels starting with maxlen.
-	 * At each level, look at all the bitmap blocks, to see if there
-	 * are extents starting there that are long enough (>= maxlen).
-	 * Note, only on the initial level can the allocation fail if
-	 * the summary says there's an extent.
+	 *
+	 * At each level, look at all the bitmap blocks, to see if there are
+	 * extents starting there that are long enough (>= maxlen).
+	 *
+	 * Note, only on the initial level can the allocation fail if the
+	 * summary says there's an extent.
 	 */
-	for (l = xfs_highbit32(maxlen); l < mp->m_rsumlevels; l++) {
-		/*
-		 * Loop over all the bitmap blocks.
-		 */
-		for (i = 0; i < mp->m_sb.sb_rbmblocks; i++) {
-			/*
-			 * Get the summary for this level/block.
-			 */
-			error = xfs_rtget_summary(args, l, i, &sum);
-			if (error)
-				return error;
-			/*
-			 * Nothing there, on to the next block.
-			 */
-			if (!sum)
-				continue;
-			/*
-			 * Try allocating the extent.
-			 */
-			error = xfs_rtallocate_extent_block(args, i, maxlen,
-					maxlen, len, &n, prod, rtx);
-			if (error != -ENOSPC)
-				return error;
-			/*
-			 * If the "next block to try" returned from the
-			 * allocator is beyond the next bitmap block,
-			 * skip to that bitmap block.
-			 */
-			if (xfs_rtx_to_rbmblock(mp, n) > i + 1)
-				i = xfs_rtx_to_rbmblock(mp, n) - 1;
-		}
+	for (l = xfs_highbit32(maxlen); l < args->mp->m_rsumlevels; l++) {
+		error = xfs_rtalloc_sumlevel(args, l, minlen, maxlen, prod, len,
+				rtx);
+		if (error != -ENOSPC)
+			return error;
 	}
+
 	/*
-	 * Didn't find any maxlen blocks.  Try smaller ones, unless
-	 * we're asking for a fixed size extent.
+	 * Didn't find any maxlen blocks.  Try smaller ones, unless we are
+	 * looking for a fixed size extent.
 	 */
 	if (minlen > --maxlen)
 		return -ENOSPC;
@@ -613,51 +632,19 @@ xfs_rtallocate_extent_size(
 
 	/*
 	 * Loop over sizes, from maxlen down to minlen.
-	 * This time, when we do the allocations, allow smaller ones
-	 * to succeed.
+	 *
+	 * This time, when we do the allocations, allow smaller ones to succeed,
+	 * but make sure the specified minlen/maxlen are in the possible range
+	 * for this summary level.
 	 */
 	for (l = xfs_highbit32(maxlen); l >= xfs_highbit32(minlen); l--) {
-		/*
-		 * Loop over all the bitmap blocks, try an allocation
-		 * starting in that block.
-		 */
-		for (i = 0; i < mp->m_sb.sb_rbmblocks; i++) {
-			/*
-			 * Get the summary information for this level/block.
-			 */
-			error =	xfs_rtget_summary(args, l, i, &sum);
-			if (error)
-				return error;
-
-			/*
-			 * If nothing there, go on to next.
-			 */
-			if (!sum)
-				continue;
-			/*
-			 * Try the allocation.  Make sure the specified
-			 * minlen/maxlen are in the possible range for
-			 * this summary level.
-			 */
-			error = xfs_rtallocate_extent_block(args, i,
-					XFS_RTMAX(minlen, 1 << l),
-					XFS_RTMIN(maxlen, (1 << (l + 1)) - 1),
-					len, &n, prod, rtx);
-			if (error != -ENOSPC)
-				return error;
-
-			/*
-			 * If the "next block to try" returned from the
-			 * allocator is beyond the next bitmap block,
-			 * skip to that bitmap block.
-			 */
-			if (xfs_rtx_to_rbmblock(mp, n) > i + 1)
-				i = xfs_rtx_to_rbmblock(mp, n) - 1;
-		}
+		error = xfs_rtalloc_sumlevel(args, l, XFS_RTMAX(minlen, 1 << l),
+				XFS_RTMIN(maxlen, (1 << (l + 1)) - 1), prod,
+				len, rtx);
+		if (error != -ENOSPC)
+			return error;
 	}
-	/*
-	 * Got nothing, return failure.
-	 */
+
 	return -ENOSPC;
 }
 
-- 
2.39.2


  parent reply	other threads:[~2023-12-18  4:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-18  4:57 RT allocator tidy ups v2 Christoph Hellwig
2023-12-18  4:57 ` [PATCH 01/22] xfs: consider minlen sized extents in xfs_rtallocate_extent_block Christoph Hellwig
2023-12-18  4:57 ` [PATCH 02/22] xfs: turn the xfs_trans_mod_dquot_byino stub into an inline function Christoph Hellwig
2023-12-18  4:57 ` [PATCH 03/22] xfs: remove the xfs_alloc_arg argument to xfs_bmap_btalloc_accounting Christoph Hellwig
2023-12-18  4:57 ` [PATCH 04/22] xfs: also use xfs_bmap_btalloc_accounting for RT allocations Christoph Hellwig
2023-12-18  4:57 ` [PATCH 05/22] xfs: move xfs_bmap_rtalloc to xfs_rtalloc.c Christoph Hellwig
2023-12-18  4:57 ` [PATCH 06/22] xfs: return -ENOSPC from xfs_rtallocate_* Christoph Hellwig
2023-12-18  4:57 ` [PATCH 07/22] xfs: reflow the tail end of xfs_bmap_rtalloc Christoph Hellwig
2023-12-18  4:57 ` [PATCH 08/22] xfs: indicate if xfs_bmap_adjacent changed ap->blkno Christoph Hellwig
2023-12-18  4:57 ` [PATCH 09/22] xfs: cleanup picking the start extent hint in xfs_bmap_rtalloc Christoph Hellwig
2023-12-18  4:57 ` [PATCH 10/22] xfs: move xfs_rtget_summary to xfs_rtbitmap.c Christoph Hellwig
2023-12-18  4:57 ` [PATCH 11/22] xfs: split xfs_rtmodify_summary_int Christoph Hellwig
2023-12-18  4:57 ` [PATCH 12/22] xfs: invert a check in xfs_rtallocate_extent_block Christoph Hellwig
2023-12-18 17:50   ` Darrick J. Wong
2023-12-18  4:57 ` [PATCH 13/22] xfs: reflow the tail end of xfs_rtallocate_extent_block Christoph Hellwig
2023-12-18 17:51   ` Darrick J. Wong
2023-12-18  4:57 ` [PATCH 14/22] xfs: merge the calls to xfs_rtallocate_range in xfs_rtallocate_block Christoph Hellwig
2023-12-18 17:52   ` Darrick J. Wong
2023-12-18  4:57 ` [PATCH 15/22] xfs: tidy up xfs_rtallocate_extent_exact Christoph Hellwig
2023-12-18  4:57 ` Christoph Hellwig [this message]
2023-12-18  4:57 ` [PATCH 17/22] xfs: remove rt-wrappers from xfs_format.h Christoph Hellwig
2023-12-18  4:57 ` [PATCH 18/22] xfs: remove XFS_RTMIN/XFS_RTMAX Christoph Hellwig
2023-12-18  4:57 ` [PATCH 19/22] xfs: reorder the minlen and prod calculations in xfs_bmap_rtalloc Christoph Hellwig
2023-12-18  4:57 ` [PATCH 20/22] xfs: simplify and optimize the RT allocation fallback cascade Christoph Hellwig
2023-12-18 22:17   ` Darrick J. Wong
2023-12-18  4:57 ` [PATCH 21/22] xfs: fold xfs_rtallocate_extent into xfs_bmap_rtalloc Christoph Hellwig
2023-12-18  4:57 ` [PATCH 22/22] xfs: rename xfs_bmap_rtalloc to xfs_rtallocate_extent Christoph Hellwig
2023-12-18 22:24   ` Darrick J. Wong
2023-12-19  4:17     ` Christoph Hellwig
2023-12-19  4:51       ` Darrick J. Wong

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=20231218045738.711465-17-hch@lst.de \
    --to=hch@lst.de \
    --cc=chandan.babu@oracle.com \
    --cc=djwong@kernel.org \
    --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