ZONE_DEVICE memmap initialization already uses a reusable struct page template when initializing compound tail pages. The template mostly contains invariant state, but a few fields still depend on the target PFN and must be refreshed before copying the template into each destination struct page. Factor that refresh into memmap_init_refresh_pfn_fields() so other boot-time memmap initialization paths can reuse the PFN-dependent part while keeping their own copy primitive. Define the helper as static inline in mm/mm_init.h, since it is small and only shared by mm/ initialization code. No functional change intended. Signed-off-by: Li Zhe --- mm/mm_init.c | 11 ++++++----- mm/mm_init.h | 11 +++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index d99af80ec752..33a9d8dd044c 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1076,11 +1076,12 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, static void zone_device_page_init_from_template(struct page *page, unsigned long pfn, struct page *template) { - set_page_section_from_pfn(template, pfn); -#ifdef WANT_PAGE_VIRTUAL - if (!is_highmem_idx(ZONE_DEVICE)) - set_page_address(template, __va(pfn << PAGE_SHIFT)); -#endif + /* + * Refresh PFN-dependent fields in the template before the + * non-temporal copy, so the destination page does not need cached + * stores after memcpy_nontemporal(). + */ + memmap_init_refresh_pfn_fields(template, pfn, ZONE_DEVICE); memcpy_nontemporal(page, template, sizeof(*page)); } diff --git a/mm/mm_init.h b/mm/mm_init.h index 0034e37dbabd..7e1d6897b844 100644 --- a/mm/mm_init.h +++ b/mm/mm_init.h @@ -112,4 +112,15 @@ void memblock_free_all(void); void __meminit __init_single_page(struct page *page, unsigned long pfn, unsigned long zone, int nid); +static inline void memmap_init_refresh_pfn_fields(struct page *page, + unsigned long pfn, + unsigned long zone) +{ + set_page_section_from_pfn(page, pfn); +#ifdef WANT_PAGE_VIRTUAL + if (!is_highmem_idx(zone)) + set_page_address(page, __va(pfn << PAGE_SHIFT)); +#endif +} + #endif /* __MM_MM_INIT_H */ -- 2.20.1