diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-generic/tlb.h | 96 | ||||
-rw-r--r-- | include/linux/mm.h | 2 |
2 files changed, 70 insertions, 28 deletions
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index e43f9766259f..2d3547c84235 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h | |||
@@ -5,6 +5,8 @@ | |||
5 | * Copyright 2001 Red Hat, Inc. | 5 | * Copyright 2001 Red Hat, Inc. |
6 | * Based on code from mm/memory.c Copyright Linus Torvalds and others. | 6 | * Based on code from mm/memory.c Copyright Linus Torvalds and others. |
7 | * | 7 | * |
8 | * Copyright 2011 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> | ||
9 | * | ||
8 | * This program is free software; you can redistribute it and/or | 10 | * This program is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU General Public License | 11 | * modify it under the terms of the GNU General Public License |
10 | * as published by the Free Software Foundation; either version | 12 | * as published by the Free Software Foundation; either version |
@@ -22,51 +24,71 @@ | |||
22 | * and page free order so much.. | 24 | * and page free order so much.. |
23 | */ | 25 | */ |
24 | #ifdef CONFIG_SMP | 26 | #ifdef CONFIG_SMP |
25 | #ifdef ARCH_FREE_PTR_NR | ||
26 | #define FREE_PTR_NR ARCH_FREE_PTR_NR | ||
27 | #else | ||
28 | #define FREE_PTE_NR 506 | ||
29 | #endif | ||
30 | #define tlb_fast_mode(tlb) ((tlb)->nr == ~0U) | 27 | #define tlb_fast_mode(tlb) ((tlb)->nr == ~0U) |
31 | #else | 28 | #else |
32 | #define FREE_PTE_NR 1 | ||
33 | #define tlb_fast_mode(tlb) 1 | 29 | #define tlb_fast_mode(tlb) 1 |
34 | #endif | 30 | #endif |
35 | 31 | ||
32 | /* | ||
33 | * If we can't allocate a page to make a big batch of page pointers | ||
34 | * to work on, then just handle a few from the on-stack structure. | ||
35 | */ | ||
36 | #define MMU_GATHER_BUNDLE 8 | ||
37 | |||
36 | /* struct mmu_gather is an opaque type used by the mm code for passing around | 38 | /* struct mmu_gather is an opaque type used by the mm code for passing around |
37 | * any data needed by arch specific code for tlb_remove_page. | 39 | * any data needed by arch specific code for tlb_remove_page. |
38 | */ | 40 | */ |
39 | struct mmu_gather { | 41 | struct mmu_gather { |
40 | struct mm_struct *mm; | 42 | struct mm_struct *mm; |
41 | unsigned int nr; /* set to ~0U means fast mode */ | 43 | unsigned int nr; /* set to ~0U means fast mode */ |
44 | unsigned int max; /* nr < max */ | ||
42 | unsigned int need_flush;/* Really unmapped some ptes? */ | 45 | unsigned int need_flush;/* Really unmapped some ptes? */ |
43 | unsigned int fullmm; /* non-zero means full mm flush */ | 46 | unsigned int fullmm; /* non-zero means full mm flush */ |
44 | struct page * pages[FREE_PTE_NR]; | 47 | #ifdef HAVE_ARCH_MMU_GATHER |
48 | struct arch_mmu_gather arch; | ||
49 | #endif | ||
50 | struct page **pages; | ||
51 | struct page *local[MMU_GATHER_BUNDLE]; | ||
45 | }; | 52 | }; |
46 | 53 | ||
47 | /* Users of the generic TLB shootdown code must declare this storage space. */ | 54 | static inline void __tlb_alloc_page(struct mmu_gather *tlb) |
48 | DECLARE_PER_CPU(struct mmu_gather, mmu_gathers); | 55 | { |
56 | unsigned long addr = __get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0); | ||
57 | |||
58 | if (addr) { | ||
59 | tlb->pages = (void *)addr; | ||
60 | tlb->max = PAGE_SIZE / sizeof(struct page *); | ||
61 | } | ||
62 | } | ||
49 | 63 | ||
50 | /* tlb_gather_mmu | 64 | /* tlb_gather_mmu |
51 | * Return a pointer to an initialized struct mmu_gather. | 65 | * Called to initialize an (on-stack) mmu_gather structure for page-table |
66 | * tear-down from @mm. The @fullmm argument is used when @mm is without | ||
67 | * users and we're going to destroy the full address space (exit/execve). | ||
52 | */ | 68 | */ |
53 | static inline struct mmu_gather * | 69 | static inline void |
54 | tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush) | 70 | tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, bool fullmm) |
55 | { | 71 | { |
56 | struct mmu_gather *tlb = &get_cpu_var(mmu_gathers); | ||
57 | |||
58 | tlb->mm = mm; | 72 | tlb->mm = mm; |
59 | 73 | ||
60 | /* Use fast mode if only one CPU is online */ | 74 | tlb->max = ARRAY_SIZE(tlb->local); |
61 | tlb->nr = num_online_cpus() > 1 ? 0U : ~0U; | 75 | tlb->pages = tlb->local; |
76 | |||
77 | if (num_online_cpus() > 1) { | ||
78 | tlb->nr = 0; | ||
79 | __tlb_alloc_page(tlb); | ||
80 | } else /* Use fast mode if only one CPU is online */ | ||
81 | tlb->nr = ~0U; | ||
62 | 82 | ||
63 | tlb->fullmm = full_mm_flush; | 83 | tlb->fullmm = fullmm; |
64 | 84 | ||
65 | return tlb; | 85 | #ifdef HAVE_ARCH_MMU_GATHER |
86 | tlb->arch = ARCH_MMU_GATHER_INIT; | ||
87 | #endif | ||
66 | } | 88 | } |
67 | 89 | ||
68 | static inline void | 90 | static inline void |
69 | tlb_flush_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end) | 91 | tlb_flush_mmu(struct mmu_gather *tlb) |
70 | { | 92 | { |
71 | if (!tlb->need_flush) | 93 | if (!tlb->need_flush) |
72 | return; | 94 | return; |
@@ -75,6 +97,13 @@ tlb_flush_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end) | |||
75 | if (!tlb_fast_mode(tlb)) { | 97 | if (!tlb_fast_mode(tlb)) { |
76 | free_pages_and_swap_cache(tlb->pages, tlb->nr); | 98 | free_pages_and_swap_cache(tlb->pages, tlb->nr); |
77 | tlb->nr = 0; | 99 | tlb->nr = 0; |
100 | /* | ||
101 | * If we are using the local on-stack array of pages for MMU | ||
102 | * gather, try allocating an off-stack array again as we have | ||
103 | * recently freed pages. | ||
104 | */ | ||
105 | if (tlb->pages == tlb->local) | ||
106 | __tlb_alloc_page(tlb); | ||
78 | } | 107 | } |
79 | } | 108 | } |
80 | 109 | ||
@@ -85,29 +114,42 @@ tlb_flush_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end) | |||
85 | static inline void | 114 | static inline void |
86 | tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end) | 115 | tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end) |
87 | { | 116 | { |
88 | tlb_flush_mmu(tlb, start, end); | 117 | tlb_flush_mmu(tlb); |
89 | 118 | ||
90 | /* keep the page table cache within bounds */ | 119 | /* keep the page table cache within bounds */ |
91 | check_pgt_cache(); | 120 | check_pgt_cache(); |
92 | 121 | ||
93 | put_cpu_var(mmu_gathers); | 122 | if (tlb->pages != tlb->local) |
123 | free_pages((unsigned long)tlb->pages, 0); | ||
94 | } | 124 | } |
95 | 125 | ||
96 | /* tlb_remove_page | 126 | /* __tlb_remove_page |
97 | * Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)), while | 127 | * Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)), while |
98 | * handling the additional races in SMP caused by other CPUs caching valid | 128 | * handling the additional races in SMP caused by other CPUs caching valid |
99 | * mappings in their TLBs. | 129 | * mappings in their TLBs. Returns the number of free page slots left. |
130 | * When out of page slots we must call tlb_flush_mmu(). | ||
100 | */ | 131 | */ |
101 | static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) | 132 | static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page) |
102 | { | 133 | { |
103 | tlb->need_flush = 1; | 134 | tlb->need_flush = 1; |
104 | if (tlb_fast_mode(tlb)) { | 135 | if (tlb_fast_mode(tlb)) { |
105 | free_page_and_swap_cache(page); | 136 | free_page_and_swap_cache(page); |
106 | return; | 137 | return 1; /* avoid calling tlb_flush_mmu() */ |
107 | } | 138 | } |
108 | tlb->pages[tlb->nr++] = page; | 139 | tlb->pages[tlb->nr++] = page; |
109 | if (tlb->nr >= FREE_PTE_NR) | 140 | VM_BUG_ON(tlb->nr > tlb->max); |
110 | tlb_flush_mmu(tlb, 0, 0); | 141 | |
142 | return tlb->max - tlb->nr; | ||
143 | } | ||
144 | |||
145 | /* tlb_remove_page | ||
146 | * Similar to __tlb_remove_page but will call tlb_flush_mmu() itself when | ||
147 | * required. | ||
148 | */ | ||
149 | static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) | ||
150 | { | ||
151 | if (!__tlb_remove_page(tlb, page)) | ||
152 | tlb_flush_mmu(tlb); | ||
111 | } | 153 | } |
112 | 154 | ||
113 | /** | 155 | /** |
diff --git a/include/linux/mm.h b/include/linux/mm.h index d2948af126ca..ffcce9bf2b54 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -906,7 +906,7 @@ int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address, | |||
906 | unsigned long size); | 906 | unsigned long size); |
907 | unsigned long zap_page_range(struct vm_area_struct *vma, unsigned long address, | 907 | unsigned long zap_page_range(struct vm_area_struct *vma, unsigned long address, |
908 | unsigned long size, struct zap_details *); | 908 | unsigned long size, struct zap_details *); |
909 | unsigned long unmap_vmas(struct mmu_gather **tlb, | 909 | unsigned long unmap_vmas(struct mmu_gather *tlb, |
910 | struct vm_area_struct *start_vma, unsigned long start_addr, | 910 | struct vm_area_struct *start_vma, unsigned long start_addr, |
911 | unsigned long end_addr, unsigned long *nr_accounted, | 911 | unsigned long end_addr, unsigned long *nr_accounted, |
912 | struct zap_details *); | 912 | struct zap_details *); |