diff mbox series

[3/9] xfs: select the AG with the largest contiguous space

Message ID 20231004001943.349265-4-david@fromorbit.com (mailing list archive)
State New, archived
Headers show
Series xfs: push perags further into allocation routines | expand

Commit Message

Dave Chinner Oct. 4, 2023, 12:19 a.m. UTC
From: Dave Chinner <dchinner@redhat.com>

If we don't find an AG with sufficient contiguous free space for a
maxlen allocation, make sure we select the AG with the largest
contiguous free space to allocate from.

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

Comments

Christoph Hellwig Oct. 5, 2023, 9:45 a.m. UTC | #1
> +	if (max_blen > *blen) {
> +		if (max_blen_agno != startag) {
> +			ap->blkno = XFS_AGB_TO_FSB(mp, max_blen_agno, 0);
> +			ap->aeof = false;
> +		}
> +		*blen = max_blen;
> +	}

A comment based on the commit message on why we do this would be nice
here.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Christoph Hellwig Oct. 5, 2023, 9:46 a.m. UTC | #2
On Wed, Oct 04, 2023 at 11:19:37AM +1100, Dave Chinner wrote:
> +	if (max_blen > *blen) {
> +		if (max_blen_agno != startag) {
> +			ap->blkno = XFS_AGB_TO_FSB(mp, max_blen_agno, 0);
> +			ap->aeof = false;
> +		}
> +		*blen = max_blen;
> +	}

A comment explaining that we at least want the longest freespace
if no perfect match is available here would be useful to future
readers.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Darrick J. Wong Oct. 24, 2023, 4:25 p.m. UTC | #3
On Thu, Oct 05, 2023 at 02:46:18AM -0700, Christoph Hellwig wrote:
> On Wed, Oct 04, 2023 at 11:19:37AM +1100, Dave Chinner wrote:
> > +	if (max_blen > *blen) {
> > +		if (max_blen_agno != startag) {
> > +			ap->blkno = XFS_AGB_TO_FSB(mp, max_blen_agno, 0);
> > +			ap->aeof = false;
> > +		}
> > +		*blen = max_blen;
> > +	}
> 
> A comment explaining that we at least want the longest freespace
> if no perfect match is available here would be useful to future
> readers.

With Christoph's request for an extra comment added,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> 
> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index e64ba7e2d13d..ee1c1415c67a 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3233,6 +3233,8 @@  xfs_bmap_btalloc_select_lengths(
 	struct xfs_mount	*mp = args->mp;
 	struct xfs_perag	*pag;
 	xfs_agnumber_t		agno, startag;
+	xfs_agnumber_t		max_blen_agno;
+	xfs_extlen_t		max_blen = 0;
 	int			error = 0;
 
 	if (ap->tp->t_flags & XFS_TRANS_LOWMODE) {
@@ -3264,10 +3266,22 @@  xfs_bmap_btalloc_select_lengths(
 			}
 			break;
 		}
+		if (*blen > max_blen) {
+			max_blen = *blen;
+			max_blen_agno = agno;
+		}
 	}
 	if (pag)
 		xfs_perag_rele(pag);
 
+	if (max_blen > *blen) {
+		if (max_blen_agno != startag) {
+			ap->blkno = XFS_AGB_TO_FSB(mp, max_blen_agno, 0);
+			ap->aeof = false;
+		}
+		*blen = max_blen;
+	}
+
 	args->minlen = xfs_bmap_select_minlen(ap, args, *blen);
 	return error;
 }