xfs: avoid unnecessary calculations in xfs_zoned_need_gc()

If zonegc_low_space is set to zero (which is the default), the second
condition in xfs_zoned_need_gc() that triggers GC never evaluates to
true because the calculated threshold will always be 0. So there is no
need to calculate the threshold and to evaluate that condition. Return
early when zonegc_low_space is zero.

While at it, add comments to document the intent of each of the 3 tests
used to determine the return value to control the execution of garbage
collection.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
This commit is contained in:
Damien Le Moal
2026-03-16 20:40:20 +09:00
committed by Carlos Maiolino
parent 68aa101bf2
commit c1f9554374

View File

@@ -171,25 +171,37 @@ xfs_zoned_need_gc(
s64 available, free, threshold;
s32 remainder;
/* If we have no reclaimable blocks, running GC is useless. */
if (!xfs_zoned_have_reclaimable(mp->m_zone_info))
return false;
/*
* In order to avoid file fragmentation as much as possible, we should
* make sure that we can open enough zones. So trigger GC if the number
* of blocks immediately available for writes is lower than the total
* number of blocks from all possible open zones.
*/
available = xfs_estimate_freecounter(mp, XC_FREE_RTAVAILABLE);
if (available <
xfs_rtgs_to_rfsbs(mp, mp->m_max_open_zones - XFS_OPEN_GC_ZONES))
return true;
free = xfs_estimate_freecounter(mp, XC_FREE_RTEXTENTS);
/*
* For cases where the user wants to be more aggressive with GC,
* the sysfs attribute zonegc_low_space may be set to a non zero value,
* to indicate that GC should try to maintain at least zonegc_low_space
* percent of the free space to be directly available for writing. Check
* this here.
*/
if (!mp->m_zonegc_low_space)
return false;
free = xfs_estimate_freecounter(mp, XC_FREE_RTEXTENTS);
threshold = div_s64_rem(free, 100, &remainder);
threshold = threshold * mp->m_zonegc_low_space +
remainder * div_s64(mp->m_zonegc_low_space, 100);
if (available < threshold)
return true;
return false;
return available < threshold;
}
static struct xfs_zone_gc_data *