Skip to content

Commit 85fa2c7

Browse files
osandovDarrick J. Wong
authored andcommitted
xfs: don't try redundant allocations in xfs_rtallocate_extent_near()
xfs_rtallocate_extent_near() tries to find a free extent as close to a target bitmap block given by bbno as possible, which may be before or after bbno. Searching backwards has a complication: the realtime summary accounts for free space _starting_ in a bitmap block, but not straddling or ending in a bitmap block. So, when the negative search finds a free extent in the realtime summary, in order to end up closer to the target, it looks for the end of the free extent. For example, if bbno - 2 has a free extent, then it will check bbno - 1, then bbno - 2. But then if bbno - 3 has a free extent, it will check bbno - 1 again, then bbno - 2 again, and then bbno - 3. This results in a quadratic loop, which is completely pointless since the repeated checks won't find anything new. Fix it by remembering where we last checked up to and continue from there. This also obviates the need for a check of the realtime summary. Signed-off-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent ec5857b commit 85fa2c7

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ xfs_rtallocate_extent_near(
477477
}
478478
bbno = xfs_rtx_to_rbmblock(mp, start);
479479
i = 0;
480+
j = -1;
480481
ASSERT(minlen != 0);
481482
log2len = xfs_highbit32(minlen);
482483
/*
@@ -527,33 +528,13 @@ xfs_rtallocate_extent_near(
527528
*/
528529
else { /* i < 0 */
529530
/*
530-
* Loop backwards through the bitmap blocks from
531-
* the starting point-1 up to where we are now.
532-
* There should be an extent which ends in this
533-
* bitmap block and is long enough.
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.
534536
*/
535-
for (j = -1; j > i; j--) {
536-
/*
537-
* Grab the summary information for
538-
* this bitmap block.
539-
*/
540-
error = xfs_rtany_summary(args,
541-
log2len,
542-
mp->m_rsumlevels - 1,
543-
bbno + j, &maxlog);
544-
if (error) {
545-
return error;
546-
}
547-
/*
548-
* If there's no extent given in the
549-
* summary that means the extent we
550-
* found must carry over from an
551-
* earlier block. If there is an
552-
* extent given, we've already tried
553-
* that allocation, don't do it again.
554-
*/
555-
if (maxlog >= 0)
556-
continue;
537+
for (; j >= i; j--) {
557538
error = xfs_rtallocate_extent_block(args,
558539
bbno + j, minlen,
559540
maxavail, len, &n, prod,
@@ -569,27 +550,6 @@ xfs_rtallocate_extent_near(
569550
return 0;
570551
}
571552
}
572-
/*
573-
* There weren't intervening bitmap blocks
574-
* with a long enough extent, or the
575-
* allocation didn't work for some reason
576-
* (i.e. it's a little * too short).
577-
* Try to allocate from the summary block
578-
* that we found.
579-
*/
580-
error = xfs_rtallocate_extent_block(args,
581-
bbno + i, minlen, maxavail, len,
582-
&n, prod, &r);
583-
if (error) {
584-
return error;
585-
}
586-
/*
587-
* If it works, return the extent.
588-
*/
589-
if (r != NULLRTEXTNO) {
590-
*rtx = r;
591-
return 0;
592-
}
593553
}
594554
}
595555
/*

0 commit comments

Comments
 (0)