Re: [PATCH 1/4] mm: factor zone-device page init helpers out of __init_zone_device_page

From: Li Zhe

Date: Mon May 18 2026 - 05:12:29 EST


On Mon, 18 May 2026 09:23:33 +0300, rppt@xxxxxxxxxx wrote:

> Hi,
>
> On Fri, May 15, 2026 at 04:20:42PM +0800, Li Zhe wrote:
> > __init_zone_device_page() currently mixes three different jobs: deciding
> > the initial page refcount, initializing the generic ZONE_DEVICE state, and
> > setting up pageblock metadata.
> >
> > Split the refcount policy into zone_device_page_init_refcount() and move
> > the generic page initialization into generic_init_zone_device_page(). This
> > keeps the slow path behavior unchanged, but makes the individual pieces
> > reusable by later fast-path patches.
> >
> > No functional change intended.
> >
> > Signed-off-by: Li Zhe <lizhe.67@xxxxxxxxxxxxx>
> > ---
> > mm/mm_init.c | 62 ++++++++++++++++++++++++++++++++--------------------
> > 1 file changed, 38 insertions(+), 24 deletions(-)
> >
> > diff --git a/mm/mm_init.c b/mm/mm_init.c
> > index f9f8e1af921c..5244acb96dbb 100644
> > --- a/mm/mm_init.c
> > +++ b/mm/mm_init.c
> > @@ -987,11 +987,36 @@ static void __init memmap_init(void)
> > }
> >
> > #ifdef CONFIG_ZONE_DEVICE
> > -static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,
> > - unsigned long zone_idx, int nid,
> > - struct dev_pagemap *pgmap)
>
> Since you are already changing __init_zone_device_page(), I'd suggest
> renaming it to zone_device_page_init().
>
> > +static inline int zone_device_page_init_refcount(
> > + const struct dev_pagemap *pgmap)
> > {
> > + /*
> > + * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC are released
> > + * directly to the driver page allocator which will set the page count
> > + * to 1 when allocating the page.
> > + *
> > + * MEMORY_TYPE_GENERIC and MEMORY_TYPE_FS_DAX pages automatically have
> > + * their refcount reset to one whenever they are freed (ie. after
> > + * their refcount drops to 0).
> > + */
> > + switch (pgmap->type) {
> > + case MEMORY_DEVICE_FS_DAX:
> > + case MEMORY_DEVICE_PRIVATE:
> > + case MEMORY_DEVICE_COHERENT:
> > + case MEMORY_DEVICE_PCI_P2PDMA:
> > + return 0;
> > + case MEMORY_DEVICE_GENERIC:
> > + return 1;
> > + default:
> > + WARN_ONCE(1, "Unknown memory type!");
> > + return 1;
> > + }
> > +}
> >
> > +static void __ref generic_init_zone_device_page(struct page *page,
> > + unsigned long pfn, unsigned long zone_idx, int nid,
> > + struct dev_pagemap *pgmap)
> > +{
>
> Here also would be better to use zone_device_page_ prefix.
> And I don't think "generic" adds clarity about what this function is doing.
>
> Seeing that later patches rename it again to _slow variant, I'd suggest to
> call it __zone_device_page_init() at keep this name going forward.

Thanks, I will fix this in the v2 revision.

Thanks,
Zhe