public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] futex: replace get_user_pages() with get_user_pages_fast()
@ 2011-06-23  6:21 KOSAKI Motohiro
  2011-06-23 15:11 ` Darren Hart
  0 siblings, 1 reply; 3+ messages in thread
From: KOSAKI Motohiro @ 2011-06-23  6:21 UTC (permalink / raw)
  To: tglx, dvhart, linux-kernel, mingo, a.p.zijlstra; +Cc: kosaki.motohiro

Hello,

Is there any reason to take mmap_sem explicitly here?
Should we change gup_fast() to allow NULL argument (ie for avoid get_page)?

============================
  down_read(&mm->mmap_sem);
  get_user_pages(current, current->mm)
  up_read(&mm->mmap_sem);

and

  get_user_pages_fast()

make an equivalent result, And latter would be better when mamp_sem
highly contended case, because it can avoid to take mmap_sem if
the target page doesn't need a page fault.

Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 kernel/futex.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index fe28dc2..9f7b1ae 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -351,13 +351,11 @@ static inline void put_futex_key(union futex_key *key)
  */
 static int fault_in_user_writeable(u32 __user *uaddr)
 {
-	struct mm_struct *mm = current->mm;
 	int ret;
+	struct page *page;

-	down_read(&mm->mmap_sem);
-	ret = get_user_pages(current, mm, (unsigned long)uaddr,
-			     1, 1, 0, NULL, NULL);
-	up_read(&mm->mmap_sem);
+	ret = get_user_pages_fast((unsigned long)uaddr, 1, 1, &page);
+	put_page(page);

 	return ret < 0 ? ret : 0;
 }
-- 
1.7.3.1



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

* Re: [RFC PATCH] futex: replace get_user_pages() with get_user_pages_fast()
  2011-06-23  6:21 [RFC PATCH] futex: replace get_user_pages() with get_user_pages_fast() KOSAKI Motohiro
@ 2011-06-23 15:11 ` Darren Hart
  2011-06-23 15:44   ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Darren Hart @ 2011-06-23 15:11 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: tglx, linux-kernel, mingo, a.p.zijlstra



On 06/22/2011 11:21 PM, KOSAKI Motohiro wrote:
> Hello,
> 
> Is there any reason to take mmap_sem explicitly here?
> Should we change gup_fast() to allow NULL argument (ie for avoid get_page)?
> 
> ============================
>   down_read(&mm->mmap_sem);
>   get_user_pages(current, current->mm)
>   up_read(&mm->mmap_sem);
> 
> and
> 
>   get_user_pages_fast()
> 
> make an equivalent result, And latter would be better when mamp_sem
> highly contended case, because it can avoid to take mmap_sem if
> the target page doesn't need a page fault.


I can't speak authoritatively here, but it seems to me that
get_user_pages_fast falls back to get_user_pages with mmap_sem anyway,
so this seems like a reasonable optimization for the best case, with a
minor overhead for the slow case.

Peter, am I missing something? Is there a reason you left this as is
during your fast gup futex update?

> 
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> ---
>  kernel/futex.c |    8 +++-----
>  1 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/futex.c b/kernel/futex.c
> index fe28dc2..9f7b1ae 100644
> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -351,13 +351,11 @@ static inline void put_futex_key(union futex_key *key)
>   */
>  static int fault_in_user_writeable(u32 __user *uaddr)
>  {
> -	struct mm_struct *mm = current->mm;
>  	int ret;
> +	struct page *page;
> 
> -	down_read(&mm->mmap_sem);
> -	ret = get_user_pages(current, mm, (unsigned long)uaddr,
> -			     1, 1, 0, NULL, NULL);
> -	up_read(&mm->mmap_sem);
> +	ret = get_user_pages_fast((unsigned long)uaddr, 1, 1, &page);
> +	put_page(page);
> 
>  	return ret < 0 ? ret : 0;
>  }

-- 
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel

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

* Re: [RFC PATCH] futex: replace get_user_pages() with get_user_pages_fast()
  2011-06-23 15:11 ` Darren Hart
@ 2011-06-23 15:44   ` Peter Zijlstra
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2011-06-23 15:44 UTC (permalink / raw)
  To: Darren Hart; +Cc: KOSAKI Motohiro, tglx, linux-kernel, mingo

On Thu, 2011-06-23 at 08:11 -0700, Darren Hart wrote:
> 
> On 06/22/2011 11:21 PM, KOSAKI Motohiro wrote:
> > Hello,
> > 
> > Is there any reason to take mmap_sem explicitly here?
> > Should we change gup_fast() to allow NULL argument (ie for avoid get_page)?
> > 
> > ============================
> >   down_read(&mm->mmap_sem);
> >   get_user_pages(current, current->mm)
> >   up_read(&mm->mmap_sem);
> > 
> > and
> > 
> >   get_user_pages_fast()
> > 
> > make an equivalent result, And latter would be better when mamp_sem
> > highly contended case, because it can avoid to take mmap_sem if
> > the target page doesn't need a page fault.
> 
> 
> I can't speak authoritatively here, but it seems to me that
> get_user_pages_fast falls back to get_user_pages with mmap_sem anyway,
> so this seems like a reasonable optimization for the best case, with a
> minor overhead for the slow case.
> 
> Peter, am I missing something? 

Right, its much cheaper on the fast-path where the page is found present
and writable, if we have to take the fault, the extra cost in the slow
path is neglectable.

> Is there a reason you left this as is
> during your fast gup futex update?

I probably completely missed this gup() user.

The proposed change looks good to me.

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

end of thread, other threads:[~2011-06-23 15:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-23  6:21 [RFC PATCH] futex: replace get_user_pages() with get_user_pages_fast() KOSAKI Motohiro
2011-06-23 15:11 ` Darren Hart
2011-06-23 15:44   ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox