Skip to contentSkip to conversation

XFS: fix zoned gc threshold math for 32-bit arches

PATCH Applied [email protected] 4 participants 5 messages Apr 22, 2025 XFS filesystem

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH v2 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.

Fixes 845abeb1f06a ("xfs: add tunable threshold parameter for triggering zone GC")

---
V2:
- threshold should be a s64, not s32

 fs/xfs/xfs_zone_gc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/xfs/xfs_zone_gc.c +8 -2
index 8c541ca71872..81c94dd1d596 100644
@@ -170,7 +170,8 @@ bool
 xfs_zoned_need_gc(
 	struct xfs_mount	*mp)
 {
-	s64			available, free;
+	s64			available, free, threshold;
+	s32			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
Reviewed-by on v2 1/1
#1 lore raw
Quoted 43 lines · On 22/04/2025 14:55, [email protected] wrote:

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.

Fixes 845abeb1f06a ("xfs: add tunable threshold parameter for triggering zone GC")

---
V2:
- threshold should be a s64, not s32

 fs/xfs/xfs_zone_gc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/xfs/xfs_zone_gc.c +2 -1
index 8c541ca71872..81c94dd1d596 100644
@@ -170,7 +170,8 @@ bool
 xfs_zoned_need_gc(
 	struct xfs_mount	*mp)
 {
-	s64			available, free;
+	s64			available, free, threshold;
+	s32			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);

fs/xfs/xfs_zone_gc.c xfs_zoned_need_gc( · line 195

Quoted 10 lines
fs/xfs/xfs_zone_gc.c +6 -1
-	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;

Thanks for fixing this up!

Tested-by on v2 1/1
#3 lore raw
In reply to [email protected]
Quoted 10 lines · On 4/22/25 05:54, [email protected] wrote:

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.

Quoted 8 lines

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.

Fixes 845abeb1f06a ("xfs: add tunable threshold parameter for triggering zone GC")

Succesfully built openrisc:allmodconfig and parisc:allmodconfig with gcc 13.3.

Guenter

author maintainer Applied
#4 lore raw
In reply to [email protected]
Quoted 9 lines · On Tue, 22 Apr 2025 14:54:54 +0200, [email protected] wrote:

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.

[...]

Applied to for-next, thanks!

[1/1] XFS: fix zoned gc threshold math for 32-bit arches

      commit: bd7c19331913b955a7823e6315ca16bbcc65aeff

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>