Skip to contentSkip to conversation

mm/gup_test: report actual pinned bytes

PATCH Applied Sarthak Sharma 3 participants 3 messages Aug 31 – Sep 7

Subsystems (2)

v2 of 3 Applied 1/1 Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm/gup_test: report actual pinned bytes

__gup_test_ioctl() advances addr to the end of the current batch before checking if GUP pinned the entire requested batch. If GUP pins more than 0 pages but less than the requested batch size, addr still advances by the requested batch size.

The next iteration detects the partial pinning and breaks out of the loop. Again gup->size is calculated using addr - gup->addr, so it also includes the unpinned pages of the requested batch.

Calculate gup->size using the actual number of pages pinned multiplied by PAGE_SIZE.

Fixes 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking")

---
Changes in v2:
- Fix typo in the commit message

v1: lore.kernel.org/all/[email protected]/

 mm/gup_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/gup_test.c +1 -1
index 44c1cdfb9c37..185ba3bb8ed1 100644
@@ -188,7 +188,7 @@ static int __gup_test_ioctl(unsigned int cmd,
 	nr_pages = i;
 
 	gup->get_delta_usec = ktime_us_delta(end_time, start_time);
-	gup->size = addr - gup->addr;
+	gup->size = nr_pages * PAGE_SIZE;
 
 	/*
 	 * Take an un-benchmark-timed moment to verify DMA pinned
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 11 lines · On Mon, 31 Aug 2026 15:43:04 +0530 Sarthak Sharma <[email protected]>…

__gup_test_ioctl() advances addr to the end of the current batch before checking if GUP pinned the entire requested batch. If GUP pins more than 0 pages but less than the requested batch size, addr still advances by the requested batch size.

The next iteration detects the partial pinning and breaks out of the loop. Again gup->size is calculated using addr - gup->addr, so it also includes the unpinned pages of the requested batch.

Calculate gup->size using the actual number of pages pinned multiplied by PAGE_SIZE.

Thanks. Sashiko might have found a somewhat-related overflow on 32-bit. Maybe fix that while we're in there?

	https://sashiko.dev/#/patchset/[email protected]
maintainer Acked-by on v2 1/1
#2 lore raw
In reply to Sarthak Sharma
Quoted 29 lines · Sarthak Sharma

__gup_test_ioctl() advances addr to the end of the current batch before checking if GUP pinned the entire requested batch. If GUP pins more than 0 pages but less than the requested batch size, addr still advances by the requested batch size.

The next iteration detects the partial pinning and breaks out of the loop. Again gup->size is calculated using addr - gup->addr, so it also includes the unpinned pages of the requested batch.

Calculate gup->size using the actual number of pages pinned multiplied by PAGE_SIZE.

Fixes 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking")

---
Changes in v2:
- Fix typo in the commit message

v1: lore.kernel.org/all/[email protected]/

 mm/gup_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/gup_test.c +0 -0
index 44c1cdfb9c37..185ba3bb8ed1 100644

mm/gup_test.c static int __gup_test_ioctl(unsigned int cmd, · line 194

Quoted 8 lines
mm/gup_test.c +1 -1
@@ -188,7 +188,7 @@ static int __gup_test_ioctl(unsigned int cmd,
 	nr_pages = i;
 
 	gup->get_delta_usec = ktime_us_delta(end_time, start_time);
-	gup->size = addr - gup->addr;
+	gup->size = nr_pages * PAGE_SIZE;
 
 	/*
 	 * Take an un-benchmark-timed moment to verify DMA pinned

I assume that loop handling could get cleaned up a bit.

Signature · 3 lines
Cheers,

David