linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Move nth_page from folio_page into folio_next
@ 2025-03-13  4:40 Herbert Xu
  2025-03-13 12:25 ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2025-03-13  4:40 UTC (permalink / raw)
  To: linux-mm, Andrew Morton, Linux Kernel Mailing List,
	Matthew Wilcox, Christoph Hellwig, Zi Yan, Eric Biggers

Discontiguous memory may require the use of nth_page instead of adding
to struct page arithmetically.  However, discontiguous memory cannot
exist within a single folio.

The function folio_page is mostly used for accessing a page within
a folio, therefore using nth_page for it is overkill.

Move it to the only place where it's needed, which is folio_next.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7b1068ddcbb7..5f63ee0770f7 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2115,7 +2115,7 @@ static inline int thp_nr_pages(struct page *page)
  */
 static inline struct folio *folio_next(struct folio *folio)
 {
-	return (struct folio *)folio_page(folio, folio_nr_pages(folio));
+	return (struct folio *)nth_page(&folio->page, folio_nr_pages(folio));
 }
 
 /**
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 36d283552f80..ebba355c45a5 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -275,7 +275,7 @@ static __always_inline unsigned long _compound_head(const struct page *page)
  * check that the page number lies within @folio; the caller is presumed
  * to have a reference to the page.
  */
-#define folio_page(folio, n)	nth_page(&(folio)->page, n)
+#define folio_page(folio, n)	(&(folio)->page + (n))
 
 static __always_inline int PageTail(const struct page *page)
 {
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-14  1:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-13  4:40 [PATCH] mm: Move nth_page from folio_page into folio_next Herbert Xu
2025-03-13 12:25 ` Matthew Wilcox
2025-03-14  1:18   ` Herbert Xu
2025-03-14  1:40     ` Zi Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox