* [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 related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: Move nth_page from folio_page into folio_next
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
0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2025-03-13 12:25 UTC (permalink / raw)
To: Herbert Xu
Cc: linux-mm, Andrew Morton, Linux Kernel Mailing List,
Christoph Hellwig, Zi Yan, Eric Biggers
On Thu, Mar 13, 2025 at 12:40:34PM +0800, Herbert Xu wrote:
> 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.
That isn't true. HugeTLB can construct a folio which crosses a
contiguity boundary.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: Move nth_page from folio_page into folio_next
2025-03-13 12:25 ` Matthew Wilcox
@ 2025-03-14 1:18 ` Herbert Xu
2025-03-14 1:40 ` Zi Yan
0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2025-03-14 1:18 UTC (permalink / raw)
To: Matthew Wilcox
Cc: linux-mm, Andrew Morton, Linux Kernel Mailing List,
Christoph Hellwig, Zi Yan, Eric Biggers
On Thu, Mar 13, 2025 at 12:25:50PM +0000, Matthew Wilcox wrote:
>
> That isn't true. HugeTLB can construct a folio which crosses a
> contiguity boundary.
Thanks. So thea means we do need to use nth_page when iterating
through a folio or a scatterlist generated from a folio.
Cheers,
--
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
* Re: [PATCH] mm: Move nth_page from folio_page into folio_next
2025-03-14 1:18 ` Herbert Xu
@ 2025-03-14 1:40 ` Zi Yan
0 siblings, 0 replies; 4+ messages in thread
From: Zi Yan @ 2025-03-14 1:40 UTC (permalink / raw)
To: Herbert Xu
Cc: Matthew Wilcox, linux-mm, Andrew Morton,
Linux Kernel Mailing List, Christoph Hellwig, Eric Biggers
On 13 Mar 2025, at 21:18, Herbert Xu wrote:
> On Thu, Mar 13, 2025 at 12:25:50PM +0000, Matthew Wilcox wrote:
>>
>> That isn't true. HugeTLB can construct a folio which crosses a
>> contiguity boundary.
>
> Thanks. So thea means we do need to use nth_page when iterating
> through a folio or a scatterlist generated from a folio.
When you know the folio is hugetlb with gigantic order. Folios
come out of buddy allocator are all within contiguity boundaries.
To be precise, the boundary here means a section boundary.
In addition, nth_page() is a trivial addition for SPARSEMEM_VMEMMAP
or FLATMEM. For SPARSEMEM && !SPARSEMEM_VMEMMAP, it needs to use
pfn for the calculation.
Best Regards,
Yan, Zi
^ 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;
as well as URLs for NNTP newsgroup(s).