Skip to content

Commit c1f9554

Browse files
damien-lemoalcmaiolino
authored andcommitted
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>
1 parent 68aa101 commit c1f9554

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

fs/xfs/xfs_zone_gc.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,37 @@ xfs_zoned_need_gc(
171171
s64 available, free, threshold;
172172
s32 remainder;
173173

174+
/* If we have no reclaimable blocks, running GC is useless. */
174175
if (!xfs_zoned_have_reclaimable(mp->m_zone_info))
175176
return false;
176177

178+
/*
179+
* In order to avoid file fragmentation as much as possible, we should
180+
* make sure that we can open enough zones. So trigger GC if the number
181+
* of blocks immediately available for writes is lower than the total
182+
* number of blocks from all possible open zones.
183+
*/
177184
available = xfs_estimate_freecounter(mp, XC_FREE_RTAVAILABLE);
178-
179185
if (available <
180186
xfs_rtgs_to_rfsbs(mp, mp->m_max_open_zones - XFS_OPEN_GC_ZONES))
181187
return true;
182188

183-
free = xfs_estimate_freecounter(mp, XC_FREE_RTEXTENTS);
189+
/*
190+
* For cases where the user wants to be more aggressive with GC,
191+
* the sysfs attribute zonegc_low_space may be set to a non zero value,
192+
* to indicate that GC should try to maintain at least zonegc_low_space
193+
* percent of the free space to be directly available for writing. Check
194+
* this here.
195+
*/
196+
if (!mp->m_zonegc_low_space)
197+
return false;
184198

199+
free = xfs_estimate_freecounter(mp, XC_FREE_RTEXTENTS);
185200
threshold = div_s64_rem(free, 100, &remainder);
186201
threshold = threshold * mp->m_zonegc_low_space +
187202
remainder * div_s64(mp->m_zonegc_low_space, 100);
188203

189-
if (available < threshold)
190-
return true;
191-
192-
return false;
204+
return available < threshold;
193205
}
194206

195207
static struct xfs_zone_gc_data *

0 commit comments

Comments
 (0)