[PATCH v2 13/15] mm/sparse: move sparse_init_one_section() to internal.h
David Hildenbrand (Arm)
david at kernel.org
Mon Mar 23 01:49:11 PDT 2026
On 3/20/26 23:13, David Hildenbrand (Arm) wrote:
> While at it, convert the BUG_ON to a VM_WARN_ON_ONCE, avoid long lines, and
> merge sparse_encode_mem_map() into its only caller
> sparse_init_one_section().
>
> Clarify the comment a bit, pointing at page_to_pfn().
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs at kernel.org>
> Reviewed-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
> Signed-off-by: David Hildenbrand (Arm) <david at kernel.org>
> ---
> include/linux/mmzone.h | 2 +-
> mm/internal.h | 22 ++++++++++++++++++++++
> mm/sparse.c | 24 ------------------------
> 3 files changed, 23 insertions(+), 25 deletions(-)
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index b694c69dee04..dcbbf36ed88c 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -2008,7 +2008,7 @@ struct mem_section {
> /*
> * This is, logically, a pointer to an array of struct
> * pages. However, it is stored with some other magic.
> - * (see sparse.c::sparse_init_one_section())
> + * (see sparse_init_one_section())
> *
> * Additionally during early boot we encode node id of
> * the location of the section here to guide allocation.
> diff --git a/mm/internal.h b/mm/internal.h
> index 5f5c45d80aca..2f188f7702f7 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -965,6 +965,28 @@ void memmap_init_range(unsigned long, int, unsigned long, unsigned long,
> */
> #ifdef CONFIG_SPARSEMEM
> void sparse_init(void);
> +
> +static inline void sparse_init_one_section(struct mem_section *ms,
> + unsigned long pnum, struct page *mem_map,
> + struct mem_section_usage *usage, unsigned long flags)
> +{
> + unsigned long coded_mem_map;
> +
> + BUILD_BUG_ON(SECTION_MAP_LAST_BIT > PFN_SECTION_SHIFT);
> +
> + /*
> + * We encode the start PFN of the section into the mem_map such that
> + * page_to_pfn() on !CONFIG_SPARSEMEM_VMEMMAP can simply subtract it
> + * from the page pointer to obtain the PFN.
> + */
> + coded_mem_map = (unsigned long)(mem_map - section_nr_to_pfn(pnum));
> + VM_WARN_ON(coded_mem_map & ~SECTION_MAP_MASK);
> +
> + ms->section_mem_map &= ~SECTION_MAP_MASK;
> + ms->section_mem_map |= coded_mem_map;
> + ms->section_mem_map |= flags | SECTION_HAS_MEM_MAP;
> + ms->usage = usage;
The following fixup on top:
>From 66ec42c610feb3b84c405222f3f39ba0776549c6 Mon Sep 17 00:00:00 2001
From: "David Hildenbrand (Arm)" <david at kernel.org>
Date: Mon, 23 Mar 2026 09:48:21 +0100
Subject: [PATCH] fixup: mm/sparse: move sparse_init_one_section() to
internal.h
Signed-off-by: David Hildenbrand (Arm) <david at kernel.org>
---
mm/internal.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/internal.h b/mm/internal.h
index 2f188f7702f7..969e58e5b3db 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -980,7 +980,7 @@ static inline void sparse_init_one_section(struct mem_section *ms,
* from the page pointer to obtain the PFN.
*/
coded_mem_map = (unsigned long)(mem_map - section_nr_to_pfn(pnum));
- VM_WARN_ON(coded_mem_map & ~SECTION_MAP_MASK);
+ VM_WARN_ON_ONCE(coded_mem_map & ~SECTION_MAP_MASK);
ms->section_mem_map &= ~SECTION_MAP_MASK;
ms->section_mem_map |= coded_mem_map;
--
2.43.0
--
Cheers,
David
More information about the linux-riscv
mailing list