xfs: don't try redundant allocations in xfs_rtallocate_extent_near()
authorOmar Sandoval <osandov@fb.com>
Mon, 16 Oct 2023 17:47:04 +0000 (10:47 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 19 Oct 2023 15:34:33 +0000 (08:34 -0700)
commit85fa2c774397b98f5dc65a4ed6ab17c1a15db158
tree5aab3c63b54251147f7b9e0275d4a5b59919a367
parentec5857bf07639a03d32b8ecb346df634925f8bc2
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>
fs/xfs/xfs_rtalloc.c