Re: [PATCH 08/43] xfs: reflow xfs_dec_freecounter

Darrick J. Wong
2025-02-06T20:14:54Z

On Thu, Feb 06, 2025 at 07:44:24AM +0100, Christoph Hellwig wrote:
> Let the successful allocation be the main path through the function
> with exception handling in branches to make the code easier to
> follow.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks ok,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
> fs/xfs/xfs_mount.c | 37 +++++++++++++++++++------------------
> 1 file changed, 19 insertions(+), 18 deletions(-)
>
> diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
> index 26793d4f2707..65123f4ffc2a 100644
> --- a/fs/xfs/xfs_mount.c
> +++ b/fs/xfs/xfs_mount.c
> @@ -1329,28 +1329,29 @@ xfs_dec_freecounter(
> set_aside = xfs_freecounter_unavailable(mp, ctr);
> percpu_counter_add_batch(counter, -((int64_t)delta), batch);
> if (__percpu_counter_compare(counter, set_aside,
> - XFS_FDBLOCKS_BATCH) >= 0) {
> - /* we had space! */
> - return 0;
> - }
> -
> - /*
> - * lock up the sb for dipping into reserves before releasing the space
> - * that took us to ENOSPC.
> - */
> - spin_lock(&mp->m_sb_lock);
> - percpu_counter_add(counter, delta);
> - if (!rsvd)
> - goto fdblocks_enospc;
> + XFS_FDBLOCKS_BATCH) < 0) {
> + /*
> + * Lock up the sb for dipping into reserves before releasing the
> + * space that took us to ENOSPC.
> + */
> + spin_lock(&mp->m_sb_lock);
> + percpu_counter_add(counter, delta);
> + if (!rsvd)
> + goto fdblocks_enospc;
> +
> + lcounter = (long long)mp->m_resblks[ctr].avail - delta;
> + if (lcounter < 0) {
> + xfs_warn_once(mp,
> +"Reserve blocks depleted! Consider increasing reserve pool size.");
> + goto fdblocks_enospc;
> + }
>
> - lcounter = (long long)mp->m_resblks[ctr].avail - delta;
> - if (lcounter >= 0) {
> mp->m_resblks[ctr].avail = lcounter;
> spin_unlock(&mp->m_sb_lock);
> - return 0;
> }
> - xfs_warn_once(mp,
> -"Reserve blocks depleted! Consider increasing reserve pool size.");
> +
> + /* we had space! */
> + return 0;
>
> fdblocks_enospc:
> spin_unlock(&mp->m_sb_lock);
> --
> 2.45.2
>
>