On 7/1/26 11:05, Li Zhe wrote: > memmap_init_zone_device() currently mixes refcount policy and core > ZONE_DEVICE page setup in a single helper. > > Factor the refcount-reset predicate into pagemap_resets_refcount(), move > the common page initialization into __zone_device_page_init(), and wrap > the existing slow path in zone_device_page_init_slow(). > > This keeps the slow-path behaviour unchanged and gives later patches > reusable helper boundaries. > > No functional change intended. > > Signed-off-by: Li Zhe <[email protected]> > Reviewed-by: Mike Rapoport (Microsoft) <[email protected]> > --- > mm/mm_init.c | 57 ++++++++++++++++++++++++++++++++++------------------ > 1 file changed, 38 insertions(+), 19 deletions(-) > > diff --git a/mm/mm_init.c b/mm/mm_init.c > index 95808ab5cfdb..4c7fad440c2a 100644 > --- a/mm/mm_init.c > +++ b/mm/mm_init.c > @@ -1005,11 +1005,38 @@ static void __init memmap_init(void) > } > > #ifdef CONFIG_ZONE_DEVICE > -static void __ref __init_zone_device_page(struct page *page, unsigned long > pfn, > +/* > + * Return true when the free path for this pagemap type restores the page > + * refcount to 1, so memmap_init_zone_device() can keep the count set by > + * __init_single_page(). Otherwise initialize the refcount to 0 and leave > + * it to the allocator or pgmap callbacks to raise it when the page is > + * handed out again. > + */ > +static inline bool pagemap_resets_refcount(const struct dev_pagemap *pgmap) > +{ > + /* > + * MEMORY_DEVICE_GENERIC pages regain a refcount of 1 in the free > + * path. The remaining ZONE_DEVICE types start from 0 here and raise > + * the count again when the allocator or driver hands the page out. > + */ > + switch (pgmap->type) { > + case MEMORY_DEVICE_FS_DAX: > + case MEMORY_DEVICE_PRIVATE: > + case MEMORY_DEVICE_COHERENT: > + case MEMORY_DEVICE_PCI_P2PDMA: > + return false; > + case MEMORY_DEVICE_GENERIC: > + return true; > + default: > + WARN_ONCE(1, "Unknown memory type!"); > + return true;
Wouldn't the compiler warn if we would define a new type but forgot to update it here? We're using an enum, and I thought the compiler would bail out in that case. Or are we scared of some other garbage ending up in there? Apart from that LGTM. -- Cheers, David

