Skip to contentSkip to conversation

mm/sparse: simplify the vmemmap alignment check

PATCH Superseded Kaitao Cheng 3 participants 4 messages Oct 28 – Oct 29

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/sparse: simplify the vmemmap alignment check

From: Kaitao Cheng <[email protected]>

sparse_init() is called only once during boot, and the vmemmap alignment check is outside any loop, so VM_WARN_ON_ONCE() provides no benefit over VM_WARN_ON() here.

Use VM_WARN_ON() and fold compound_info_has_mask() into its condition, preserving short-circuit evaluation.

---
 mm/sparse.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/sparse.c +2 -4
index 6acb628c8a73..248bee2d39b9 100644
@@ -277,10 +277,8 @@ static void __init sparse_metadata_init(void)
  */
 void __init sparse_init(void)
 {
-	if (compound_info_has_mask()) {
-		VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0),
-				    MAX_FOLIO_VMEMMAP_ALIGN));
-	}
+	VM_WARN_ON(compound_info_has_mask() && !IS_ALIGNED(
+		   (unsigned long)pfn_to_page(0), MAX_FOLIO_VMEMMAP_ALIGN));
 
 	sparse_metadata_init();
 	sparse_init_subsection_map();
Signature · 1 line
2.53.0
#1 lore raw
Quoted 9 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

sparse_init() is called only once during boot, and the vmemmap alignment check is outside any loop, so VM_WARN_ON_ONCE() provides no benefit over VM_WARN_ON() here.

Yes.

Quoted 14 lines

Use VM_WARN_ON() and fold compound_info_has_mask() into its condition, preserving short-circuit evaluation.

---
mm/sparse.c | 6 ++----

1 file changed, 2 insertions(+), 4 deletions(-)
mm/sparse.c +0 -0
index 6acb628c8a73..248bee2d39b9 100644

mm/sparse.c static void __init sparse_metadata_init(void) · line 280

Quoted 8 lines
mm/sparse.c +1 -4
@@ -277,10 +277,8 @@ static void __init sparse_metadata_init(void)
 */
 void __init sparse_init(void)
 {
- 	if (compound_info_has_mask()) {
- 		VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0),
-    				MAX_FOLIO_VMEMMAP_ALIGN));
- 	}
+ 	VM_WARN_ON(compound_info_has_mask() && !IS_ALIGNED(

We usually don't end with "(“. At least I rarely see that in the existing code. We can break the line after &&.

Thanks,
Muchun

Quoted 7 lines
mm/sparse.c +1 -0
+   		(unsigned long)pfn_to_page(0), MAX_FOLIO_VMEMMAP_ALIGN));
 
 sparse_metadata_init();
 sparse_init_subsection_map();
Signature · 1 line
2.53.0
reviewer
#2 lore raw
In reply to Kaitao Cheng

Hi,

Quoted 8 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

sparse_init() is called only once during boot, and the vmemmap alignment check is outside any loop, so VM_WARN_ON_ONCE() provides no benefit over VM_WARN_ON() here.

Use VM_WARN_ON() and fold compound_info_has_mask() into its condition, preserving short-circuit evaluation.

Do you think it's worth the churn?

Quoted 25 lines
---
 mm/sparse.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/sparse.c +2 -4
index 6acb628c8a73..248bee2d39b9 100644
@@ -277,10 +277,8 @@ static void __init sparse_metadata_init(void)
  */
 void __init sparse_init(void)
 {
-	if (compound_info_has_mask()) {
-		VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0),
-				    MAX_FOLIO_VMEMMAP_ALIGN));
-	}
+	VM_WARN_ON(compound_info_has_mask() && !IS_ALIGNED(
+		   (unsigned long)pfn_to_page(0), MAX_FOLIO_VMEMMAP_ALIGN));
 
 	sparse_metadata_init();
 	sparse_init_subsection_map();
Signature · 1 line
2.53.0
Signature · 2 lines
Sincerely yours,
Mike.
#3 lore raw
Quoted 5 lines · Mike Rapoport

Hi,

Quoted 2 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

Quoted 8 lines
Quoted 6 lines

sparse_init() is called only once during boot, and the vmemmap alignment check is outside any loop, so VM_WARN_ON_ONCE() provides no benefit over VM_WARN_ON() here.

Use VM_WARN_ON() and fold compound_info_has_mask() into its condition, preserving short-circuit evaluation.

Do you think it's worth the churn?

I think saving two lines of code is nice. It also eliminates a variable, even if only in debug kernels.

I’ll send a v2 following Muchun’s suggestion. If the consensus is that this change isn’t worth merging, please feel free to ignore this email.

Quoted 26 lines
Quoted 25 lines
---
 mm/sparse.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/sparse.c +2 -4
index 6acb628c8a73..248bee2d39b9 100644
@@ -277,10 +277,8 @@ static void __init sparse_metadata_init(void)
  */
 void __init sparse_init(void)
 {
-	if (compound_info_has_mask()) {
-		VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0),
-				    MAX_FOLIO_VMEMMAP_ALIGN));
-	}
+	VM_WARN_ON(compound_info_has_mask() && !IS_ALIGNED(
+		   (unsigned long)pfn_to_page(0), MAX_FOLIO_VMEMMAP_ALIGN));
 
 	sparse_metadata_init();
 	sparse_init_subsection_map();
Signature · 1 line
2.53.0
Signature · 2 lines
Thanks
Kaitao Cheng