Skip to contentSkip to conversation

unnecessary tlb flush in mprotect

DISCUSSION Alex Shi 3 participants 5 messages May 21, 2012 – May 26, 2012

lore
Share & tools
lore

Alex Shi

author
#0 lore raw

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

author
#1 lore raw
Quoted 11 lines · Alex Shi

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?

Quoted 3 lines

Alex Shi

#2 lore raw
Quoted 9 lines · Alex Shi
Quoted 7 lines · Alex Shi

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)

Quoted 7 lines
Quoted 4 lines

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

Signature · 1 line
[email protected] -- Speaking for myself only
author
#3 lore raw
Quoted 16 lines · Andi Kleen
Quoted 15 lines · Alex Shi
Quoted 11 lines · Alex Shi

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?

Quoted 7 lines
Quoted 1 line

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.

#4 lore raw
Quoted 10 lines · Alex Shi
Quoted 9 lines · Andi Kleen
Quoted 8 lines · Alex Shi
Quoted 6 lines · Alex Shi

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.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

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

Quoted 13 lines
Quoted 10 lines
Quoted 4 lines
Quoted 1 line

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.