Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: simplify folio_page() and folio_page_idx()

Now that a single folio/compound page can no longer span memory sections
in problematic kernel configurations, we can stop using nth_page() in
folio_page() and folio_page_idx().

While at it, turn both macros into static inline functions and add kernel
doc for folio_page_idx().

Link: https://lkml.kernel.org/r/20250901150359.867252-13-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
73b3294b 4751c39e

+18 -3
+14 -2
include/linux/mm.h
··· 210 210 211 211 #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) 212 212 #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) 213 - #define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio)) 214 213 #else 215 214 #define nth_page(page,n) ((page) + (n)) 216 - #define folio_page_idx(folio, p) ((p) - &(folio)->page) 217 215 #endif 218 216 219 217 /* to align the pointer to the (next) page boundary */ ··· 222 224 223 225 /* test whether an address (unsigned long or pointer) is aligned to PAGE_SIZE */ 224 226 #define PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), PAGE_SIZE) 227 + 228 + /** 229 + * folio_page_idx - Return the number of a page in a folio. 230 + * @folio: The folio. 231 + * @page: The folio page. 232 + * 233 + * This function expects that the page is actually part of the folio. 234 + * The returned number is relative to the start of the folio. 235 + */ 236 + static inline unsigned long folio_page_idx(const struct folio *folio, 237 + const struct page *page) 238 + { 239 + return page - &folio->page; 240 + } 225 241 226 242 static inline struct folio *lru_to_folio(struct list_head *head) 227 243 {
+4 -1
include/linux/page-flags.h
··· 316 316 * check that the page number lies within @folio; the caller is presumed 317 317 * to have a reference to the page. 318 318 */ 319 - #define folio_page(folio, n) nth_page(&(folio)->page, n) 319 + static inline struct page *folio_page(struct folio *folio, unsigned long n) 320 + { 321 + return &folio->page + n; 322 + } 320 323 321 324 static __always_inline int PageTail(const struct page *page) 322 325 {