Skip to content

Commit 61c7732

Browse files
Shaohua LiH. Peter Anvin
authored andcommitted
x86, mm: Avoid unnecessary TLB flush
In x86, access and dirty bits are set automatically by CPU when CPU accesses memory. When we go into the code path of below flush_tlb_fix_spurious_fault(), we already set dirty bit for pte and don't need flush tlb. This might mean tlb entry in some CPUs hasn't dirty bit set, but this doesn't matter. When the CPUs do page write, they will automatically check the bit and no software involved. On the other hand, flush tlb in below position is harmful. Test creates CPU number of threads, each thread writes to a same but random address in same vma range and we measure the total time. Under a 4 socket system, original time is 1.96s, while with the patch, the time is 0.8s. Under a 2 socket system, there is 20% time cut too. perf shows a lot of time are taking to send ipi/handle ipi for tlb flush. Signed-off-by: Shaohua Li <[email protected]> LKML-Reference: <[email protected]> Acked-by: Suresh Siddha <[email protected]> Cc: Andrea Archangeli <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 76be97c commit 61c7732

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm,
603603
pte_update(mm, addr, ptep);
604604
}
605605

606+
#define flush_tlb_fix_spurious_fault(vma, address)
607+
606608
/*
607609
* clone_pgd_range(pgd_t *dst, pgd_t *src, int count);
608610
*

include/asm-generic/pgtable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addres
129129
#define move_pte(pte, prot, old_addr, new_addr) (pte)
130130
#endif
131131

132+
#ifndef flush_tlb_fix_spurious_fault
133+
#define flush_tlb_fix_spurious_fault(vma, address) flush_tlb_page(vma, address)
134+
#endif
135+
132136
#ifndef pgprot_noncached
133137
#define pgprot_noncached(prot) (prot)
134138
#endif

mm/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,7 @@ static inline int handle_pte_fault(struct mm_struct *mm,
31473147
* with threads.
31483148
*/
31493149
if (flags & FAULT_FLAG_WRITE)
3150-
flush_tlb_page(vma, address);
3150+
flush_tlb_fix_spurious_fault(vma, address);
31513151
}
31523152
unlock:
31533153
pte_unmap_unlock(pte, ptl);

0 commit comments

Comments
 (0)