linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: avoid unnecessary page table walk for __get_user_pages
@ 2022-09-06  2:44 Chen Wandun
  2022-09-07 23:34 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Wandun @ 2022-09-06  2:44 UTC (permalink / raw)
  To: akpm, linux-mm, linux-kernel; +Cc: wangkefeng.wang, chenwandun

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.

Signed-off-by: Chen Wandun <chenwandun@huawei.com>
---
 mm/gup.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/gup.c b/mm/gup.c
index 983e24fd4b70..c8de33cc37af 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -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;
-- 
2.25.1



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

* Re: [PATCH] mm: avoid unnecessary page table walk for __get_user_pages
  2022-09-06  2:44 [PATCH] mm: avoid unnecessary page table walk for __get_user_pages Chen Wandun
@ 2022-09-07 23:34 ` Andrew Morton
  2022-09-08  1:58   ` John Hubbard
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2022-09-07 23:34 UTC (permalink / raw)
  To: Chen Wandun; +Cc: linux-mm, linux-kernel, wangkefeng.wang

On Tue, 6 Sep 2022 10:44:01 +0800 Chen Wandun <chenwandun@huawei.com> 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.
>
> ...
>
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -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;

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.



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

* Re: [PATCH] mm: avoid unnecessary page table walk for __get_user_pages
  2022-09-07 23:34 ` Andrew Morton
@ 2022-09-08  1:58   ` John Hubbard
  0 siblings, 0 replies; 3+ messages in thread
From: John Hubbard @ 2022-09-08  1:58 UTC (permalink / raw)
  To: Andrew Morton, Chen Wandun; +Cc: linux-mm, linux-kernel, wangkefeng.wang

On 9/7/22 16:34, Andrew Morton wrote:
> On Tue, 6 Sep 2022 10:44:01 +0800 Chen Wandun <chenwandun@huawei.com> 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.
>>
>> ...
>>
>> --- a/mm/gup.c
>> +++ b/mm/gup.c
>> @@ -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!

>>   			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

Reviewed-by: John Hubbard <jhubbard@nvidia.com>


thanks,
-- 
John Hubbard
NVIDIA



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

end of thread, other threads:[~2022-09-08  1:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-06  2:44 [PATCH] mm: avoid unnecessary page table walk for __get_user_pages Chen Wandun
2022-09-07 23:34 ` Andrew Morton
2022-09-08  1:58   ` John Hubbard

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).