All of lore.kernel.org
 help / color / mirror / Atom feed
* unnecessary tlb flush in mprotect
@ 2012-05-21  8:30 Alex Shi
  2012-05-22  1:08 ` Alex Shi
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Shi @ 2012-05-21  8:30 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: cl, Peter Zijlstra, mgorman, Andrew Morton, linux-kernel,
	linux-mm, Andi Kleen

when mprotect just change prots of non-present pages, current mprotect
still do the tlb flush in check_protection().
but according to 4.10.2.3 Intel SDM V3A (
www.intel.com/Assets/ja_JP/PDF/manual/253668.pdf ) at that time, TLB has
no this lines for this page. So, tlb flush is just waste time. (for cr3
rewrite, flush all tlb, or invlpg, like a 'nop' in intel cpu)

Do we need to add the pte_present similar check here to prevent the
unnecessary tlb flushing? I mean, are there real case in word, User like
to change page prots before assign a physical page to it?



Alex Shi

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

* Re: unnecessary tlb flush in mprotect
  2012-05-21  8:30 unnecessary tlb flush in mprotect Alex Shi
@ 2012-05-22  1:08 ` Alex Shi
  2012-05-22 16:37   ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Shi @ 2012-05-22  1:08 UTC (permalink / raw)
  To: H. Peter Anvin, cl, Peter Zijlstra, mgorman, Andrew Morton,
	linux-kernel, linux-mm, Andi Kleen

On 05/21/2012 04:30 PM, Alex Shi wrote:

> when mprotect just change prots of non-present pages, current mprotect
> still do the tlb flush in check_protection().
> but according to 4.10.2.3 Intel SDM V3A (
> www.intel.com/Assets/ja_JP/PDF/manual/253668.pdf ) at that time, TLB has
> no this lines for this page. So, tlb flush is just waste time. (for cr3
> rewrite, flush all tlb, or invlpg, like a 'nop' in intel cpu)
> 
> Do we need to add the pte_present similar check here to prevent the
> unnecessary tlb flushing? I mean, are there real case in word, User like
> to change page prots before assign a physical page to it?
> 


Any comments from linux-mm emailing list?

> 
> 
> Alex Shi



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

* Re: unnecessary tlb flush in mprotect
  2012-05-22  1:08 ` Alex Shi
@ 2012-05-22 16:37   ` Andi Kleen
  2012-05-23  0:06     ` Alex Shi
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2012-05-22 16:37 UTC (permalink / raw)
  To: Alex Shi
  Cc: H. Peter Anvin, cl, Peter Zijlstra, mgorman, Andrew Morton,
	linux-kernel, linux-mm

On Tue, May 22, 2012 at 09:08:47AM +0800, Alex Shi wrote:
> On 05/21/2012 04:30 PM, Alex Shi wrote:
> 
> > when mprotect just change prots of non-present pages, current mprotect
> > still do the tlb flush in check_protection().
> > but according to 4.10.2.3 Intel SDM V3A (
> > www.intel.com/Assets/ja_JP/PDF/manual/253668.pdf ) at that time, TLB has
> > no this lines for this page. So, tlb flush is just waste time. (for cr3
> > rewrite, flush all tlb, or invlpg, like a 'nop' in intel cpu)
> > 
> > Do we need to add the pte_present similar check here to prevent the
> > unnecessary tlb flushing? I mean, are there real case in word, User like
> > to change page prots before assign a physical page to it?
> > 
> 
> 
> Any comments from linux-mm emailing list?

I would be careful with TLB optimizations if it's not a clear performance
wins. A lot of these interactions are tricky and it's very easy to break
things in subtle and hard to debug ways.

-Andi
-- 
ak@linux.intel.com -- Speaking for myself only

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

* Re: unnecessary tlb flush in mprotect
  2012-05-22 16:37   ` Andi Kleen
@ 2012-05-23  0:06     ` Alex Shi
  2012-05-26 18:46       ` Hugh Dickins
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Shi @ 2012-05-23  0:06 UTC (permalink / raw)
  To: Andi Kleen
  Cc: H. Peter Anvin, cl, Peter Zijlstra, mgorman, Andrew Morton,
	linux-kernel, linux-mm

On 05/23/2012 12:37 AM, Andi Kleen wrote:

> On Tue, May 22, 2012 at 09:08:47AM +0800, Alex Shi wrote:
>> On 05/21/2012 04:30 PM, Alex Shi wrote:
>>
>>> when mprotect just change prots of non-present pages, current mprotect
>>> still do the tlb flush in check_protection().
>>> but according to 4.10.2.3 Intel SDM V3A (
>>> www.intel.com/Assets/ja_JP/PDF/manual/253668.pdf ) at that time, TLB has
>>> no this lines for this page. So, tlb flush is just waste time. (for cr3
>>> rewrite, flush all tlb, or invlpg, like a 'nop' in intel cpu)
>>>
>>> Do we need to add the pte_present similar check here to prevent the
>>> unnecessary tlb flushing? I mean, are there real case in word, User like
>>> to change page prots before assign a physical page to it?
>>>
>>
>>
>> Any comments from linux-mm emailing list?
> 
> I would be careful with TLB optimizations if it's not a clear performance
> wins. A lot of these interactions are tricky and it's very easy to break
> things in subtle and hard to debug ways.
> 
> -Andi


Sure, functionality is fundamental.

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

* Re: unnecessary tlb flush in mprotect
  2012-05-23  0:06     ` Alex Shi
@ 2012-05-26 18:46       ` Hugh Dickins
  0 siblings, 0 replies; 5+ messages in thread
From: Hugh Dickins @ 2012-05-26 18:46 UTC (permalink / raw)
  To: Alex Shi
  Cc: Andi Kleen, H. Peter Anvin, cl, Peter Zijlstra, mgorman,
	Andrew Morton, linux-kernel, linux-mm

On Wed, 23 May 2012, Alex Shi wrote:
> On 05/23/2012 12:37 AM, Andi Kleen wrote:
> > On Tue, May 22, 2012 at 09:08:47AM +0800, Alex Shi wrote:
> >> On 05/21/2012 04:30 PM, Alex Shi wrote:
> >>
> >>> when mprotect just change prots of non-present pages, current mprotect
> >>> still do the tlb flush in check_protection().
> >>> but according to 4.10.2.3 Intel SDM V3A (
> >>> www.intel.com/Assets/ja_JP/PDF/manual/253668.pdf ) at that time, TLB has
> >>> no this lines for this page. So, tlb flush is just waste time. (for cr3
> >>> rewrite, flush all tlb, or invlpg, like a 'nop' in intel cpu)

Yes.

> >>>
> >>> Do we need to add the pte_present similar check here to prevent the
> >>> unnecessary tlb flushing? I mean, are there real case in word, User like
> >>> to change page prots before assign a physical page to it?

We have always simply assumed that mprotecting an entirely empty range
is too uncommon to bother with the slight complication of optimizing it.
Our assumption might be very wrong.

Hugh

> >>>
> >>
> >>
> >> Any comments from linux-mm emailing list?
> > 
> > I would be careful with TLB optimizations if it's not a clear performance
> > wins. A lot of these interactions are tricky and it's very easy to break
> > things in subtle and hard to debug ways.
> > 
> > -Andi
> 
> 
> Sure, functionality is fundamental.

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

end of thread, other threads:[~2012-05-26 18:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-21  8:30 unnecessary tlb flush in mprotect Alex Shi
2012-05-22  1:08 ` Alex Shi
2012-05-22 16:37   ` Andi Kleen
2012-05-23  0:06     ` Alex Shi
2012-05-26 18:46       ` Hugh Dickins

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.