Re: [PATCH] xfs: keep successful near rt allocations
From: Carlos Maiolino
Date: Wed Nov 04 2026 - 10:46:19 EST
On Wed, Nov 04, 2026 at 10:01:15AM -0500, Rik van Riel wrote:
> XFS realtime allocations first attempt to allocate space near where
> other parts of a file already are. If that allocation succeeds, it
> does not have to do a global search for free space.
>
> Unfortunately, a code cleanup a while ago causes xfs_rtallocate_rtg
> to unconditionally do the global search, even when the search for a
> nearby extent has succeeded.
>
> Fix it by running the global search only when the near search did
> not find available space.
>
> Found by noticing higher kernel CPU use and examining the profile.
>
> Fixes: fd048a1bb391d ("xfs: rework the rtalloc fallback handling")
> Cc: stable@xxxxxxxxxxxxxxx # v6.12
> Reported-by: Christian Andres Saide <csaide@xxxxxxxx>
> Signed-off-by: Rik van Riel <riel@xxxxxxxxxxx>
This sounds correct yes.
Reviewed-by: Carlos Maiolino <cmaiolino@xxxxxxxxxx>
> ---
> fs/xfs/xfs_rtalloc.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
> index 84efe5a8fb11..31d90828b4e9 100644
> --- a/fs/xfs/xfs_rtalloc.c
> +++ b/fs/xfs/xfs_rtalloc.c
> @@ -1997,10 +1997,14 @@ xfs_rtallocate_rtg(
> if (error == -ENOSPC) {
> xfs_rtbuf_cache_relse(&args);
> error = 0;
> + start = 0;
> }
> }
>
> - if (!error) {
> + /*
> + * Global search, runs when the near search did not find space.
> + */
> + if (!error && !start) {
> error = xfs_rtallocate_extent_size(&args, minlen, maxlen, &len,
> prod, &rtx);
> }
> --
> 2.56.0
>
>