Skip to content

Commit ec5857b

Browse files
osandovDarrick J. Wong
authored andcommitted
xfs: limit maxlen based on available space in xfs_rtallocate_extent_near()
xfs_rtallocate_extent_near() calls xfs_rtallocate_extent_block() with the minlen and maxlen that were passed to it. xfs_rtallocate_extent_block() then scans the bitmap block looking for a free range of size maxlen. If there is none, it has to scan the whole bitmap block before returning the largest range of at least size minlen. For a fragmented realtime device and a large allocation request, it's almost certain that this will have to search the whole bitmap block, leading to high CPU usage. However, the realtime summary tells us the maximum size available in the bitmap block. We can limit the search in xfs_rtallocate_extent_block() to that size and often stop before scanning the whole bitmap block. 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 1b5d639 commit ec5857b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ xfs_rtallocate_extent_near(
497497
* allocating one.
498498
*/
499499
if (maxlog >= 0) {
500+
xfs_extlen_t maxavail =
501+
min_t(xfs_rtblock_t, maxlen,
502+
(1ULL << (maxlog + 1)) - 1);
500503
/*
501504
* On the positive side of the starting location.
502505
*/
@@ -506,7 +509,7 @@ xfs_rtallocate_extent_near(
506509
* this block.
507510
*/
508511
error = xfs_rtallocate_extent_block(args,
509-
bbno + i, minlen, maxlen, len,
512+
bbno + i, minlen, maxavail, len,
510513
&n, prod, &r);
511514
if (error) {
512515
return error;
@@ -553,7 +556,7 @@ xfs_rtallocate_extent_near(
553556
continue;
554557
error = xfs_rtallocate_extent_block(args,
555558
bbno + j, minlen,
556-
maxlen, len, &n, prod,
559+
maxavail, len, &n, prod,
557560
&r);
558561
if (error) {
559562
return error;
@@ -575,7 +578,7 @@ xfs_rtallocate_extent_near(
575578
* that we found.
576579
*/
577580
error = xfs_rtallocate_extent_block(args,
578-
bbno + i, minlen, maxlen, len,
581+
bbno + i, minlen, maxavail, len,
579582
&n, prod, &r);
580583
if (error) {
581584
return error;

0 commit comments

Comments
 (0)