aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic/tlb.h
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2011-05-24 20:12:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-05-25 11:39:16 -0400
commite303297e6c3a7b847c4731eb14006ca6b435ecca (patch)
treec2bbec8fb0cad1405f4a3ff908cd1d22abcd3e77 /include/asm-generic/tlb.h
parent267239116987d64850ad2037d8e0f3071dc3b5ce (diff)
mm: extended batches for generic mmu_gather
Instead of using a single batch (the small on-stack, or an allocated page), try and extend the batch every time it runs out and only flush once either the extend fails or we're done. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Requested-by: Nick Piggin <npiggin@kernel.dk> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Hugh Dickins <hughd@google.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: David Miller <davem@davemloft.net> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Russell King <rmk@arm.linux.org.uk> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Jeff Dike <jdike@addtoit.com> Cc: Richard Weinberger <richard@nod.at> Cc: Tony Luck <tony.luck@intel.com> Cc: Mel Gorman <mel@csn.ul.ie> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Nick Piggin <npiggin@kernel.dk> Cc: Namhyung Kim <namhyung@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/asm-generic/tlb.h')
-rw-r--r--include/asm-generic/tlb.h129
1 files changed, 83 insertions, 46 deletions
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
index 74f80f6b6cf1..5a946a08ff9d 100644
--- a/include/asm-generic/tlb.h
+++ b/include/asm-generic/tlb.h
@@ -19,16 +19,6 @@
19#include <asm/pgalloc.h> 19#include <asm/pgalloc.h>
20#include <asm/tlbflush.h> 20#include <asm/tlbflush.h>
21 21
22/*
23 * For UP we don't need to worry about TLB flush
24 * and page free order so much..
25 */
26#ifdef CONFIG_SMP
27 #define tlb_fast_mode(tlb) ((tlb)->nr == ~0U)
28#else
29 #define tlb_fast_mode(tlb) 1
30#endif
31
32#ifdef CONFIG_HAVE_RCU_TABLE_FREE 22#ifdef CONFIG_HAVE_RCU_TABLE_FREE
33/* 23/*
34 * Semi RCU freeing of the page directories. 24 * Semi RCU freeing of the page directories.
@@ -78,6 +68,16 @@ extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
78 */ 68 */
79#define MMU_GATHER_BUNDLE 8 69#define MMU_GATHER_BUNDLE 8
80 70
71struct mmu_gather_batch {
72 struct mmu_gather_batch *next;
73 unsigned int nr;
74 unsigned int max;
75 struct page *pages[0];
76};
77
78#define MAX_GATHER_BATCH \
79 ((PAGE_SIZE - sizeof(struct mmu_gather_batch)) / sizeof(void *))
80
81/* struct mmu_gather is an opaque type used by the mm code for passing around 81/* struct mmu_gather is an opaque type used by the mm code for passing around
82 * any data needed by arch specific code for tlb_remove_page. 82 * any data needed by arch specific code for tlb_remove_page.
83 */ 83 */
@@ -86,22 +86,48 @@ struct mmu_gather {
86#ifdef CONFIG_HAVE_RCU_TABLE_FREE 86#ifdef CONFIG_HAVE_RCU_TABLE_FREE
87 struct mmu_table_batch *batch; 87 struct mmu_table_batch *batch;
88#endif 88#endif
89 unsigned int nr; /* set to ~0U means fast mode */ 89 unsigned int need_flush : 1, /* Did free PTEs */
90 unsigned int max; /* nr < max */ 90 fast_mode : 1; /* No batching */
91 unsigned int need_flush;/* Really unmapped some ptes? */ 91
92 unsigned int fullmm; /* non-zero means full mm flush */ 92 unsigned int fullmm;
93 struct page **pages; 93
94 struct page *local[MMU_GATHER_BUNDLE]; 94 struct mmu_gather_batch *active;
95 struct mmu_gather_batch local;
96 struct page *__pages[MMU_GATHER_BUNDLE];
95}; 97};
96 98
97static inline void __tlb_alloc_page(struct mmu_gather *tlb) 99/*
100 * For UP we don't need to worry about TLB flush
101 * and page free order so much..
102 */
103#ifdef CONFIG_SMP
104 #define tlb_fast_mode(tlb) (tlb->fast_mode)
105#else
106 #define tlb_fast_mode(tlb) 1
107#endif
108
109static inline int tlb_next_batch(struct mmu_gather *tlb)
98{ 110{
99 unsigned long addr = __get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0); 111 struct mmu_gather_batch *batch;
100 112
101 if (addr) { 113 batch = tlb->active;
102 tlb->pages = (void *)addr; 114 if (batch->next) {
103 tlb->max = PAGE_SIZE / sizeof(struct page *); 115 tlb->active = batch->next;
116 return 1;
104 } 117 }
118
119 batch = (void *)__get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0);
120 if (!batch)
121 return 0;
122
123 batch->next = NULL;
124 batch->nr = 0;
125 batch->max = MAX_GATHER_BATCH;
126
127 tlb->active->next = batch;
128 tlb->active = batch;
129
130 return 1;
105} 131}
106 132
107/* tlb_gather_mmu 133/* tlb_gather_mmu
@@ -114,16 +140,13 @@ tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, bool fullmm)
114{ 140{
115 tlb->mm = mm; 141 tlb->mm = mm;
116 142
117 tlb->max = ARRAY_SIZE(tlb->local); 143 tlb->fullmm = fullmm;
118 tlb->pages = tlb->local; 144 tlb->need_flush = 0;
119 145 tlb->fast_mode = (num_possible_cpus() == 1);
120 if (num_online_cpus() > 1) { 146 tlb->local.next = NULL;
121 tlb->nr = 0; 147 tlb->local.nr = 0;
122 __tlb_alloc_page(tlb); 148 tlb->local.max = ARRAY_SIZE(tlb->__pages);
123 } else /* Use fast mode if only one CPU is online */ 149 tlb->active = &tlb->local;
124 tlb->nr = ~0U;
125
126 tlb->fullmm = fullmm;
127 150
128#ifdef CONFIG_HAVE_RCU_TABLE_FREE 151#ifdef CONFIG_HAVE_RCU_TABLE_FREE
129 tlb->batch = NULL; 152 tlb->batch = NULL;
@@ -133,6 +156,8 @@ tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, bool fullmm)
133static inline void 156static inline void
134tlb_flush_mmu(struct mmu_gather *tlb) 157tlb_flush_mmu(struct mmu_gather *tlb)
135{ 158{
159 struct mmu_gather_batch *batch;
160
136 if (!tlb->need_flush) 161 if (!tlb->need_flush)
137 return; 162 return;
138 tlb->need_flush = 0; 163 tlb->need_flush = 0;
@@ -140,17 +165,15 @@ tlb_flush_mmu(struct mmu_gather *tlb)
140#ifdef CONFIG_HAVE_RCU_TABLE_FREE 165#ifdef CONFIG_HAVE_RCU_TABLE_FREE
141 tlb_table_flush(tlb); 166 tlb_table_flush(tlb);
142#endif 167#endif
143 if (!tlb_fast_mode(tlb)) { 168
144 free_pages_and_swap_cache(tlb->pages, tlb->nr); 169 if (tlb_fast_mode(tlb))
145 tlb->nr = 0; 170 return;
146 /* 171
147 * If we are using the local on-stack array of pages for MMU 172 for (batch = &tlb->local; batch; batch = batch->next) {
148 * gather, try allocating an off-stack array again as we have 173 free_pages_and_swap_cache(batch->pages, batch->nr);
149 * recently freed pages. 174 batch->nr = 0;
150 */
151 if (tlb->pages == tlb->local)
152 __tlb_alloc_page(tlb);
153 } 175 }
176 tlb->active = &tlb->local;
154} 177}
155 178
156/* tlb_finish_mmu 179/* tlb_finish_mmu
@@ -160,13 +183,18 @@ tlb_flush_mmu(struct mmu_gather *tlb)
160static inline void 183static inline void
161tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end) 184tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
162{ 185{
186 struct mmu_gather_batch *batch, *next;
187
163 tlb_flush_mmu(tlb); 188 tlb_flush_mmu(tlb);
164 189
165 /* keep the page table cache within bounds */ 190 /* keep the page table cache within bounds */
166 check_pgt_cache(); 191 check_pgt_cache();
167 192
168 if (tlb->pages != tlb->local) 193 for (batch = tlb->local.next; batch; batch = next) {
169 free_pages((unsigned long)tlb->pages, 0); 194 next = batch->next;
195 free_pages((unsigned long)batch, 0);
196 }
197 tlb->local.next = NULL;
170} 198}
171 199
172/* __tlb_remove_page 200/* __tlb_remove_page
@@ -177,15 +205,24 @@ tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
177 */ 205 */
178static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page) 206static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
179{ 207{
208 struct mmu_gather_batch *batch;
209
180 tlb->need_flush = 1; 210 tlb->need_flush = 1;
211
181 if (tlb_fast_mode(tlb)) { 212 if (tlb_fast_mode(tlb)) {
182 free_page_and_swap_cache(page); 213 free_page_and_swap_cache(page);
183 return 1; /* avoid calling tlb_flush_mmu() */ 214 return 1; /* avoid calling tlb_flush_mmu() */
184 } 215 }
185 tlb->pages[tlb->nr++] = page;
186 VM_BUG_ON(tlb->nr > tlb->max);
187 216
188 return tlb->max - tlb->nr; 217 batch = tlb->active;
218 batch->pages[batch->nr++] = page;
219 VM_BUG_ON(batch->nr > batch->max);
220 if (batch->nr == batch->max) {
221 if (!tlb_next_batch(tlb))
222 return 0;
223 }
224
225 return batch->max - batch->nr;
189} 226}
190 227
191/* tlb_remove_page 228/* tlb_remove_page