Thread (140 messages) 140 messages, 13 authors, 2025-09-01

Re: [PATCH v1 18/36] mm/gup: drop nth_page() usage within folio when recording subpages

From: Lorenzo Stoakes <hidden>
Date: 2025-08-28 16:38:44
Also in: dri-devel, intel-gfx, io-uring, kvm, linux-arm-kernel, linux-crypto, linux-ide, linux-iommu, linux-kselftest, linux-mips, linux-mm, linux-mmc, linux-riscv, linux-s390, linux-scsi, lkml, virtualization

On Thu, Aug 28, 2025 at 12:01:22AM +0200, David Hildenbrand wrote:
nth_page() is no longer required when iterating over pages within a
single folio, so let's just drop it when recording subpages.

Signed-off-by: David Hildenbrand <redacted>
This looks correct to me, so notwithtsanding suggestion below, LGTM and:

Reviewed-by: Lorenzo Stoakes <redacted>
quoted hunk ↗ jump to hunk
---
 mm/gup.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/mm/gup.c b/mm/gup.c
index b2a78f0291273..89ca0813791ab 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -488,12 +488,11 @@ static int record_subpages(struct page *page, unsigned long sz,
 			   unsigned long addr, unsigned long end,
 			   struct page **pages)
 {
-	struct page *start_page;
 	int nr;

-	start_page = nth_page(page, (addr & (sz - 1)) >> PAGE_SHIFT);
+	page += (addr & (sz - 1)) >> PAGE_SHIFT;
 	for (nr = 0; addr != end; nr++, addr += PAGE_SIZE)
-		pages[nr] = nth_page(start_page, nr);
+		pages[nr] = page++;

This is really nice, but I wonder if (while we're here) we can't be even
more clear as to what's going on here, e.g.:

static int record_subpages(struct page *page, unsigned long sz,
			   unsigned long addr, unsigned long end,
			   struct page **pages)
{
	size_t offset_in_folio = (addr & (sz - 1)) >> PAGE_SHIFT;
	struct page *subpage = page + offset_in_folio;

	for (; addr != end; addr += PAGE_SIZE)
		*pages++ = subpage++;

	return nr;
}

Or some variant of that with the masking stuff self-documented.
quoted hunk ↗ jump to hunk
 	return nr;
 }
@@ -1512,7 +1511,7 @@ static long __get_user_pages(struct mm_struct *mm,
 			}

 			for (j = 0; j < page_increm; j++) {
-				subpage = nth_page(page, j);
+				subpage = page + j;
 				pages[i + j] = subpage;
 				flush_anon_page(vma, subpage, start + j * PAGE_SIZE);
 				flush_dcache_page(subpage);
--
2.50.1
Cheers, Lorenzo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help