diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2011-05-24 20:12:00 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-05-25 11:39:16 -0400 |
commit | 267239116987d64850ad2037d8e0f3071dc3b5ce (patch) | |
tree | 142595897f7fc7bb673b791891dcc2fab31f6e91 /arch | |
parent | 1c395176962176660bb108f90e97e1686cfe0d85 (diff) |
mm, powerpc: move the RCU page-table freeing into generic code
In case other architectures require RCU freed page-tables to implement
gup_fast() and software filled hashes and similar things, provide the
means to do so by moving the logic into generic code.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Requested-by: David Miller <davem@davemloft.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
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: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Hugh Dickins <hughd@google.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 'arch')
-rw-r--r-- | arch/Kconfig | 3 | ||||
-rw-r--r-- | arch/powerpc/Kconfig | 1 | ||||
-rw-r--r-- | arch/powerpc/include/asm/pgalloc.h | 21 | ||||
-rw-r--r-- | arch/powerpc/include/asm/tlb.h | 10 | ||||
-rw-r--r-- | arch/powerpc/mm/pgtable.c | 98 | ||||
-rw-r--r-- | arch/powerpc/mm/tlb_hash32.c | 3 | ||||
-rw-r--r-- | arch/powerpc/mm/tlb_hash64.c | 3 | ||||
-rw-r--r-- | arch/powerpc/mm/tlb_nohash.c | 3 |
8 files changed, 22 insertions, 120 deletions
diff --git a/arch/Kconfig b/arch/Kconfig index 8d24bacaa61e..26b0e2397a57 100644 --- a/arch/Kconfig +++ b/arch/Kconfig | |||
@@ -175,4 +175,7 @@ config HAVE_ARCH_JUMP_LABEL | |||
175 | config HAVE_ARCH_MUTEX_CPU_RELAX | 175 | config HAVE_ARCH_MUTEX_CPU_RELAX |
176 | bool | 176 | bool |
177 | 177 | ||
178 | config HAVE_RCU_TABLE_FREE | ||
179 | bool | ||
180 | |||
178 | source "kernel/gcov/Kconfig" | 181 | source "kernel/gcov/Kconfig" |
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index a3128ca0fe11..423145a6f7ba 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig | |||
@@ -140,6 +140,7 @@ config PPC | |||
140 | select IRQ_PER_CPU | 140 | select IRQ_PER_CPU |
141 | select GENERIC_IRQ_SHOW | 141 | select GENERIC_IRQ_SHOW |
142 | select GENERIC_IRQ_SHOW_LEVEL | 142 | select GENERIC_IRQ_SHOW_LEVEL |
143 | select HAVE_RCU_TABLE_FREE if SMP | ||
143 | 144 | ||
144 | config EARLY_PRINTK | 145 | config EARLY_PRINTK |
145 | bool | 146 | bool |
diff --git a/arch/powerpc/include/asm/pgalloc.h b/arch/powerpc/include/asm/pgalloc.h index df1b4cbb2e70..bf301ac62f35 100644 --- a/arch/powerpc/include/asm/pgalloc.h +++ b/arch/powerpc/include/asm/pgalloc.h | |||
@@ -31,14 +31,29 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage) | |||
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #ifdef CONFIG_SMP | 33 | #ifdef CONFIG_SMP |
34 | extern void pgtable_free_tlb(struct mmu_gather *tlb, void *table, unsigned shift); | 34 | struct mmu_gather; |
35 | extern void pte_free_finish(struct mmu_gather *tlb); | 35 | extern void tlb_remove_table(struct mmu_gather *, void *); |
36 | |||
37 | static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift) | ||
38 | { | ||
39 | unsigned long pgf = (unsigned long)table; | ||
40 | BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE); | ||
41 | pgf |= shift; | ||
42 | tlb_remove_table(tlb, (void *)pgf); | ||
43 | } | ||
44 | |||
45 | static inline void __tlb_remove_table(void *_table) | ||
46 | { | ||
47 | void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE); | ||
48 | unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE; | ||
49 | |||
50 | pgtable_free(table, shift); | ||
51 | } | ||
36 | #else /* CONFIG_SMP */ | 52 | #else /* CONFIG_SMP */ |
37 | static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, unsigned shift) | 53 | static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, unsigned shift) |
38 | { | 54 | { |
39 | pgtable_free(table, shift); | 55 | pgtable_free(table, shift); |
40 | } | 56 | } |
41 | static inline void pte_free_finish(struct mmu_gather *tlb) { } | ||
42 | #endif /* !CONFIG_SMP */ | 57 | #endif /* !CONFIG_SMP */ |
43 | 58 | ||
44 | static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *ptepage, | 59 | static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *ptepage, |
diff --git a/arch/powerpc/include/asm/tlb.h b/arch/powerpc/include/asm/tlb.h index 8f0ed7adcd12..e2b428b0f7ba 100644 --- a/arch/powerpc/include/asm/tlb.h +++ b/arch/powerpc/include/asm/tlb.h | |||
@@ -28,16 +28,6 @@ | |||
28 | #define tlb_start_vma(tlb, vma) do { } while (0) | 28 | #define tlb_start_vma(tlb, vma) do { } while (0) |
29 | #define tlb_end_vma(tlb, vma) do { } while (0) | 29 | #define tlb_end_vma(tlb, vma) do { } while (0) |
30 | 30 | ||
31 | #define HAVE_ARCH_MMU_GATHER 1 | ||
32 | |||
33 | struct pte_freelist_batch; | ||
34 | |||
35 | struct arch_mmu_gather { | ||
36 | struct pte_freelist_batch *batch; | ||
37 | }; | ||
38 | |||
39 | #define ARCH_MMU_GATHER_INIT (struct arch_mmu_gather){ .batch = NULL, } | ||
40 | |||
41 | extern void tlb_flush(struct mmu_gather *tlb); | 31 | extern void tlb_flush(struct mmu_gather *tlb); |
42 | 32 | ||
43 | /* Get the generic bits... */ | 33 | /* Get the generic bits... */ |
diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index 6e72788598f8..af40c8768a78 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c | |||
@@ -33,104 +33,6 @@ | |||
33 | 33 | ||
34 | #include "mmu_decl.h" | 34 | #include "mmu_decl.h" |
35 | 35 | ||
36 | #ifdef CONFIG_SMP | ||
37 | |||
38 | /* | ||
39 | * Handle batching of page table freeing on SMP. Page tables are | ||
40 | * queued up and send to be freed later by RCU in order to avoid | ||
41 | * freeing a page table page that is being walked without locks | ||
42 | */ | ||
43 | |||
44 | static unsigned long pte_freelist_forced_free; | ||
45 | |||
46 | struct pte_freelist_batch | ||
47 | { | ||
48 | struct rcu_head rcu; | ||
49 | unsigned int index; | ||
50 | unsigned long tables[0]; | ||
51 | }; | ||
52 | |||
53 | #define PTE_FREELIST_SIZE \ | ||
54 | ((PAGE_SIZE - sizeof(struct pte_freelist_batch)) \ | ||
55 | / sizeof(unsigned long)) | ||
56 | |||
57 | static void pte_free_smp_sync(void *arg) | ||
58 | { | ||
59 | /* Do nothing, just ensure we sync with all CPUs */ | ||
60 | } | ||
61 | |||
62 | /* This is only called when we are critically out of memory | ||
63 | * (and fail to get a page in pte_free_tlb). | ||
64 | */ | ||
65 | static void pgtable_free_now(void *table, unsigned shift) | ||
66 | { | ||
67 | pte_freelist_forced_free++; | ||
68 | |||
69 | smp_call_function(pte_free_smp_sync, NULL, 1); | ||
70 | |||
71 | pgtable_free(table, shift); | ||
72 | } | ||
73 | |||
74 | static void pte_free_rcu_callback(struct rcu_head *head) | ||
75 | { | ||
76 | struct pte_freelist_batch *batch = | ||
77 | container_of(head, struct pte_freelist_batch, rcu); | ||
78 | unsigned int i; | ||
79 | |||
80 | for (i = 0; i < batch->index; i++) { | ||
81 | void *table = (void *)(batch->tables[i] & ~MAX_PGTABLE_INDEX_SIZE); | ||
82 | unsigned shift = batch->tables[i] & MAX_PGTABLE_INDEX_SIZE; | ||
83 | |||
84 | pgtable_free(table, shift); | ||
85 | } | ||
86 | |||
87 | free_page((unsigned long)batch); | ||
88 | } | ||
89 | |||
90 | static void pte_free_submit(struct pte_freelist_batch *batch) | ||
91 | { | ||
92 | call_rcu_sched(&batch->rcu, pte_free_rcu_callback); | ||
93 | } | ||
94 | |||
95 | void pgtable_free_tlb(struct mmu_gather *tlb, void *table, unsigned shift) | ||
96 | { | ||
97 | struct pte_freelist_batch **batchp = &tlb->arch.batch; | ||
98 | unsigned long pgf; | ||
99 | |||
100 | if (atomic_read(&tlb->mm->mm_users) < 2) { | ||
101 | pgtable_free(table, shift); | ||
102 | return; | ||
103 | } | ||
104 | |||
105 | if (*batchp == NULL) { | ||
106 | *batchp = (struct pte_freelist_batch *)__get_free_page(GFP_ATOMIC); | ||
107 | if (*batchp == NULL) { | ||
108 | pgtable_free_now(table, shift); | ||
109 | return; | ||
110 | } | ||
111 | (*batchp)->index = 0; | ||
112 | } | ||
113 | BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE); | ||
114 | pgf = (unsigned long)table | shift; | ||
115 | (*batchp)->tables[(*batchp)->index++] = pgf; | ||
116 | if ((*batchp)->index == PTE_FREELIST_SIZE) { | ||
117 | pte_free_submit(*batchp); | ||
118 | *batchp = NULL; | ||
119 | } | ||
120 | } | ||
121 | |||
122 | void pte_free_finish(struct mmu_gather *tlb) | ||
123 | { | ||
124 | struct pte_freelist_batch **batchp = &tlb->arch.batch; | ||
125 | |||
126 | if (*batchp == NULL) | ||
127 | return; | ||
128 | pte_free_submit(*batchp); | ||
129 | *batchp = NULL; | ||
130 | } | ||
131 | |||
132 | #endif /* CONFIG_SMP */ | ||
133 | |||
134 | static inline int is_exec_fault(void) | 36 | static inline int is_exec_fault(void) |
135 | { | 37 | { |
136 | return current->thread.regs && TRAP(current->thread.regs) == 0x400; | 38 | return current->thread.regs && TRAP(current->thread.regs) == 0x400; |
diff --git a/arch/powerpc/mm/tlb_hash32.c b/arch/powerpc/mm/tlb_hash32.c index d555cdb06bc8..27b863c14941 100644 --- a/arch/powerpc/mm/tlb_hash32.c +++ b/arch/powerpc/mm/tlb_hash32.c | |||
@@ -71,9 +71,6 @@ void tlb_flush(struct mmu_gather *tlb) | |||
71 | */ | 71 | */ |
72 | _tlbia(); | 72 | _tlbia(); |
73 | } | 73 | } |
74 | |||
75 | /* Push out batch of freed page tables */ | ||
76 | pte_free_finish(tlb); | ||
77 | } | 74 | } |
78 | 75 | ||
79 | /* | 76 | /* |
diff --git a/arch/powerpc/mm/tlb_hash64.c b/arch/powerpc/mm/tlb_hash64.c index 5c94ca34cd79..31f18207970b 100644 --- a/arch/powerpc/mm/tlb_hash64.c +++ b/arch/powerpc/mm/tlb_hash64.c | |||
@@ -165,9 +165,6 @@ void tlb_flush(struct mmu_gather *tlb) | |||
165 | __flush_tlb_pending(tlbbatch); | 165 | __flush_tlb_pending(tlbbatch); |
166 | 166 | ||
167 | put_cpu_var(ppc64_tlb_batch); | 167 | put_cpu_var(ppc64_tlb_batch); |
168 | |||
169 | /* Push out batch of freed page tables */ | ||
170 | pte_free_finish(tlb); | ||
171 | } | 168 | } |
172 | 169 | ||
173 | /** | 170 | /** |
diff --git a/arch/powerpc/mm/tlb_nohash.c b/arch/powerpc/mm/tlb_nohash.c index 8eaf67d32043..0bdad3aecc67 100644 --- a/arch/powerpc/mm/tlb_nohash.c +++ b/arch/powerpc/mm/tlb_nohash.c | |||
@@ -299,9 +299,6 @@ EXPORT_SYMBOL(flush_tlb_range); | |||
299 | void tlb_flush(struct mmu_gather *tlb) | 299 | void tlb_flush(struct mmu_gather *tlb) |
300 | { | 300 | { |
301 | flush_tlb_mm(tlb->mm); | 301 | flush_tlb_mm(tlb->mm); |
302 | |||
303 | /* Push out batch of freed page tables */ | ||
304 | pte_free_finish(tlb); | ||
305 | } | 302 | } |
306 | 303 | ||
307 | /* | 304 | /* |