Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/sparse: simplify the vmemmap alignment check
@ 2026-10-28 12:11 Kaitao Cheng
  2026-10-28 13:05 ` Muchun Song
  2026-10-28 16:08 ` Mike Rapoport
  0 siblings, 2 replies; 3+ messages in thread
From: Kaitao Cheng @ 2026-10-28 12:11 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Muchun Song, linux-mm,
	linux-kernel, Kaitao Cheng

From: Kaitao Cheng <chengkaitao@kylinos.cn>

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.

Signed-off-by: Kaitao Cheng <chengkaitao@kylinos.cn>
---
 mm/sparse.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index 6acb628c8a73..248bee2d39b9 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -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();
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/sparse: simplify the vmemmap alignment check
  2026-10-28 12:11 [PATCH] mm/sparse: simplify the vmemmap alignment check Kaitao Cheng
@ 2026-10-28 13:05 ` Muchun Song
  2026-10-28 16:08 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Muchun Song @ 2026-10-28 13:05 UTC (permalink / raw)
  To: Kaitao Cheng
  Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	Kaitao Cheng



> On Oct 28, 2026, at 20:11, Kaitao Cheng <kaitao.cheng@linux.dev> wrote:
> 
> From: Kaitao Cheng <chengkaitao@kylinos.cn>
> 
> 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.

> 
> Use VM_WARN_ON() and fold compound_info_has_mask() into its condition,
> preserving short-circuit evaluation.
> 
> Signed-off-by: Kaitao Cheng <chengkaitao@kylinos.cn>
> ---
> mm/sparse.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 6acb628c8a73..248bee2d39b9 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -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

> +   		(unsigned long)pfn_to_page(0), MAX_FOLIO_VMEMMAP_ALIGN));
> 
> sparse_metadata_init();
> sparse_init_subsection_map();
> -- 
> 2.53.0
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/sparse: simplify the vmemmap alignment check
  2026-10-28 12:11 [PATCH] mm/sparse: simplify the vmemmap alignment check Kaitao Cheng
  2026-10-28 13:05 ` Muchun Song
@ 2026-10-28 16:08 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2026-10-28 16:08 UTC (permalink / raw)
  To: Kaitao Cheng
  Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan,
	Michal Hocko, Muchun Song, linux-mm, linux-kernel, Kaitao Cheng

Hi,

On Wed, Oct 28, 2026 at 08:11:29PM +0800, Kaitao Cheng wrote:
> From: Kaitao Cheng <chengkaitao@kylinos.cn>
> 
> 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?
 
> Signed-off-by: Kaitao Cheng <chengkaitao@kylinos.cn>
> ---
>  mm/sparse.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 6acb628c8a73..248bee2d39b9 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -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();
> -- 
> 2.53.0
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-28 16:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 12:11 [PATCH] mm/sparse: simplify the vmemmap alignment check Kaitao Cheng
2026-10-28 13:05 ` Muchun Song
2026-10-28 16:08 ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox