XFS: fix zoned gc threshold math for 32-bit arches
[email protected]
maintainerPATCH 1/1 XFS: fix zoned gc threshold math for 32-bit arches
From: Carlos Maiolino <[email protected]>
xfs_zoned_need_gc makes use of mult_frac() to calculate the threshold for triggering the zoned garbage collector, but, turns out mult_frac() doesn't properly work with 64-bit data types and this caused build failures on some 32-bit architectures.
Fix this by essentially open coding mult_frac() in a 64-bit friendly way.
Notice we don't need to bother with counters underflow here because xfs_estimate_freecounter() will always return a positive value, as it leverages percpu_counter_read_positive to read such counters.
---
fs/xfs/xfs_zone_gc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/xfs/xfs_zone_gc.c +7 -1
@@ -171,6 +171,7 @@ xfs_zoned_need_gc( struct xfs_mount *mp) {s64 available, free; +s32 threshold, remainder;if (!xfs_group_marked (mp,XG_TYPE_RTG ,XFS_RTG_RECLAIMABLE ))return false;
@@ -183,7 +184,12 @@ xfs_zoned_need_gc(return true; free =xfs_estimate_freecounter (mp,XC_FREE_RTEXTENTS ); -if (available <mult_frac (free, mp->m_zonegc_low_space,100 )) + + 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;
Signature · 1 line
2.49.0
Quoted 36 lines · On 22/04/2025 13:42, [email protected] wrote:
From: Carlos Maiolino <[email protected]>
xfs_zoned_need_gcmakes use ofmult_frac()to calculate the threshold for triggering the zoned garbage collector, but, turns outmult_frac()doesn't properly work with 64-bit data types and this caused build failures on some 32-bit architectures.Fix this by essentially open coding
mult_frac()in a 64-bit friendly way.Notice we don't need to bother with counters underflow here because
xfs_estimate_freecounter()will always return a positive value, as it leveragespercpu_counter_read_positiveto read such counters.Fixes 845abeb1f06a ("xfs: add tunable threshold parameter for triggering zone GC")Reported-by kernel test robot <[email protected]>Signed-off-by Carlos Maiolino <[email protected]>---
fs/xfs/xfs_zone_gc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/xfs/xfs_zone_gc.c +1
-0@@ -171,6 +171,7 @@ xfs_zoned_need_gc( struct xfs_mount *mp) {s64 available, free; +s32 threshold, remainder;if (!xfs_group_marked (mp,XG_TYPE_RTG ,XFS_RTG_RECLAIMABLE ))return false;
fs/xfs/xfs_zone_gc.c xfs_zoned_need_gc( · line 188
Quoted 6 lines
fs/xfs/xfs_zone_gc.c +2
-1@@ -183,7 +184,12 @@ xfs_zoned_need_gc(return true; free =xfs_estimate_freecounter (mp,XC_FREE_RTEXTENTS ); -if (available <mult_frac (free, mp->m_zonegc_low_space,100 )) + + threshold =div_s64_rem (free,100 , &remainder);
Hmm, shouldn't threshold be a s64?
Quoted 7 lines
fs/xfs/xfs_zone_gc.c +4
-0+ threshold = threshold * mp->m_zonegc_low_space + + remainder *div_s64 (mp->m_zonegc_low_space,100 ); + +if (available < threshold)return true;return false;
Carlos Maiolino
maintainerQuoted 39 lines · Hans Holmberg
Quoted 38 lines · On 22/04/2025 13:42, [email protected] wrote:
From: Carlos Maiolino <[email protected]>
xfs_zoned_need_gcmakes use ofmult_frac()to calculate the threshold for triggering the zoned garbage collector, but, turns outmult_frac()doesn't properly work with 64-bit data types and this caused build failures on some 32-bit architectures.Fix this by essentially open coding
mult_frac()in a 64-bit friendly way.Notice we don't need to bother with counters underflow here because
xfs_estimate_freecounter()will always return a positive value, as it leveragespercpu_counter_read_positiveto read such counters.Fixes 845abeb1f06a ("xfs: add tunable threshold parameter for triggering zone GC")Reported-by kernel test robot <[email protected]>Signed-off-by Carlos Maiolino <[email protected]>---
fs/xfs/xfs_zone_gc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/xfs/xfs_zone_gc.c +1
-0@@ -171,6 +171,7 @@ xfs_zoned_need_gc( struct xfs_mount *mp) {s64 available, free; +s32 threshold, remainder;if (!xfs_group_marked (mp,XG_TYPE_RTG ,XFS_RTG_RECLAIMABLE ))return false;@@ -183,7 +184,12 @@ xfs_zoned_need_gc(return true;
Quoted 6 lines
fs/xfs/xfs_zone_gc.c xfs_zoned_need_gc( · line 188
Quoted 4 lines
fs/xfs/xfs_zone_gc.c +2
-1free =xfs_estimate_freecounter (mp,XC_FREE_RTEXTENTS ); -if (available <mult_frac (free, mp->m_zonegc_low_space,100 )) + + threshold =div_s64_rem (free,100 , &remainder);Hmm, shouldn't threshold be a s64?
Uff, yes, I wrote it to use as a divisor initially, changed my mind and forgot to fix the definition. I'll send a V2, thanks for spotting it. Only remainder must be a s32.
Quoted 10 lines
Quoted 8 lines
fs/xfs/xfs_zone_gc.c +4
-0+ threshold = threshold * mp->m_zonegc_low_space + + remainder *div_s64 (mp->m_zonegc_low_space,100 ); + +if (available < threshold)return true;return false;