Skip to contentSkip to conversation

xfs: Simplify maximum determination in xrep_calc_ag_resblks()

PATCH In review Markus Elfring 2 participants 4 messages Mar 1, 2025 – Apr 30, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: Simplify maximum determination in xrep_calc_ag_resblks()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Mar 2025 11:24:52 +0100

Reduce nested max() calls by a single max3() call in this function implementation.

The source code was transformed by using the Coccinelle software.

---
 fs/xfs/scrub/repair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/repair.c +1 -1
index 3b5288d3ef4e..6b23a3943907 100644
@@ -382,7 +382,7 @@ xrep_calc_ag_resblks(
 			refcbt_sz);
 	xfs_perag_put(pag);
 
-	return max(max(bnobt_sz, inobt_sz), max(rmapbt_sz, refcbt_sz));
+	return max3(bnobt_sz, inobt_sz, max(rmapbt_sz, refcbt_sz));
 }
 
 #ifdef CONFIG_XFS_RT

--
2.48.1

maintainer
#1 lore raw
Quoted 18 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 1 Mar 2025 11:24:52 +0100

Reduce nested max() calls by a single max3() call in this function implementation.

The source code was transformed by using the Coccinelle software.

---
 fs/xfs/scrub/repair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/repair.c +0 -0
index 3b5288d3ef4e..6b23a3943907 100644

fs/xfs/scrub/repair.c xrep_calc_ag_resblks( · line 385

Quoted 5 lines
fs/xfs/scrub/repair.c +1 -1
@@ -382,7 +382,7 @@ xrep_calc_ag_resblks(
 			refcbt_sz);
 	xfs_perag_put(pag);
 
-	return max(max(bnobt_sz, inobt_sz), max(rmapbt_sz, refcbt_sz));
+	return max3(bnobt_sz, inobt_sz, max(rmapbt_sz, refcbt_sz));

I have nothing against the patch itself, but honestly I don't see how it improves anything. It boils down to nesting comparison instructions too, and doesn't make the code more clear IMHO.
So, unless somebody else has a stronger reason to have this change, NAK from my side.

Carlos

Quoted 6 lines
fs/xfs/scrub/repair.c +0 -1
 }
 
 #ifdef CONFIG_XFS_RT
--

2.48.1

#2 lore raw

…

Quoted 5 lines
Quoted 5 lines

+++ b/fs/xfs/scrub/repair.c

fs/xfs/scrub/repair.c +0 -0
@@ -382,7 +382,7 @@ xrep_calc_ag_resblks(
 			refcbt_sz);
 	xfs_perag_put(pag);
 
Quoted 7 lines

fs/xfs/scrub/repair.c xrep_calc_ag_resblks( · line 385

Quoted 2 lines
fs/xfs/scrub/repair.c +1 -1
-	return max(max(bnobt_sz, inobt_sz), max(rmapbt_sz, refcbt_sz));
+	return max3(bnobt_sz, inobt_sz, max(rmapbt_sz, refcbt_sz));

I have nothing against the patch itself, but honestly I don't see how it improves anything. It boils down to nesting comparison instructions too, and doesn't make the code more clear IMHO.
So, unless somebody else has a stronger reason to have this change, NAK from my side.

Would you be looking for a wrapper call variant like max4()?

Regards,
Markus

maintainer
#3 lore raw
Quoted 6 lines · Markus Elfring

…

Quoted 5 lines
Quoted 5 lines

+++ b/fs/xfs/scrub/repair.c

fs/xfs/scrub/repair.c +0 -0
@@ -382,7 +382,7 @@ xrep_calc_ag_resblks(
 			refcbt_sz);
 	xfs_perag_put(pag);
 
Quoted 8 lines
Quoted 7 lines

fs/xfs/scrub/repair.c xrep_calc_ag_resblks( · line 385

Quoted 2 lines
fs/xfs/scrub/repair.c +1 -1
-	return max(max(bnobt_sz, inobt_sz), max(rmapbt_sz, refcbt_sz));
+	return max3(bnobt_sz, inobt_sz, max(rmapbt_sz, refcbt_sz));

I have nothing against the patch itself, but honestly I don't see how it improves anything. It boils down to nesting comparison instructions too, and doesn't make the code more clear IMHO.
So, unless somebody else has a stronger reason to have this change, NAK from my side.

Would you be looking for a wrapper call variant like max4()?

I have no preference really, between a max(max(), max()) and a max4(a, b, c, d), the latter is a tad easier to the eyes, if it's worth adding a new max() macro for that, it's another thing. Although a quick search on the source code returned returned several usages of the max(max3(a,b,c), d) patterns, so I think indeed the kernel could benefit of a max4() :)

Quoted 3 lines

Regards,
Markus