Skip to content

Commit e0f7422

Browse files
osandovDarrick J. Wong
authored andcommitted
xfs: don't look for end of extent further than necessary in xfs_rtallocate_extent_near()
As explained in the previous commit, xfs_rtallocate_extent_near() looks for the end of a free extent when searching backwards from the target bitmap block. Since the previous commit, it searches from the last bitmap block it checked to the bitmap block containing the start of the extent. This may still be more than necessary, since the free extent may not be that long. We know the maximum size of the free extent from the realtime summary. Use that to compute how many bitmap blocks we actually need to check. Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 85fa2c7 commit e0f7422

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,30 @@ xfs_rtallocate_extent_near(
527527
* On the negative side of the starting location.
528528
*/
529529
else { /* i < 0 */
530+
int maxblocks;
531+
532+
/*
533+
* Loop backwards to find the end of the extent
534+
* we found in the realtime summary.
535+
*
536+
* maxblocks is the maximum possible number of
537+
* bitmap blocks from the start of the extent
538+
* to the end of the extent.
539+
*/
540+
if (maxlog == 0)
541+
maxblocks = 0;
542+
else if (maxlog < mp->m_blkbit_log)
543+
maxblocks = 1;
544+
else
545+
maxblocks = 2 << (maxlog - mp->m_blkbit_log);
546+
530547
/*
531-
* Loop backwards through the bitmap blocks
532-
* from where we last checked down to where we
533-
* are now. There should be an extent which
534-
* ends in this bitmap block and is long
535-
* enough.
548+
* We need to check bbno + i + maxblocks down to
549+
* bbno + i. We already checked bbno down to
550+
* bbno + j + 1, so we don't need to check those
551+
* again.
536552
*/
553+
j = min(i + maxblocks, j);
537554
for (; j >= i; j--) {
538555
error = xfs_rtallocate_extent_block(args,
539556
bbno + j, minlen,

0 commit comments

Comments
 (0)