mm/sparse: simplify the vmemmap alignment check
Subsystems (2)
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
@@ -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
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, soVM_WARN_ON_ONCE()provides no benefit overVM_WARN_ON()here.
Yes.
Quoted 14 lines
Use
VM_WARN_ON()and foldcompound_info_has_mask()into its condition, preserving short-circuit evaluation.Signed-off-by Kaitao Cheng <[email protected]>---
mm/sparse.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)mm/sparse.c +0
-0
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
Mike Rapoport
reviewerHi,
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, soVM_WARN_ON_ONCE()provides no benefit overVM_WARN_ON()here.Use
VM_WARN_ON()and foldcompound_info_has_mask()into its condition, preserving short-circuit evaluation.
Do you think it's worth the churn?
Quoted 25 lines
Signed-off-by Kaitao Cheng <[email protected]>--- mm/sparse.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)mm/sparse.c +2
-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 ( + (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.
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, soVM_WARN_ON_ONCE()provides no benefit overVM_WARN_ON()here.Use
VM_WARN_ON()and foldcompound_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
Signed-off-by Kaitao Cheng <[email protected]>--- mm/sparse.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)mm/sparse.c +2
-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 ( + (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