Skip to contentSkip to conversation

mm: avoid unnecessary page table walk for __get_user_pages

PATCH In review Chen Wandun 3 participants 3 messages Sep 6, 2022 – Sep 8, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: avoid unnecessary page table walk for __get_user_pages

It is no need to walk page table and find pages if faultin_page success and __get_user_pages does't care pages at all, so directly handle next page.

---
 mm/gup.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mm/gup.c +4 -1
index 983e24fd4b70..c8de33cc37af 100644
@@ -1198,7 +1198,10 @@ static long __get_user_pages(struct mm_struct *mm,
 					   PTR_ERR(page) == -EMLINK, locked);
 			switch (ret) {
 			case 0:
-				goto retry;
+				if (pages)
+					goto retry;
+				else
+					goto next_page;
 			case -EBUSY:
 			case -EAGAIN:
 				ret = 0;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 10 lines · On Tue, 6 Sep 2022 10:44:01 +0800 Chen Wandun <[email protected]> wrote:

It is no need to walk page table and find pages if faultin_page success and __get_user_pages does't care pages at all, so directly handle next page.

...

mm/gup.c +0 -0
@@ -1198,7 +1198,10 @@ static long __get_user_pages(struct mm_struct *mm,
 					   PTR_ERR(page) == -EMLINK, locked);

mm/gup.c static long __get_user_pages(struct mm_struct *mm, · line 1207

Quoted 10 lines
mm/gup.c +4 -1
 			switch (ret) {
 			case 0:
-				goto retry;
+				if (pages)
+					goto retry;
+				else
+					goto next_page;
 			case -EBUSY:
 			case -EAGAIN:
 				ret = 0;

Looks right to me. I redid the changelog somewhat:

: There is no need to walk page tables and find pages if faultin_page)_ : succeeds and __get_user_pages)_ doesn't care about populating the pages[] : array. So directly go on to handle the next page.

reviewer Reviewed-by
#2 lore raw
Quoted 8 lines · Andrew Morton
Quoted 6 lines · On Tue, 6 Sep 2022 10:44:01 +0800 Chen Wandun <[email protected]> wrote:

It is no need to walk page table and find pages if faultin_page success and __get_user_pages does't care pages at all, so directly handle next page.

...

Quoted 11 lines

mm/gup.c static long __get_user_pages(struct mm_struct *mm, · line 1204

Quoted 11 lines
mm/gup.c +4 -1
@@ -1198,7 +1198,10 @@ static long __get_user_pages(struct mm_struct *mm,
  					   PTR_ERR(page) == -EMLINK, locked);
  			switch (ret) {
  			case 0:
-				goto retry;
+				if (pages)
+					goto retry;
+				else
+					goto next_page;

Wow, good point. And it's been doing that for a *long* time!

Quoted 11 lines

mm/gup.c static long __get_user_pages(struct mm_struct *mm, · line 1207

Quoted 3 lines
mm/gup.c +0 -0
  			case -EBUSY:
  			case -EAGAIN:
  				ret = 0;

Looks right to me. I redid the changelog somewhat:

: There is no need to walk page tables and find pages if faultin_page)_ : succeeds and __get_user_pages)_ doesn't care about populating the pages[] : array. So directly go on to handle the next page.

With that re-worded commit description, please feel to add

thanks,

Signature · 2 lines
John Hubbard
NVIDIA