Skip to contentSkip to conversation

xfs: replace min & max with clamp() in xfs_max_open_zones()

PATCH In review George Hu 4 participants 5 messages Jul 12, 2025 – Jul 15, 2025 XFS filesystem

lore
Share & tools
lore

George Hu

author
#0 lore raw

PATCH 1/1 xfs: replace min & max with clamp() in xfs_max_open_zones()

Refactor the xfs_max_open_zones() function by replacing the usage of min() and max() macro with clamp() to simplify the code and improve readability.

---
 fs/xfs/xfs_zone_alloc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/xfs/xfs_zone_alloc.c +1 -3
index 01315ed75502..58997afb1a14 100644
@@ -1133,9 +1133,7 @@ xfs_max_open_zones(
 	/*
 	 * Cap the max open limit to 1/4 of available space
 	 */
-	max_open = min(max_open, mp->m_sb.sb_rgcount / 4);
-
-	return max(XFS_MIN_OPEN_ZONES, max_open);
+	return clamp(max_open, XFS_MIN_OPEN_ZONES, mp->m_sb.sb_rgcount / 4);
 }
 
 /*
Signature · 1 line
2.50.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · George Hu

Refactor the xfs_max_open_zones() function by replacing the usage of min() and max() macro with clamp() to simplify the code and improve readability.

Nit: you can use up to 73 characters in each commit message line:

Refactor the xfs_max_open_zones() function by replacing the usage of min() and max() macro with clamp() to simplify the code and improve readability.

Otherwise looks good:

Reviewed-by on v1 1/1
#2 lore raw
In reply to George Hu
Quoted 5 lines · George Hu

Refactor the xfs_max_open_zones() function by replacing the usage of min() and max() macro with clamp() to simplify the code and improve readability.

FWIW,

fs/xfs/xfs_zone_alloc.c xfs_max_open_zones( · line 1135

Quoted 12 lines
---
  fs/xfs/xfs_zone_alloc.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
fs/xfs/xfs_zone_alloc.c +0 -0
index 01315ed75502..58997afb1a14 100644
@@ -1133,9 +1133,7 @@ xfs_max_open_zones(
  	/*
  	 * Cap the max open limit to 1/4 of available space
  	 */

Maybe you can keep this comment, but it was pretty much describing the code and not explaining the rationale.

Quoted 7 lines
fs/xfs/xfs_zone_alloc.c +1 -3
-	max_open = min(max_open, mp->m_sb.sb_rgcount / 4);
-
-	return max(XFS_MIN_OPEN_ZONES, max_open);
+	return clamp(max_open, XFS_MIN_OPEN_ZONES, mp->m_sb.sb_rgcount / 4);
  }
 
  /*
#3 lore raw
Quoted 7 lines · John Garry

fs/xfs/xfs_zone_alloc.c xfs_max_open_zones( · line 1135

Quoted 4 lines
fs/xfs/xfs_zone_alloc.c +0 -0
@@ -1133,9 +1133,7 @@ xfs_max_open_zones(
  	/*
  	 * Cap the max open limit to 1/4 of available space
  	 */

Maybe you can keep this comment, but it was pretty much describing the code and not explaining the rationale.

Let me send an incremental patch to explain the rational as long as I can still remember it :)

maintainer
#4 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · John Garry

fs/xfs/xfs_zone_alloc.c xfs_max_open_zones( · line 1135

Quoted 4 lines
fs/xfs/xfs_zone_alloc.c +0 -0
@@ -1133,9 +1133,7 @@ xfs_max_open_zones(
  	/*
  	 * Cap the max open limit to 1/4 of available space
  	 */

Maybe you can keep this comment, but it was pretty much describing the code and not explaining the rationale.

Let me send an incremental patch to explain the rational as long as I can still remember it :)

Sounds good, I'll wait and merge both together.

Quoted 2 lines