On 7/1/26 11:05, Li Zhe wrote:
> Callers that want to update section bits from a PFN currently need to
> open-code:
>
> set_page_section(page, pfn_to_section_nr(pfn));
>
> and guard that sequence with #ifdef SECTION_IN_PAGE_FLAGS.
>
> Add set_page_section_from_pfn() to wrap that update in one place. When
> section bits are stored in page flags, the helper derives the section
> number from the PFN and updates the page flags. Otherwise it degrades to
> a no-op.
>
> Convert set_page_links() to use the new helper so later ZONE_DEVICE
> fast-path patches can also update section bits without open-coding
> SECTION_IN_PAGE_FLAGS at each callsite.
>
> This keeps the PFN-to-section translation local to the configurations
> that actually store section bits in struct page flags, and avoids
> exposing that detail to generic callers.
>
> No functional change intended.
>
> Signed-off-by: Li Zhe <[email protected]>
> Reviewed-by: Mike Rapoport (Microsoft) <[email protected]>
> ---
> include/linux/mm.h | 19 ++++++++++++++++---
> 1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 485df9c2dbdd..f78afa63dd3d 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2541,11 +2541,26 @@ static inline void set_page_section(struct page
> *page, unsigned long section)
> page->flags.f |= (section & SECTIONS_MASK) << SECTIONS_PGSHIFT;
> }
>
> +static inline void set_page_section_from_pfn(struct page *page,
> + unsigned long pfn)
Two tab indent.
> +{
> + set_page_section(page, pfn_to_section_nr(pfn));
> +}
> +
> static inline unsigned long memdesc_section(memdesc_flags_t mdf)
> {
> return (mdf.f >> SECTIONS_PGSHIFT) & SECTIONS_MASK;
> }
> #else /* !SECTION_IN_PAGE_FLAGS */
> +static inline void set_page_section(struct page *page, unsigned long section)
> +{
> +}
Why do we need this?
> +
> +static inline void set_page_section_from_pfn(struct page *page,
> + unsigned long pfn)
> +{
> +}
Dito.
> +
> static inline unsigned long memdesc_section(memdesc_flags_t mdf)
> {
> return 0;
> @@ -2768,9 +2783,7 @@ static inline void set_page_links(struct page *page,
> enum zone_type zone,
> {
> set_page_zone(page, zone);
> set_page_node(page, node);
> -#ifdef SECTION_IN_PAGE_FLAGS
> - set_page_section(page, pfn_to_section_nr(pfn));
> -#endif
> + set_page_section_from_pfn(page, pfn);
> }
>
> /**
--
Cheers,
David