__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 --- 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) +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) +{ __init_single_page(page, pfn, zone_idx, nid); /* @@ -1011,6 +1036,16 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, page_folio(page)->pgmap = pgmap; page->zone_device_data = NULL; + if (!zone_device_page_init_refcount(pgmap)) + set_page_count(page, 0); +} + +static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, + unsigned long zone_idx, int nid, + struct dev_pagemap *pgmap) +{ + generic_init_zone_device_page(page, pfn, zone_idx, nid, pgmap); + /* * Mark the block movable so that blocks are reserved for * movable at startup. This will force kernel allocations @@ -1025,27 +1060,6 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, init_pageblock_migratetype(page, MIGRATE_MOVABLE, false); cond_resched(); } - - /* - * 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: - set_page_count(page, 0); - break; - - case MEMORY_DEVICE_GENERIC: - break; - } } /* -- 2.20.1