Re: [PATCH v2 04/14] mm/mm_init: factor out common struct page initialization

From: Mike Rapoport

Date: Tue Nov 17 2026 - 08:21:39 EST


On Tue, Nov 17, 2026 at 11:13:42AM +0800, Muchun Song wrote:
> On 2026/11/16 18:42, Mike Rapoport wrote:
>
> > > page_cpupid_reset_last(page);
> > > page_kasan_tag_reset(page);
> > > + atomic_set(&page->_mapcount, -1);
> > > +#ifdef CONFIG_ZONE_DEVICE
> > > + if (zone == ZONE_DEVICE)
> > > + __SetPageReserved(page);
> > > +#endif
> > Can't we keep this in ZONE_DEVICE part?
>
> We can. But I put it here because there are at least two places where
> we need to mark a ZONE_DEVICE page as reserved. Handling it in
> memmap_init_page_common is simpler — it reduces the number of places
> where we have to set reserved individually. Otherwise, we would need
> to explicitly set reserved in multiple places.
>
> >
> > If we can't, __init_single_page() sets PG_reserved for ZONE_DEVICE pages
> > and the
> >
> > if (zone == ZONE_DEVICE)
> > __SetPageReserved(page);
> >
> > in the MEMINIT_HOTPLUG part of memmap_init_range() becomes redundant.
> >
>
> Good catch. I think I could remove this redundancy next version if you
> think handing it in memmap_init_page_common is okay.

Let's keep the #ifdef, still better than duplication.

> Thanks,
> Muchun

--
Sincerely yours,
Mike.