Commit ec5857bf authored by Omar Sandoval's avatar Omar Sandoval Committed by Darrick J. Wong

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: default avatarOmar Sandoval <osandov@fb.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 1b5d6396
......@@ -497,6 +497,9 @@ xfs_rtallocate_extent_near(
* allocating one.
*/
if (maxlog >= 0) {
xfs_extlen_t maxavail =
min_t(xfs_rtblock_t, maxlen,
(1ULL << (maxlog + 1)) - 1);
/*
* On the positive side of the starting location.
*/
......@@ -506,7 +509,7 @@ xfs_rtallocate_extent_near(
* this block.
*/
error = xfs_rtallocate_extent_block(args,
bbno + i, minlen, maxlen, len,
bbno + i, minlen, maxavail, len,
&n, prod, &r);
if (error) {
return error;
......@@ -553,7 +556,7 @@ xfs_rtallocate_extent_near(
continue;
error = xfs_rtallocate_extent_block(args,
bbno + j, minlen,
maxlen, len, &n, prod,
maxavail, len, &n, prod,
&r);
if (error) {
return error;
......@@ -575,7 +578,7 @@ xfs_rtallocate_extent_near(
* that we found.
*/
error = xfs_rtallocate_extent_block(args,
bbno + i, minlen, maxlen, len,
bbno + i, minlen, maxavail, len,
&n, prod, &r);
if (error) {
return error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment