Re: [PATCH 03/12] mm/sparse: move initialization of section metadata to sparse_metadata_init()
From: Lorenzo Stoakes (ARM)
Date: Thu Sep 10 2026 - 10:08:02 EST
On Wed, Sep 09, 2026 at 03:32:56PM +0200, David Hildenbrand (Arm) wrote:
> Let's move the code responsible for initializing sparse metadata (usemap,
> memmap) into a helper. Cleanup the variable while at it (e.g.,
> "map_count").
>
> Drop the rather obvious code comments.
>
> No functional change intended.
>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Similar comment to last, the move screws up the diff a bit, but staring at
git-delta it looks ok and the renames are good so:
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
> ---
> mm/sparse.c | 43 ++++++++++++++++++++++---------------------
> 1 file changed, 22 insertions(+), 21 deletions(-)
>
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 36e3d854febc5..a85a9c3840f6c 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -257,38 +257,39 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin,
> }
> }
>
> +static void __init sparse_metadata_init(void)
> +{
> + unsigned long start_section_nr = first_present_section_nr();
> + int nid_begin = sparse_early_nid(__nr_to_section(start_section_nr));
> + unsigned long section_nr, nr_sections = 1;
> +
> + for_each_present_section_nr(start_section_nr + 1, section_nr) {
> + const int nid = sparse_early_nid(__nr_to_section(section_nr));
> +
> + if (nid == nid_begin) {
> + nr_sections++;
> + continue;
> + }
> + sparse_init_nid(nid_begin, start_section_nr, section_nr, nr_sections);
> + nid_begin = nid;
> + start_section_nr = section_nr;
> + nr_sections = 1;
> + }
> + sparse_init_nid(nid_begin, start_section_nr, section_nr, nr_sections);
> +}
> +
> /*
> * Allocate the accumulated non-linear sections, allocate a mem_map
> * for each and record the physical to section mapping.
> */
> void __init sparse_init(void)
> {
> - unsigned long pnum_end, pnum_begin, map_count = 1;
> - int nid_begin;
> -
> if (compound_info_has_mask()) {
> VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0),
> MAX_FOLIO_VMEMMAP_ALIGN));
> }
>
> - pnum_begin = first_present_section_nr();
> - nid_begin = sparse_early_nid(__nr_to_section(pnum_begin));
> -
> - for_each_present_section_nr(pnum_begin + 1, pnum_end) {
> - int nid = sparse_early_nid(__nr_to_section(pnum_end));
> -
> - if (nid == nid_begin) {
> - map_count++;
> - continue;
> - }
> - /* Init node with sections in range [pnum_begin, pnum_end) */
> - sparse_init_nid(nid_begin, pnum_begin, pnum_end, map_count);
> - nid_begin = nid;
> - pnum_begin = pnum_end;
> - map_count = 1;
> - }
> - /* cover the last node */
> - sparse_init_nid(nid_begin, pnum_begin, pnum_end, map_count);
> + sparse_metadata_init();
> sparse_init_subsection_map();
> vmemmap_populate_print_last();
> }
>
> --
> 2.43.0
>
--
Cheers, Lorenzo