diff options
Diffstat (limited to 'mm')
-rw-r--r-- | mm/slab.c | 537 |
1 files changed, 376 insertions, 161 deletions
@@ -121,6 +121,120 @@ | |||
121 | #include <asm/page.h> | 121 | #include <asm/page.h> |
122 | 122 | ||
123 | /* | 123 | /* |
124 | * On !PREEMPT_RT, raw irq flags are used as a per-CPU locking | ||
125 | * mechanism. | ||
126 | * | ||
127 | * On PREEMPT_RT, we use per-CPU locks for this. That's why the | ||
128 | * calling convention is changed slightly: a new 'flags' argument | ||
129 | * is passed to 'irq disable/enable' - the PREEMPT_RT code stores | ||
130 | * the CPU number of the lock there. | ||
131 | */ | ||
132 | #ifndef CONFIG_PREEMPT_RT | ||
133 | |||
134 | # define slab_irq_disable(cpu) \ | ||
135 | do { local_irq_disable(); (cpu) = smp_processor_id(); } while (0) | ||
136 | # define slab_irq_enable(cpu) local_irq_enable() | ||
137 | |||
138 | static inline void slab_irq_disable_this_rt(int cpu) | ||
139 | { | ||
140 | } | ||
141 | |||
142 | static inline void slab_irq_enable_rt(int cpu) | ||
143 | { | ||
144 | } | ||
145 | |||
146 | # define slab_irq_save(flags, cpu) \ | ||
147 | do { local_irq_save(flags); (cpu) = smp_processor_id(); } while (0) | ||
148 | # define slab_irq_restore(flags, cpu) local_irq_restore(flags) | ||
149 | |||
150 | /* | ||
151 | * In the __GFP_WAIT case we enable/disable interrupts on !PREEMPT_RT, | ||
152 | * which has no per-CPU locking effect since we are holding the cache | ||
153 | * lock in that case already. | ||
154 | */ | ||
155 | static void slab_irq_enable_GFP_WAIT(gfp_t flags, int *cpu) | ||
156 | { | ||
157 | if (flags & __GFP_WAIT) | ||
158 | local_irq_enable(); | ||
159 | } | ||
160 | |||
161 | static void slab_irq_disable_GFP_WAIT(gfp_t flags, int *cpu) | ||
162 | { | ||
163 | if (flags & __GFP_WAIT) | ||
164 | local_irq_disable(); | ||
165 | } | ||
166 | |||
167 | # define slab_spin_lock_irq(lock, cpu) \ | ||
168 | do { spin_lock_irq(lock); (cpu) = smp_processor_id(); } while (0) | ||
169 | # define slab_spin_unlock_irq(lock, cpu) spin_unlock_irq(lock) | ||
170 | |||
171 | # define slab_spin_lock_irqsave(lock, flags, cpu) \ | ||
172 | do { spin_lock_irqsave(lock, flags); (cpu) = smp_processor_id(); } while (0) | ||
173 | # define slab_spin_unlock_irqrestore(lock, flags, cpu) \ | ||
174 | do { spin_unlock_irqrestore(lock, flags); } while (0) | ||
175 | |||
176 | #else /* CONFIG_PREEMPT_RT */ | ||
177 | |||
178 | /* | ||
179 | * Instead of serializing the per-cpu state by disabling interrupts we do so | ||
180 | * by a lock. This keeps the code preemptable - albeit at the cost of remote | ||
181 | * memory access when the task does get migrated away. | ||
182 | */ | ||
183 | DEFINE_PER_CPU_LOCKED(int, slab_irq_locks) = { 0, }; | ||
184 | |||
185 | static void _slab_irq_disable(int *cpu) | ||
186 | { | ||
187 | get_cpu_var_locked(slab_irq_locks, cpu); | ||
188 | } | ||
189 | |||
190 | #define slab_irq_disable(cpu) _slab_irq_disable(&(cpu)) | ||
191 | |||
192 | static inline void slab_irq_enable(int cpu) | ||
193 | { | ||
194 | put_cpu_var_locked(slab_irq_locks, cpu); | ||
195 | } | ||
196 | |||
197 | static inline void slab_irq_disable_this_rt(int cpu) | ||
198 | { | ||
199 | spin_lock(&__get_cpu_lock(slab_irq_locks, cpu)); | ||
200 | } | ||
201 | |||
202 | static inline void slab_irq_enable_rt(int cpu) | ||
203 | { | ||
204 | spin_unlock(&__get_cpu_lock(slab_irq_locks, cpu)); | ||
205 | } | ||
206 | |||
207 | # define slab_irq_save(flags, cpu) \ | ||
208 | do { slab_irq_disable(cpu); (void) (flags); } while (0) | ||
209 | # define slab_irq_restore(flags, cpu) \ | ||
210 | do { slab_irq_enable(cpu); (void) (flags); } while (0) | ||
211 | |||
212 | /* | ||
213 | * On PREEMPT_RT we have to drop the locks unconditionally to avoid lock | ||
214 | * recursion on the cache_grow()->alloc_slabmgmt() path. | ||
215 | */ | ||
216 | static void slab_irq_enable_GFP_WAIT(gfp_t flags, int *cpu) | ||
217 | { | ||
218 | slab_irq_enable(*cpu); | ||
219 | } | ||
220 | |||
221 | static void slab_irq_disable_GFP_WAIT(gfp_t flags, int *cpu) | ||
222 | { | ||
223 | slab_irq_disable(*cpu); | ||
224 | } | ||
225 | |||
226 | # define slab_spin_lock_irq(lock, cpu) \ | ||
227 | do { slab_irq_disable(cpu); spin_lock(lock); } while (0) | ||
228 | # define slab_spin_unlock_irq(lock, cpu) \ | ||
229 | do { spin_unlock(lock); slab_irq_enable(cpu); } while (0) | ||
230 | # define slab_spin_lock_irqsave(lock, flags, cpu) \ | ||
231 | do { slab_irq_disable(cpu); spin_lock_irqsave(lock, flags); } while (0) | ||
232 | # define slab_spin_unlock_irqrestore(lock, flags, cpu) \ | ||
233 | do { spin_unlock_irqrestore(lock, flags); slab_irq_enable(cpu); } while (0) | ||
234 | |||
235 | #endif /* CONFIG_PREEMPT_RT */ | ||
236 | |||
237 | /* | ||
124 | * DEBUG - 1 for kmem_cache_create() to honour; SLAB_RED_ZONE & SLAB_POISON. | 238 | * DEBUG - 1 for kmem_cache_create() to honour; SLAB_RED_ZONE & SLAB_POISON. |
125 | * 0 for faster, smaller code (especially in the critical paths). | 239 | * 0 for faster, smaller code (especially in the critical paths). |
126 | * | 240 | * |
@@ -316,7 +430,7 @@ struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS]; | |||
316 | static int drain_freelist(struct kmem_cache *cache, | 430 | static int drain_freelist(struct kmem_cache *cache, |
317 | struct kmem_list3 *l3, int tofree); | 431 | struct kmem_list3 *l3, int tofree); |
318 | static void free_block(struct kmem_cache *cachep, void **objpp, int len, | 432 | static void free_block(struct kmem_cache *cachep, void **objpp, int len, |
319 | int node); | 433 | int node, int *this_cpu); |
320 | static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp); | 434 | static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp); |
321 | static void cache_reap(struct work_struct *unused); | 435 | static void cache_reap(struct work_struct *unused); |
322 | 436 | ||
@@ -687,9 +801,10 @@ int slab_is_available(void) | |||
687 | 801 | ||
688 | static DEFINE_PER_CPU(struct delayed_work, reap_work); | 802 | static DEFINE_PER_CPU(struct delayed_work, reap_work); |
689 | 803 | ||
690 | static inline struct array_cache *cpu_cache_get(struct kmem_cache *cachep) | 804 | static inline struct array_cache * |
805 | cpu_cache_get(struct kmem_cache *cachep, int this_cpu) | ||
691 | { | 806 | { |
692 | return cachep->array[smp_processor_id()]; | 807 | return cachep->array[this_cpu]; |
693 | } | 808 | } |
694 | 809 | ||
695 | static inline struct kmem_cache *__find_general_cachep(size_t size, | 810 | static inline struct kmem_cache *__find_general_cachep(size_t size, |
@@ -930,7 +1045,7 @@ static int transfer_objects(struct array_cache *to, | |||
930 | #ifndef CONFIG_NUMA | 1045 | #ifndef CONFIG_NUMA |
931 | 1046 | ||
932 | #define drain_alien_cache(cachep, alien) do { } while (0) | 1047 | #define drain_alien_cache(cachep, alien) do { } while (0) |
933 | #define reap_alien(cachep, l3) do { } while (0) | 1048 | #define reap_alien(cachep, l3, this_cpu) 0 |
934 | 1049 | ||
935 | static inline struct array_cache **alloc_alien_cache(int node, int limit, gfp_t gfp) | 1050 | static inline struct array_cache **alloc_alien_cache(int node, int limit, gfp_t gfp) |
936 | { | 1051 | { |
@@ -941,27 +1056,28 @@ static inline void free_alien_cache(struct array_cache **ac_ptr) | |||
941 | { | 1056 | { |
942 | } | 1057 | } |
943 | 1058 | ||
944 | static inline int cache_free_alien(struct kmem_cache *cachep, void *objp) | 1059 | static inline int |
1060 | cache_free_alien(struct kmem_cache *cachep, void *objp, int *this_cpu) | ||
945 | { | 1061 | { |
946 | return 0; | 1062 | return 0; |
947 | } | 1063 | } |
948 | 1064 | ||
949 | static inline void *alternate_node_alloc(struct kmem_cache *cachep, | 1065 | static inline void *alternate_node_alloc(struct kmem_cache *cachep, |
950 | gfp_t flags) | 1066 | gfp_t flags, int *this_cpu) |
951 | { | 1067 | { |
952 | return NULL; | 1068 | return NULL; |
953 | } | 1069 | } |
954 | 1070 | ||
955 | static inline void *____cache_alloc_node(struct kmem_cache *cachep, | 1071 | static inline void *____cache_alloc_node(struct kmem_cache *cachep, |
956 | gfp_t flags, int nodeid) | 1072 | gfp_t flags, int nodeid, int *this_cpu) |
957 | { | 1073 | { |
958 | return NULL; | 1074 | return NULL; |
959 | } | 1075 | } |
960 | 1076 | ||
961 | #else /* CONFIG_NUMA */ | 1077 | #else /* CONFIG_NUMA */ |
962 | 1078 | ||
963 | static void *____cache_alloc_node(struct kmem_cache *, gfp_t, int); | 1079 | static void *____cache_alloc_node(struct kmem_cache *, gfp_t, int, int *); |
964 | static void *alternate_node_alloc(struct kmem_cache *, gfp_t); | 1080 | static void *alternate_node_alloc(struct kmem_cache *, gfp_t, int *); |
965 | 1081 | ||
966 | static struct array_cache **alloc_alien_cache(int node, int limit, gfp_t gfp) | 1082 | static struct array_cache **alloc_alien_cache(int node, int limit, gfp_t gfp) |
967 | { | 1083 | { |
@@ -1002,7 +1118,8 @@ static void free_alien_cache(struct array_cache **ac_ptr) | |||
1002 | } | 1118 | } |
1003 | 1119 | ||
1004 | static void __drain_alien_cache(struct kmem_cache *cachep, | 1120 | static void __drain_alien_cache(struct kmem_cache *cachep, |
1005 | struct array_cache *ac, int node) | 1121 | struct array_cache *ac, int node, |
1122 | int *this_cpu) | ||
1006 | { | 1123 | { |
1007 | struct kmem_list3 *rl3 = cachep->nodelists[node]; | 1124 | struct kmem_list3 *rl3 = cachep->nodelists[node]; |
1008 | 1125 | ||
@@ -1016,7 +1133,7 @@ static void __drain_alien_cache(struct kmem_cache *cachep, | |||
1016 | if (rl3->shared) | 1133 | if (rl3->shared) |
1017 | transfer_objects(rl3->shared, ac, ac->limit); | 1134 | transfer_objects(rl3->shared, ac, ac->limit); |
1018 | 1135 | ||
1019 | free_block(cachep, ac->entry, ac->avail, node); | 1136 | free_block(cachep, ac->entry, ac->avail, node, this_cpu); |
1020 | ac->avail = 0; | 1137 | ac->avail = 0; |
1021 | spin_unlock(&rl3->list_lock); | 1138 | spin_unlock(&rl3->list_lock); |
1022 | } | 1139 | } |
@@ -1025,38 +1142,42 @@ static void __drain_alien_cache(struct kmem_cache *cachep, | |||
1025 | /* | 1142 | /* |
1026 | * Called from cache_reap() to regularly drain alien caches round robin. | 1143 | * Called from cache_reap() to regularly drain alien caches round robin. |
1027 | */ | 1144 | */ |
1028 | static void reap_alien(struct kmem_cache *cachep, struct kmem_list3 *l3) | 1145 | static int |
1146 | reap_alien(struct kmem_cache *cachep, struct kmem_list3 *l3, int *this_cpu) | ||
1029 | { | 1147 | { |
1030 | int node = __get_cpu_var(reap_node); | 1148 | int node = per_cpu(reap_node, *this_cpu); |
1031 | 1149 | ||
1032 | if (l3->alien) { | 1150 | if (l3->alien) { |
1033 | struct array_cache *ac = l3->alien[node]; | 1151 | struct array_cache *ac = l3->alien[node]; |
1034 | 1152 | ||
1035 | if (ac && ac->avail && spin_trylock_irq(&ac->lock)) { | 1153 | if (ac && ac->avail && spin_trylock_irq(&ac->lock)) { |
1036 | __drain_alien_cache(cachep, ac, node); | 1154 | __drain_alien_cache(cachep, ac, node, this_cpu); |
1037 | spin_unlock_irq(&ac->lock); | 1155 | spin_unlock_irq(&ac->lock); |
1156 | return 1; | ||
1038 | } | 1157 | } |
1039 | } | 1158 | } |
1159 | return 0; | ||
1040 | } | 1160 | } |
1041 | 1161 | ||
1042 | static void drain_alien_cache(struct kmem_cache *cachep, | 1162 | static void drain_alien_cache(struct kmem_cache *cachep, |
1043 | struct array_cache **alien) | 1163 | struct array_cache **alien) |
1044 | { | 1164 | { |
1045 | int i = 0; | 1165 | int i = 0, this_cpu; |
1046 | struct array_cache *ac; | 1166 | struct array_cache *ac; |
1047 | unsigned long flags; | 1167 | unsigned long flags; |
1048 | 1168 | ||
1049 | for_each_online_node(i) { | 1169 | for_each_online_node(i) { |
1050 | ac = alien[i]; | 1170 | ac = alien[i]; |
1051 | if (ac) { | 1171 | if (ac) { |
1052 | spin_lock_irqsave(&ac->lock, flags); | 1172 | slab_spin_lock_irqsave(&ac->lock, flags, this_cpu); |
1053 | __drain_alien_cache(cachep, ac, i); | 1173 | __drain_alien_cache(cachep, ac, i, &this_cpu); |
1054 | spin_unlock_irqrestore(&ac->lock, flags); | 1174 | slab_spin_unlock_irqrestore(&ac->lock, flags, this_cpu); |
1055 | } | 1175 | } |
1056 | } | 1176 | } |
1057 | } | 1177 | } |
1058 | 1178 | ||
1059 | static inline int cache_free_alien(struct kmem_cache *cachep, void *objp) | 1179 | static inline int |
1180 | cache_free_alien(struct kmem_cache *cachep, void *objp, int *this_cpu) | ||
1060 | { | 1181 | { |
1061 | struct slab *slabp = virt_to_slab(objp); | 1182 | struct slab *slabp = virt_to_slab(objp); |
1062 | int nodeid = slabp->nodeid; | 1183 | int nodeid = slabp->nodeid; |
@@ -1064,7 +1185,7 @@ static inline int cache_free_alien(struct kmem_cache *cachep, void *objp) | |||
1064 | struct array_cache *alien = NULL; | 1185 | struct array_cache *alien = NULL; |
1065 | int node; | 1186 | int node; |
1066 | 1187 | ||
1067 | node = numa_node_id(); | 1188 | node = cpu_to_node(*this_cpu); |
1068 | 1189 | ||
1069 | /* | 1190 | /* |
1070 | * Make sure we are not freeing a object from another node to the array | 1191 | * Make sure we are not freeing a object from another node to the array |
@@ -1080,20 +1201,20 @@ static inline int cache_free_alien(struct kmem_cache *cachep, void *objp) | |||
1080 | spin_lock(&alien->lock); | 1201 | spin_lock(&alien->lock); |
1081 | if (unlikely(alien->avail == alien->limit)) { | 1202 | if (unlikely(alien->avail == alien->limit)) { |
1082 | STATS_INC_ACOVERFLOW(cachep); | 1203 | STATS_INC_ACOVERFLOW(cachep); |
1083 | __drain_alien_cache(cachep, alien, nodeid); | 1204 | __drain_alien_cache(cachep, alien, nodeid, this_cpu); |
1084 | } | 1205 | } |
1085 | alien->entry[alien->avail++] = objp; | 1206 | alien->entry[alien->avail++] = objp; |
1086 | spin_unlock(&alien->lock); | 1207 | spin_unlock(&alien->lock); |
1087 | } else { | 1208 | } else { |
1088 | spin_lock(&(cachep->nodelists[nodeid])->list_lock); | 1209 | spin_lock(&(cachep->nodelists[nodeid])->list_lock); |
1089 | free_block(cachep, &objp, 1, nodeid); | 1210 | free_block(cachep, &objp, 1, nodeid, this_cpu); |
1090 | spin_unlock(&(cachep->nodelists[nodeid])->list_lock); | 1211 | spin_unlock(&(cachep->nodelists[nodeid])->list_lock); |
1091 | } | 1212 | } |
1092 | return 1; | 1213 | return 1; |
1093 | } | 1214 | } |
1094 | #endif | 1215 | #endif |
1095 | 1216 | ||
1096 | static void __cpuinit cpuup_canceled(long cpu) | 1217 | static void __cpuinit cpuup_canceled(int cpu) |
1097 | { | 1218 | { |
1098 | struct kmem_cache *cachep; | 1219 | struct kmem_cache *cachep; |
1099 | struct kmem_list3 *l3 = NULL; | 1220 | struct kmem_list3 *l3 = NULL; |
@@ -1104,6 +1225,7 @@ static void __cpuinit cpuup_canceled(long cpu) | |||
1104 | struct array_cache *nc; | 1225 | struct array_cache *nc; |
1105 | struct array_cache *shared; | 1226 | struct array_cache *shared; |
1106 | struct array_cache **alien; | 1227 | struct array_cache **alien; |
1228 | int orig_cpu = cpu; | ||
1107 | 1229 | ||
1108 | /* cpu is dead; no one can alloc from it. */ | 1230 | /* cpu is dead; no one can alloc from it. */ |
1109 | nc = cachep->array[cpu]; | 1231 | nc = cachep->array[cpu]; |
@@ -1118,7 +1240,8 @@ static void __cpuinit cpuup_canceled(long cpu) | |||
1118 | /* Free limit for this kmem_list3 */ | 1240 | /* Free limit for this kmem_list3 */ |
1119 | l3->free_limit -= cachep->batchcount; | 1241 | l3->free_limit -= cachep->batchcount; |
1120 | if (nc) | 1242 | if (nc) |
1121 | free_block(cachep, nc->entry, nc->avail, node); | 1243 | free_block(cachep, nc->entry, nc->avail, node, |
1244 | &cpu); | ||
1122 | 1245 | ||
1123 | if (!cpus_empty(*mask)) { | 1246 | if (!cpus_empty(*mask)) { |
1124 | spin_unlock_irq(&l3->list_lock); | 1247 | spin_unlock_irq(&l3->list_lock); |
@@ -1128,7 +1251,7 @@ static void __cpuinit cpuup_canceled(long cpu) | |||
1128 | shared = l3->shared; | 1251 | shared = l3->shared; |
1129 | if (shared) { | 1252 | if (shared) { |
1130 | free_block(cachep, shared->entry, | 1253 | free_block(cachep, shared->entry, |
1131 | shared->avail, node); | 1254 | shared->avail, node, &cpu); |
1132 | l3->shared = NULL; | 1255 | l3->shared = NULL; |
1133 | } | 1256 | } |
1134 | 1257 | ||
@@ -1144,6 +1267,7 @@ static void __cpuinit cpuup_canceled(long cpu) | |||
1144 | } | 1267 | } |
1145 | free_array_cache: | 1268 | free_array_cache: |
1146 | kfree(nc); | 1269 | kfree(nc); |
1270 | BUG_ON(cpu != orig_cpu); | ||
1147 | } | 1271 | } |
1148 | /* | 1272 | /* |
1149 | * In the previous loop, all the objects were freed to | 1273 | * In the previous loop, all the objects were freed to |
@@ -1158,7 +1282,7 @@ free_array_cache: | |||
1158 | } | 1282 | } |
1159 | } | 1283 | } |
1160 | 1284 | ||
1161 | static int __cpuinit cpuup_prepare(long cpu) | 1285 | static int __cpuinit cpuup_prepare(int cpu) |
1162 | { | 1286 | { |
1163 | struct kmem_cache *cachep; | 1287 | struct kmem_cache *cachep; |
1164 | struct kmem_list3 *l3 = NULL; | 1288 | struct kmem_list3 *l3 = NULL; |
@@ -1266,10 +1390,19 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb, | |||
1266 | long cpu = (long)hcpu; | 1390 | long cpu = (long)hcpu; |
1267 | int err = 0; | 1391 | int err = 0; |
1268 | 1392 | ||
1393 | |||
1269 | switch (action) { | 1394 | switch (action) { |
1270 | case CPU_UP_PREPARE: | 1395 | case CPU_UP_PREPARE: |
1271 | case CPU_UP_PREPARE_FROZEN: | 1396 | case CPU_UP_PREPARE_FROZEN: |
1272 | mutex_lock(&cache_chain_mutex); | 1397 | mutex_lock(&cache_chain_mutex); |
1398 | /* | ||
1399 | * lock/unlock cycle to push any holders away -- no new ones | ||
1400 | * can come in due to the cpu still being offline. | ||
1401 | * | ||
1402 | * XXX -- weird case anyway, can it happen? | ||
1403 | */ | ||
1404 | slab_irq_disable_this_rt(cpu); | ||
1405 | slab_irq_enable_rt(cpu); | ||
1273 | err = cpuup_prepare(cpu); | 1406 | err = cpuup_prepare(cpu); |
1274 | mutex_unlock(&cache_chain_mutex); | 1407 | mutex_unlock(&cache_chain_mutex); |
1275 | break; | 1408 | break; |
@@ -1309,10 +1442,14 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb, | |||
1309 | case CPU_UP_CANCELED: | 1442 | case CPU_UP_CANCELED: |
1310 | case CPU_UP_CANCELED_FROZEN: | 1443 | case CPU_UP_CANCELED_FROZEN: |
1311 | mutex_lock(&cache_chain_mutex); | 1444 | mutex_lock(&cache_chain_mutex); |
1445 | slab_irq_disable_this_rt(cpu); | ||
1312 | cpuup_canceled(cpu); | 1446 | cpuup_canceled(cpu); |
1447 | slab_irq_enable_rt(cpu); | ||
1313 | mutex_unlock(&cache_chain_mutex); | 1448 | mutex_unlock(&cache_chain_mutex); |
1314 | break; | 1449 | break; |
1315 | } | 1450 | } |
1451 | |||
1452 | |||
1316 | return err ? NOTIFY_BAD : NOTIFY_OK; | 1453 | return err ? NOTIFY_BAD : NOTIFY_OK; |
1317 | } | 1454 | } |
1318 | 1455 | ||
@@ -1499,32 +1636,34 @@ void __init kmem_cache_init(void) | |||
1499 | /* 4) Replace the bootstrap head arrays */ | 1636 | /* 4) Replace the bootstrap head arrays */ |
1500 | { | 1637 | { |
1501 | struct array_cache *ptr; | 1638 | struct array_cache *ptr; |
1639 | int cpu = smp_processor_id(); | ||
1502 | 1640 | ||
1503 | ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT); | 1641 | ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT); |
1504 | 1642 | ||
1505 | BUG_ON(cpu_cache_get(&cache_cache) != &initarray_cache.cache); | 1643 | BUG_ON(cpu_cache_get(&cache_cache, cpu) != |
1506 | memcpy(ptr, cpu_cache_get(&cache_cache), | 1644 | &initarray_cache.cache); |
1645 | memcpy(ptr, cpu_cache_get(&cache_cache, cpu), | ||
1507 | sizeof(struct arraycache_init)); | 1646 | sizeof(struct arraycache_init)); |
1508 | /* | 1647 | /* |
1509 | * Do not assume that spinlocks can be initialized via memcpy: | 1648 | * Do not assume that spinlocks can be initialized via memcpy: |
1510 | */ | 1649 | */ |
1511 | spin_lock_init(&ptr->lock); | 1650 | spin_lock_init(&ptr->lock); |
1512 | 1651 | ||
1513 | cache_cache.array[smp_processor_id()] = ptr; | 1652 | cache_cache.array[cpu] = ptr; |
1514 | 1653 | ||
1515 | ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT); | 1654 | ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT); |
1516 | 1655 | ||
1517 | BUG_ON(cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep) | 1656 | BUG_ON(cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep, cpu) |
1518 | != &initarray_generic.cache); | 1657 | != &initarray_generic.cache); |
1519 | memcpy(ptr, cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep), | 1658 | memcpy(ptr, |
1659 | cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep, cpu), | ||
1520 | sizeof(struct arraycache_init)); | 1660 | sizeof(struct arraycache_init)); |
1521 | /* | 1661 | /* |
1522 | * Do not assume that spinlocks can be initialized via memcpy: | 1662 | * Do not assume that spinlocks can be initialized via memcpy: |
1523 | */ | 1663 | */ |
1524 | spin_lock_init(&ptr->lock); | 1664 | spin_lock_init(&ptr->lock); |
1525 | 1665 | ||
1526 | malloc_sizes[INDEX_AC].cs_cachep->array[smp_processor_id()] = | 1666 | malloc_sizes[INDEX_AC].cs_cachep->array[cpu] = ptr; |
1527 | ptr; | ||
1528 | } | 1667 | } |
1529 | /* 5) Replace the bootstrap kmem_list3's */ | 1668 | /* 5) Replace the bootstrap kmem_list3's */ |
1530 | { | 1669 | { |
@@ -1691,7 +1830,7 @@ static void store_stackinfo(struct kmem_cache *cachep, unsigned long *addr, | |||
1691 | 1830 | ||
1692 | *addr++ = 0x12345678; | 1831 | *addr++ = 0x12345678; |
1693 | *addr++ = caller; | 1832 | *addr++ = caller; |
1694 | *addr++ = smp_processor_id(); | 1833 | *addr++ = raw_smp_processor_id(); |
1695 | size -= 3 * sizeof(unsigned long); | 1834 | size -= 3 * sizeof(unsigned long); |
1696 | { | 1835 | { |
1697 | unsigned long *sptr = &caller; | 1836 | unsigned long *sptr = &caller; |
@@ -1881,6 +2020,10 @@ static void slab_destroy_debugcheck(struct kmem_cache *cachep, struct slab *slab | |||
1881 | } | 2020 | } |
1882 | #endif | 2021 | #endif |
1883 | 2022 | ||
2023 | static void | ||
2024 | __cache_free(struct kmem_cache *cachep, void *objp, int *this_cpu); | ||
2025 | |||
2026 | |||
1884 | /** | 2027 | /** |
1885 | * slab_destroy - destroy and release all objects in a slab | 2028 | * slab_destroy - destroy and release all objects in a slab |
1886 | * @cachep: cache pointer being destroyed | 2029 | * @cachep: cache pointer being destroyed |
@@ -1890,7 +2033,8 @@ static void slab_destroy_debugcheck(struct kmem_cache *cachep, struct slab *slab | |||
1890 | * Before calling the slab must have been unlinked from the cache. The | 2033 | * Before calling the slab must have been unlinked from the cache. The |
1891 | * cache-lock is not held/needed. | 2034 | * cache-lock is not held/needed. |
1892 | */ | 2035 | */ |
1893 | static void slab_destroy(struct kmem_cache *cachep, struct slab *slabp) | 2036 | static void |
2037 | slab_destroy(struct kmem_cache *cachep, struct slab *slabp, int *this_cpu) | ||
1894 | { | 2038 | { |
1895 | void *addr = slabp->s_mem - slabp->colouroff; | 2039 | void *addr = slabp->s_mem - slabp->colouroff; |
1896 | 2040 | ||
@@ -1904,8 +2048,12 @@ static void slab_destroy(struct kmem_cache *cachep, struct slab *slabp) | |||
1904 | call_rcu(&slab_rcu->head, kmem_rcu_free); | 2048 | call_rcu(&slab_rcu->head, kmem_rcu_free); |
1905 | } else { | 2049 | } else { |
1906 | kmem_freepages(cachep, addr); | 2050 | kmem_freepages(cachep, addr); |
1907 | if (OFF_SLAB(cachep)) | 2051 | if (OFF_SLAB(cachep)) { |
1908 | kmem_cache_free(cachep->slabp_cache, slabp); | 2052 | if (this_cpu) |
2053 | __cache_free(cachep->slabp_cache, slabp, this_cpu); | ||
2054 | else | ||
2055 | kmem_cache_free(cachep->slabp_cache, slabp); | ||
2056 | } | ||
1909 | } | 2057 | } |
1910 | } | 2058 | } |
1911 | 2059 | ||
@@ -2002,6 +2150,8 @@ static size_t calculate_slab_order(struct kmem_cache *cachep, | |||
2002 | 2150 | ||
2003 | static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp) | 2151 | static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp) |
2004 | { | 2152 | { |
2153 | int this_cpu; | ||
2154 | |||
2005 | if (g_cpucache_up == FULL) | 2155 | if (g_cpucache_up == FULL) |
2006 | return enable_cpucache(cachep, gfp); | 2156 | return enable_cpucache(cachep, gfp); |
2007 | 2157 | ||
@@ -2045,10 +2195,12 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp) | |||
2045 | jiffies + REAPTIMEOUT_LIST3 + | 2195 | jiffies + REAPTIMEOUT_LIST3 + |
2046 | ((unsigned long)cachep) % REAPTIMEOUT_LIST3; | 2196 | ((unsigned long)cachep) % REAPTIMEOUT_LIST3; |
2047 | 2197 | ||
2048 | cpu_cache_get(cachep)->avail = 0; | 2198 | this_cpu = raw_smp_processor_id(); |
2049 | cpu_cache_get(cachep)->limit = BOOT_CPUCACHE_ENTRIES; | 2199 | |
2050 | cpu_cache_get(cachep)->batchcount = 1; | 2200 | cpu_cache_get(cachep, this_cpu)->avail = 0; |
2051 | cpu_cache_get(cachep)->touched = 0; | 2201 | cpu_cache_get(cachep, this_cpu)->limit = BOOT_CPUCACHE_ENTRIES; |
2202 | cpu_cache_get(cachep, this_cpu)->batchcount = 1; | ||
2203 | cpu_cache_get(cachep, this_cpu)->touched = 0; | ||
2052 | cachep->batchcount = 1; | 2204 | cachep->batchcount = 1; |
2053 | cachep->limit = BOOT_CPUCACHE_ENTRIES; | 2205 | cachep->limit = BOOT_CPUCACHE_ENTRIES; |
2054 | return 0; | 2206 | return 0; |
@@ -2358,19 +2510,19 @@ EXPORT_SYMBOL(kmem_cache_create); | |||
2358 | #if DEBUG | 2510 | #if DEBUG |
2359 | static void check_irq_off(void) | 2511 | static void check_irq_off(void) |
2360 | { | 2512 | { |
2513 | /* | ||
2514 | * On PREEMPT_RT we use locks to protect the per-CPU lists, | ||
2515 | * and keep interrupts enabled. | ||
2516 | */ | ||
2517 | #ifndef CONFIG_PREEMPT_RT | ||
2361 | BUG_ON(!irqs_disabled()); | 2518 | BUG_ON(!irqs_disabled()); |
2519 | #endif | ||
2362 | } | 2520 | } |
2363 | 2521 | ||
2364 | static void check_irq_on(void) | 2522 | static void check_irq_on(void) |
2365 | { | 2523 | { |
2524 | #ifndef CONFIG_PREEMPT_RT | ||
2366 | BUG_ON(irqs_disabled()); | 2525 | BUG_ON(irqs_disabled()); |
2367 | } | ||
2368 | |||
2369 | static void check_spinlock_acquired(struct kmem_cache *cachep) | ||
2370 | { | ||
2371 | #ifdef CONFIG_SMP | ||
2372 | check_irq_off(); | ||
2373 | assert_spin_locked(&cachep->nodelists[numa_node_id()]->list_lock); | ||
2374 | #endif | 2526 | #endif |
2375 | } | 2527 | } |
2376 | 2528 | ||
@@ -2385,34 +2537,67 @@ static void check_spinlock_acquired_node(struct kmem_cache *cachep, int node) | |||
2385 | #else | 2537 | #else |
2386 | #define check_irq_off() do { } while(0) | 2538 | #define check_irq_off() do { } while(0) |
2387 | #define check_irq_on() do { } while(0) | 2539 | #define check_irq_on() do { } while(0) |
2388 | #define check_spinlock_acquired(x) do { } while(0) | ||
2389 | #define check_spinlock_acquired_node(x, y) do { } while(0) | 2540 | #define check_spinlock_acquired_node(x, y) do { } while(0) |
2390 | #endif | 2541 | #endif |
2391 | 2542 | ||
2392 | static void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3, | 2543 | static int drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3, |
2393 | struct array_cache *ac, | 2544 | struct array_cache *ac, |
2394 | int force, int node); | 2545 | int force, int node); |
2395 | 2546 | ||
2396 | static void do_drain(void *arg) | 2547 | static void __do_drain(void *arg, int this_cpu) |
2397 | { | 2548 | { |
2398 | struct kmem_cache *cachep = arg; | 2549 | struct kmem_cache *cachep = arg; |
2550 | int node = cpu_to_node(this_cpu); | ||
2399 | struct array_cache *ac; | 2551 | struct array_cache *ac; |
2400 | int node = numa_node_id(); | ||
2401 | 2552 | ||
2402 | check_irq_off(); | 2553 | check_irq_off(); |
2403 | ac = cpu_cache_get(cachep); | 2554 | ac = cpu_cache_get(cachep, this_cpu); |
2404 | spin_lock(&cachep->nodelists[node]->list_lock); | 2555 | spin_lock(&cachep->nodelists[node]->list_lock); |
2405 | free_block(cachep, ac->entry, ac->avail, node); | 2556 | free_block(cachep, ac->entry, ac->avail, node, &this_cpu); |
2406 | spin_unlock(&cachep->nodelists[node]->list_lock); | 2557 | spin_unlock(&cachep->nodelists[node]->list_lock); |
2407 | ac->avail = 0; | 2558 | ac->avail = 0; |
2408 | } | 2559 | } |
2409 | 2560 | ||
2561 | #ifdef CONFIG_PREEMPT_RT | ||
2562 | static void do_drain(void *arg, int this_cpu) | ||
2563 | { | ||
2564 | __do_drain(arg, this_cpu); | ||
2565 | } | ||
2566 | #else | ||
2567 | static void do_drain(void *arg) | ||
2568 | { | ||
2569 | __do_drain(arg, smp_processor_id()); | ||
2570 | } | ||
2571 | #endif | ||
2572 | |||
2573 | #ifdef CONFIG_PREEMPT_RT | ||
2574 | /* | ||
2575 | * execute func() for all CPUs. On PREEMPT_RT we dont actually have | ||
2576 | * to run on the remote CPUs - we only have to take their CPU-locks. | ||
2577 | * (This is a rare operation, so cacheline bouncing is not an issue.) | ||
2578 | */ | ||
2579 | static void | ||
2580 | slab_on_each_cpu(void (*func)(void *arg, int this_cpu), void *arg) | ||
2581 | { | ||
2582 | unsigned int i; | ||
2583 | |||
2584 | check_irq_on(); | ||
2585 | for_each_online_cpu(i) { | ||
2586 | spin_lock(&__get_cpu_lock(slab_irq_locks, i)); | ||
2587 | func(arg, i); | ||
2588 | spin_unlock(&__get_cpu_lock(slab_irq_locks, i)); | ||
2589 | } | ||
2590 | } | ||
2591 | #else | ||
2592 | # define slab_on_each_cpu(func, cachep) on_each_cpu(func, cachep, 1) | ||
2593 | #endif | ||
2594 | |||
2410 | static void drain_cpu_caches(struct kmem_cache *cachep) | 2595 | static void drain_cpu_caches(struct kmem_cache *cachep) |
2411 | { | 2596 | { |
2412 | struct kmem_list3 *l3; | 2597 | struct kmem_list3 *l3; |
2413 | int node; | 2598 | int node; |
2414 | 2599 | ||
2415 | on_each_cpu(do_drain, cachep, 1); | 2600 | slab_on_each_cpu(do_drain, cachep); |
2416 | check_irq_on(); | 2601 | check_irq_on(); |
2417 | for_each_online_node(node) { | 2602 | for_each_online_node(node) { |
2418 | l3 = cachep->nodelists[node]; | 2603 | l3 = cachep->nodelists[node]; |
@@ -2437,16 +2622,16 @@ static int drain_freelist(struct kmem_cache *cache, | |||
2437 | struct kmem_list3 *l3, int tofree) | 2622 | struct kmem_list3 *l3, int tofree) |
2438 | { | 2623 | { |
2439 | struct list_head *p; | 2624 | struct list_head *p; |
2440 | int nr_freed; | 2625 | int nr_freed, this_cpu; |
2441 | struct slab *slabp; | 2626 | struct slab *slabp; |
2442 | 2627 | ||
2443 | nr_freed = 0; | 2628 | nr_freed = 0; |
2444 | while (nr_freed < tofree && !list_empty(&l3->slabs_free)) { | 2629 | while (nr_freed < tofree && !list_empty(&l3->slabs_free)) { |
2445 | 2630 | ||
2446 | spin_lock_irq(&l3->list_lock); | 2631 | slab_spin_lock_irq(&l3->list_lock, this_cpu); |
2447 | p = l3->slabs_free.prev; | 2632 | p = l3->slabs_free.prev; |
2448 | if (p == &l3->slabs_free) { | 2633 | if (p == &l3->slabs_free) { |
2449 | spin_unlock_irq(&l3->list_lock); | 2634 | slab_spin_unlock_irq(&l3->list_lock, this_cpu); |
2450 | goto out; | 2635 | goto out; |
2451 | } | 2636 | } |
2452 | 2637 | ||
@@ -2455,13 +2640,9 @@ static int drain_freelist(struct kmem_cache *cache, | |||
2455 | BUG_ON(slabp->inuse); | 2640 | BUG_ON(slabp->inuse); |
2456 | #endif | 2641 | #endif |
2457 | list_del(&slabp->list); | 2642 | list_del(&slabp->list); |
2458 | /* | ||
2459 | * Safe to drop the lock. The slab is no longer linked | ||
2460 | * to the cache. | ||
2461 | */ | ||
2462 | l3->free_objects -= cache->num; | 2643 | l3->free_objects -= cache->num; |
2463 | spin_unlock_irq(&l3->list_lock); | 2644 | slab_destroy(cache, slabp, &this_cpu); |
2464 | slab_destroy(cache, slabp); | 2645 | slab_spin_unlock_irq(&l3->list_lock, this_cpu); |
2465 | nr_freed++; | 2646 | nr_freed++; |
2466 | } | 2647 | } |
2467 | out: | 2648 | out: |
@@ -2725,8 +2906,8 @@ static void slab_map_pages(struct kmem_cache *cache, struct slab *slab, | |||
2725 | * Grow (by 1) the number of slabs within a cache. This is called by | 2906 | * Grow (by 1) the number of slabs within a cache. This is called by |
2726 | * kmem_cache_alloc() when there are no active objs left in a cache. | 2907 | * kmem_cache_alloc() when there are no active objs left in a cache. |
2727 | */ | 2908 | */ |
2728 | static int cache_grow(struct kmem_cache *cachep, | 2909 | static int cache_grow(struct kmem_cache *cachep, gfp_t flags, int nodeid, |
2729 | gfp_t flags, int nodeid, void *objp) | 2910 | void *objp, int *this_cpu) |
2730 | { | 2911 | { |
2731 | struct slab *slabp; | 2912 | struct slab *slabp; |
2732 | size_t offset; | 2913 | size_t offset; |
@@ -2754,8 +2935,7 @@ static int cache_grow(struct kmem_cache *cachep, | |||
2754 | 2935 | ||
2755 | offset *= cachep->colour_off; | 2936 | offset *= cachep->colour_off; |
2756 | 2937 | ||
2757 | if (local_flags & __GFP_WAIT) | 2938 | slab_irq_enable_GFP_WAIT(local_flags, this_cpu); |
2758 | local_irq_enable(); | ||
2759 | 2939 | ||
2760 | /* | 2940 | /* |
2761 | * The test for missing atomic flag is performed here, rather than | 2941 | * The test for missing atomic flag is performed here, rather than |
@@ -2784,8 +2964,8 @@ static int cache_grow(struct kmem_cache *cachep, | |||
2784 | 2964 | ||
2785 | cache_init_objs(cachep, slabp); | 2965 | cache_init_objs(cachep, slabp); |
2786 | 2966 | ||
2787 | if (local_flags & __GFP_WAIT) | 2967 | slab_irq_disable_GFP_WAIT(local_flags, this_cpu); |
2788 | local_irq_disable(); | 2968 | |
2789 | check_irq_off(); | 2969 | check_irq_off(); |
2790 | spin_lock(&l3->list_lock); | 2970 | spin_lock(&l3->list_lock); |
2791 | 2971 | ||
@@ -2798,8 +2978,7 @@ static int cache_grow(struct kmem_cache *cachep, | |||
2798 | opps1: | 2978 | opps1: |
2799 | kmem_freepages(cachep, objp); | 2979 | kmem_freepages(cachep, objp); |
2800 | failed: | 2980 | failed: |
2801 | if (local_flags & __GFP_WAIT) | 2981 | slab_irq_disable_GFP_WAIT(local_flags, this_cpu); |
2802 | local_irq_disable(); | ||
2803 | return 0; | 2982 | return 0; |
2804 | } | 2983 | } |
2805 | 2984 | ||
@@ -2921,7 +3100,8 @@ bad: | |||
2921 | #define check_slabp(x,y) do { } while(0) | 3100 | #define check_slabp(x,y) do { } while(0) |
2922 | #endif | 3101 | #endif |
2923 | 3102 | ||
2924 | static void *cache_alloc_refill(struct kmem_cache *cachep, gfp_t flags) | 3103 | static void * |
3104 | cache_alloc_refill(struct kmem_cache *cachep, gfp_t flags, int *this_cpu) | ||
2925 | { | 3105 | { |
2926 | int batchcount; | 3106 | int batchcount; |
2927 | struct kmem_list3 *l3; | 3107 | struct kmem_list3 *l3; |
@@ -2931,7 +3111,7 @@ static void *cache_alloc_refill(struct kmem_cache *cachep, gfp_t flags) | |||
2931 | retry: | 3111 | retry: |
2932 | check_irq_off(); | 3112 | check_irq_off(); |
2933 | node = numa_node_id(); | 3113 | node = numa_node_id(); |
2934 | ac = cpu_cache_get(cachep); | 3114 | ac = cpu_cache_get(cachep, *this_cpu); |
2935 | batchcount = ac->batchcount; | 3115 | batchcount = ac->batchcount; |
2936 | if (!ac->touched && batchcount > BATCHREFILL_LIMIT) { | 3116 | if (!ac->touched && batchcount > BATCHREFILL_LIMIT) { |
2937 | /* | 3117 | /* |
@@ -2941,7 +3121,7 @@ retry: | |||
2941 | */ | 3121 | */ |
2942 | batchcount = BATCHREFILL_LIMIT; | 3122 | batchcount = BATCHREFILL_LIMIT; |
2943 | } | 3123 | } |
2944 | l3 = cachep->nodelists[node]; | 3124 | l3 = cachep->nodelists[cpu_to_node(*this_cpu)]; |
2945 | 3125 | ||
2946 | BUG_ON(ac->avail > 0 || !l3); | 3126 | BUG_ON(ac->avail > 0 || !l3); |
2947 | spin_lock(&l3->list_lock); | 3127 | spin_lock(&l3->list_lock); |
@@ -2964,7 +3144,7 @@ retry: | |||
2964 | 3144 | ||
2965 | slabp = list_entry(entry, struct slab, list); | 3145 | slabp = list_entry(entry, struct slab, list); |
2966 | check_slabp(cachep, slabp); | 3146 | check_slabp(cachep, slabp); |
2967 | check_spinlock_acquired(cachep); | 3147 | check_spinlock_acquired_node(cachep, cpu_to_node(*this_cpu)); |
2968 | 3148 | ||
2969 | /* | 3149 | /* |
2970 | * The slab was either on partial or free list so | 3150 | * The slab was either on partial or free list so |
@@ -2978,8 +3158,9 @@ retry: | |||
2978 | STATS_INC_ACTIVE(cachep); | 3158 | STATS_INC_ACTIVE(cachep); |
2979 | STATS_SET_HIGH(cachep); | 3159 | STATS_SET_HIGH(cachep); |
2980 | 3160 | ||
2981 | ac->entry[ac->avail++] = slab_get_obj(cachep, slabp, | 3161 | ac->entry[ac->avail++] = |
2982 | node); | 3162 | slab_get_obj(cachep, slabp, |
3163 | cpu_to_node(*this_cpu)); | ||
2983 | } | 3164 | } |
2984 | check_slabp(cachep, slabp); | 3165 | check_slabp(cachep, slabp); |
2985 | 3166 | ||
@@ -2998,10 +3179,10 @@ alloc_done: | |||
2998 | 3179 | ||
2999 | if (unlikely(!ac->avail)) { | 3180 | if (unlikely(!ac->avail)) { |
3000 | int x; | 3181 | int x; |
3001 | x = cache_grow(cachep, flags | GFP_THISNODE, node, NULL); | 3182 | x = cache_grow(cachep, flags | GFP_THISNODE, cpu_to_node(*this_cpu), NULL, this_cpu); |
3002 | 3183 | ||
3003 | /* cache_grow can reenable interrupts, then ac could change. */ | 3184 | /* cache_grow can reenable interrupts, then ac could change. */ |
3004 | ac = cpu_cache_get(cachep); | 3185 | ac = cpu_cache_get(cachep, *this_cpu); |
3005 | if (!x && ac->avail == 0) /* no objects in sight? abort */ | 3186 | if (!x && ac->avail == 0) /* no objects in sight? abort */ |
3006 | return NULL; | 3187 | return NULL; |
3007 | 3188 | ||
@@ -3088,21 +3269,22 @@ static bool slab_should_failslab(struct kmem_cache *cachep, gfp_t flags) | |||
3088 | return should_failslab(obj_size(cachep), flags); | 3269 | return should_failslab(obj_size(cachep), flags); |
3089 | } | 3270 | } |
3090 | 3271 | ||
3091 | static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags) | 3272 | static inline void * |
3273 | ____cache_alloc(struct kmem_cache *cachep, gfp_t flags, int *this_cpu) | ||
3092 | { | 3274 | { |
3093 | void *objp; | 3275 | void *objp; |
3094 | struct array_cache *ac; | 3276 | struct array_cache *ac; |
3095 | 3277 | ||
3096 | check_irq_off(); | 3278 | check_irq_off(); |
3097 | 3279 | ||
3098 | ac = cpu_cache_get(cachep); | 3280 | ac = cpu_cache_get(cachep, *this_cpu); |
3099 | if (likely(ac->avail)) { | 3281 | if (likely(ac->avail)) { |
3100 | STATS_INC_ALLOCHIT(cachep); | 3282 | STATS_INC_ALLOCHIT(cachep); |
3101 | ac->touched = 1; | 3283 | ac->touched = 1; |
3102 | objp = ac->entry[--ac->avail]; | 3284 | objp = ac->entry[--ac->avail]; |
3103 | } else { | 3285 | } else { |
3104 | STATS_INC_ALLOCMISS(cachep); | 3286 | STATS_INC_ALLOCMISS(cachep); |
3105 | objp = cache_alloc_refill(cachep, flags); | 3287 | objp = cache_alloc_refill(cachep, flags, this_cpu); |
3106 | } | 3288 | } |
3107 | /* | 3289 | /* |
3108 | * To avoid a false negative, if an object that is in one of the | 3290 | * To avoid a false negative, if an object that is in one of the |
@@ -3120,7 +3302,8 @@ static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags) | |||
3120 | * If we are in_interrupt, then process context, including cpusets and | 3302 | * If we are in_interrupt, then process context, including cpusets and |
3121 | * mempolicy, may not apply and should not be used for allocation policy. | 3303 | * mempolicy, may not apply and should not be used for allocation policy. |
3122 | */ | 3304 | */ |
3123 | static void *alternate_node_alloc(struct kmem_cache *cachep, gfp_t flags) | 3305 | static void *alternate_node_alloc(struct kmem_cache *cachep, gfp_t flags, |
3306 | int *this_cpu) | ||
3124 | { | 3307 | { |
3125 | int nid_alloc, nid_here; | 3308 | int nid_alloc, nid_here; |
3126 | 3309 | ||
@@ -3132,7 +3315,7 @@ static void *alternate_node_alloc(struct kmem_cache *cachep, gfp_t flags) | |||
3132 | else if (current->mempolicy) | 3315 | else if (current->mempolicy) |
3133 | nid_alloc = slab_node(current->mempolicy); | 3316 | nid_alloc = slab_node(current->mempolicy); |
3134 | if (nid_alloc != nid_here) | 3317 | if (nid_alloc != nid_here) |
3135 | return ____cache_alloc_node(cachep, flags, nid_alloc); | 3318 | return ____cache_alloc_node(cachep, flags, nid_alloc, this_cpu); |
3136 | return NULL; | 3319 | return NULL; |
3137 | } | 3320 | } |
3138 | 3321 | ||
@@ -3144,7 +3327,7 @@ static void *alternate_node_alloc(struct kmem_cache *cachep, gfp_t flags) | |||
3144 | * allocator to do its reclaim / fallback magic. We then insert the | 3327 | * allocator to do its reclaim / fallback magic. We then insert the |
3145 | * slab into the proper nodelist and then allocate from it. | 3328 | * slab into the proper nodelist and then allocate from it. |
3146 | */ | 3329 | */ |
3147 | static void *fallback_alloc(struct kmem_cache *cache, gfp_t flags) | 3330 | static void *fallback_alloc(struct kmem_cache *cache, gfp_t flags, int *this_cpu) |
3148 | { | 3331 | { |
3149 | struct zonelist *zonelist; | 3332 | struct zonelist *zonelist; |
3150 | gfp_t local_flags; | 3333 | gfp_t local_flags; |
@@ -3172,7 +3355,8 @@ retry: | |||
3172 | cache->nodelists[nid] && | 3355 | cache->nodelists[nid] && |
3173 | cache->nodelists[nid]->free_objects) { | 3356 | cache->nodelists[nid]->free_objects) { |
3174 | obj = ____cache_alloc_node(cache, | 3357 | obj = ____cache_alloc_node(cache, |
3175 | flags | GFP_THISNODE, nid); | 3358 | flags | GFP_THISNODE, nid, |
3359 | this_cpu); | ||
3176 | if (obj) | 3360 | if (obj) |
3177 | break; | 3361 | break; |
3178 | } | 3362 | } |
@@ -3185,20 +3369,21 @@ retry: | |||
3185 | * We may trigger various forms of reclaim on the allowed | 3369 | * We may trigger various forms of reclaim on the allowed |
3186 | * set and go into memory reserves if necessary. | 3370 | * set and go into memory reserves if necessary. |
3187 | */ | 3371 | */ |
3188 | if (local_flags & __GFP_WAIT) | 3372 | slab_irq_enable_GFP_WAIT(local_flags, this_cpu); |
3189 | local_irq_enable(); | 3373 | |
3190 | kmem_flagcheck(cache, flags); | 3374 | kmem_flagcheck(cache, flags); |
3191 | obj = kmem_getpages(cache, local_flags, numa_node_id()); | 3375 | obj = kmem_getpages(cache, local_flags, cpu_to_node(*this_cpu)); |
3192 | if (local_flags & __GFP_WAIT) | 3376 | |
3193 | local_irq_disable(); | 3377 | slab_irq_disable_GFP_WAIT(local_flags, this_cpu); |
3378 | |||
3194 | if (obj) { | 3379 | if (obj) { |
3195 | /* | 3380 | /* |
3196 | * Insert into the appropriate per node queues | 3381 | * Insert into the appropriate per node queues |
3197 | */ | 3382 | */ |
3198 | nid = page_to_nid(virt_to_page(obj)); | 3383 | nid = page_to_nid(virt_to_page(obj)); |
3199 | if (cache_grow(cache, flags, nid, obj)) { | 3384 | if (cache_grow(cache, flags, nid, obj, this_cpu)) { |
3200 | obj = ____cache_alloc_node(cache, | 3385 | obj = ____cache_alloc_node(cache, |
3201 | flags | GFP_THISNODE, nid); | 3386 | flags | GFP_THISNODE, nid, this_cpu); |
3202 | if (!obj) | 3387 | if (!obj) |
3203 | /* | 3388 | /* |
3204 | * Another processor may allocate the | 3389 | * Another processor may allocate the |
@@ -3219,7 +3404,7 @@ retry: | |||
3219 | * A interface to enable slab creation on nodeid | 3404 | * A interface to enable slab creation on nodeid |
3220 | */ | 3405 | */ |
3221 | static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, | 3406 | static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, |
3222 | int nodeid) | 3407 | int nodeid, int *this_cpu) |
3223 | { | 3408 | { |
3224 | struct list_head *entry; | 3409 | struct list_head *entry; |
3225 | struct slab *slabp; | 3410 | struct slab *slabp; |
@@ -3267,11 +3452,11 @@ retry: | |||
3267 | 3452 | ||
3268 | must_grow: | 3453 | must_grow: |
3269 | spin_unlock(&l3->list_lock); | 3454 | spin_unlock(&l3->list_lock); |
3270 | x = cache_grow(cachep, flags | GFP_THISNODE, nodeid, NULL); | 3455 | x = cache_grow(cachep, flags | GFP_THISNODE, nodeid, NULL, this_cpu); |
3271 | if (x) | 3456 | if (x) |
3272 | goto retry; | 3457 | goto retry; |
3273 | 3458 | ||
3274 | return fallback_alloc(cachep, flags); | 3459 | return fallback_alloc(cachep, flags, this_cpu); |
3275 | 3460 | ||
3276 | done: | 3461 | done: |
3277 | return obj; | 3462 | return obj; |
@@ -3294,6 +3479,7 @@ __cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, | |||
3294 | void *caller) | 3479 | void *caller) |
3295 | { | 3480 | { |
3296 | unsigned long save_flags; | 3481 | unsigned long save_flags; |
3482 | int this_cpu, this_node; | ||
3297 | void *ptr; | 3483 | void *ptr; |
3298 | 3484 | ||
3299 | flags &= gfp_allowed_mask; | 3485 | flags &= gfp_allowed_mask; |
@@ -3304,32 +3490,34 @@ __cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, | |||
3304 | return NULL; | 3490 | return NULL; |
3305 | 3491 | ||
3306 | cache_alloc_debugcheck_before(cachep, flags); | 3492 | cache_alloc_debugcheck_before(cachep, flags); |
3307 | local_irq_save(save_flags); | ||
3308 | 3493 | ||
3494 | slab_irq_save(save_flags, this_cpu); | ||
3495 | |||
3496 | this_node = cpu_to_node(this_cpu); | ||
3309 | if (unlikely(nodeid == -1)) | 3497 | if (unlikely(nodeid == -1)) |
3310 | nodeid = numa_node_id(); | 3498 | nodeid = this_node; |
3311 | 3499 | ||
3312 | if (unlikely(!cachep->nodelists[nodeid])) { | 3500 | if (unlikely(!cachep->nodelists[nodeid])) { |
3313 | /* Node not bootstrapped yet */ | 3501 | /* Node not bootstrapped yet */ |
3314 | ptr = fallback_alloc(cachep, flags); | 3502 | ptr = fallback_alloc(cachep, flags, &this_cpu); |
3315 | goto out; | 3503 | goto out; |
3316 | } | 3504 | } |
3317 | 3505 | ||
3318 | if (nodeid == numa_node_id()) { | 3506 | if (nodeid == this_node) { |
3319 | /* | 3507 | /* |
3320 | * Use the locally cached objects if possible. | 3508 | * Use the locally cached objects if possible. |
3321 | * However ____cache_alloc does not allow fallback | 3509 | * However ____cache_alloc does not allow fallback |
3322 | * to other nodes. It may fail while we still have | 3510 | * to other nodes. It may fail while we still have |
3323 | * objects on other nodes available. | 3511 | * objects on other nodes available. |
3324 | */ | 3512 | */ |
3325 | ptr = ____cache_alloc(cachep, flags); | 3513 | ptr = ____cache_alloc(cachep, flags, &this_cpu); |
3326 | if (ptr) | 3514 | if (ptr) |
3327 | goto out; | 3515 | goto out; |
3328 | } | 3516 | } |
3329 | /* ___cache_alloc_node can fall back to other nodes */ | 3517 | /* ___cache_alloc_node can fall back to other nodes */ |
3330 | ptr = ____cache_alloc_node(cachep, flags, nodeid); | 3518 | ptr = ____cache_alloc_node(cachep, flags, nodeid, &this_cpu); |
3331 | out: | 3519 | out: |
3332 | local_irq_restore(save_flags); | 3520 | slab_irq_restore(save_flags, this_cpu); |
3333 | ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); | 3521 | ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); |
3334 | kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags, | 3522 | kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags, |
3335 | flags); | 3523 | flags); |
@@ -3344,33 +3532,33 @@ __cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, | |||
3344 | } | 3532 | } |
3345 | 3533 | ||
3346 | static __always_inline void * | 3534 | static __always_inline void * |
3347 | __do_cache_alloc(struct kmem_cache *cache, gfp_t flags) | 3535 | __do_cache_alloc(struct kmem_cache *cache, gfp_t flags, int *this_cpu) |
3348 | { | 3536 | { |
3349 | void *objp; | 3537 | void *objp; |
3350 | 3538 | ||
3351 | if (unlikely(current->flags & (PF_SPREAD_SLAB | PF_MEMPOLICY))) { | 3539 | if (unlikely(current->flags & (PF_SPREAD_SLAB | PF_MEMPOLICY))) { |
3352 | objp = alternate_node_alloc(cache, flags); | 3540 | objp = alternate_node_alloc(cache, flags, this_cpu); |
3353 | if (objp) | 3541 | if (objp) |
3354 | goto out; | 3542 | goto out; |
3355 | } | 3543 | } |
3356 | objp = ____cache_alloc(cache, flags); | ||
3357 | 3544 | ||
3545 | objp = ____cache_alloc(cache, flags, this_cpu); | ||
3358 | /* | 3546 | /* |
3359 | * We may just have run out of memory on the local node. | 3547 | * We may just have run out of memory on the local node. |
3360 | * ____cache_alloc_node() knows how to locate memory on other nodes | 3548 | * ____cache_alloc_node() knows how to locate memory on other nodes |
3361 | */ | 3549 | */ |
3362 | if (!objp) | 3550 | if (!objp) |
3363 | objp = ____cache_alloc_node(cache, flags, numa_node_id()); | 3551 | objp = ____cache_alloc_node(cache, flags, |
3364 | 3552 | cpu_to_node(*this_cpu), this_cpu); | |
3365 | out: | 3553 | out: |
3366 | return objp; | 3554 | return objp; |
3367 | } | 3555 | } |
3368 | #else | 3556 | #else |
3369 | 3557 | ||
3370 | static __always_inline void * | 3558 | static __always_inline void * |
3371 | __do_cache_alloc(struct kmem_cache *cachep, gfp_t flags) | 3559 | __do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int *this_cpu) |
3372 | { | 3560 | { |
3373 | return ____cache_alloc(cachep, flags); | 3561 | return ____cache_alloc(cachep, flags, this_cpu); |
3374 | } | 3562 | } |
3375 | 3563 | ||
3376 | #endif /* CONFIG_NUMA */ | 3564 | #endif /* CONFIG_NUMA */ |
@@ -3379,6 +3567,7 @@ static __always_inline void * | |||
3379 | __cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller) | 3567 | __cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller) |
3380 | { | 3568 | { |
3381 | unsigned long save_flags; | 3569 | unsigned long save_flags; |
3570 | int this_cpu; | ||
3382 | void *objp; | 3571 | void *objp; |
3383 | 3572 | ||
3384 | flags &= gfp_allowed_mask; | 3573 | flags &= gfp_allowed_mask; |
@@ -3389,9 +3578,9 @@ __cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller) | |||
3389 | return NULL; | 3578 | return NULL; |
3390 | 3579 | ||
3391 | cache_alloc_debugcheck_before(cachep, flags); | 3580 | cache_alloc_debugcheck_before(cachep, flags); |
3392 | local_irq_save(save_flags); | 3581 | slab_irq_save(save_flags, this_cpu); |
3393 | objp = __do_cache_alloc(cachep, flags); | 3582 | objp = __do_cache_alloc(cachep, flags, &this_cpu); |
3394 | local_irq_restore(save_flags); | 3583 | slab_irq_restore(save_flags, this_cpu); |
3395 | objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller); | 3584 | objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller); |
3396 | kmemleak_alloc_recursive(objp, obj_size(cachep), 1, cachep->flags, | 3585 | kmemleak_alloc_recursive(objp, obj_size(cachep), 1, cachep->flags, |
3397 | flags); | 3586 | flags); |
@@ -3410,7 +3599,7 @@ __cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller) | |||
3410 | * Caller needs to acquire correct kmem_list's list_lock | 3599 | * Caller needs to acquire correct kmem_list's list_lock |
3411 | */ | 3600 | */ |
3412 | static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects, | 3601 | static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects, |
3413 | int node) | 3602 | int node, int *this_cpu) |
3414 | { | 3603 | { |
3415 | int i; | 3604 | int i; |
3416 | struct kmem_list3 *l3; | 3605 | struct kmem_list3 *l3; |
@@ -3439,7 +3628,7 @@ static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects, | |||
3439 | * a different cache, refer to comments before | 3628 | * a different cache, refer to comments before |
3440 | * alloc_slabmgmt. | 3629 | * alloc_slabmgmt. |
3441 | */ | 3630 | */ |
3442 | slab_destroy(cachep, slabp); | 3631 | slab_destroy(cachep, slabp, this_cpu); |
3443 | } else { | 3632 | } else { |
3444 | list_add(&slabp->list, &l3->slabs_free); | 3633 | list_add(&slabp->list, &l3->slabs_free); |
3445 | } | 3634 | } |
@@ -3453,11 +3642,12 @@ static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects, | |||
3453 | } | 3642 | } |
3454 | } | 3643 | } |
3455 | 3644 | ||
3456 | static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac) | 3645 | static void |
3646 | cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac, int *this_cpu) | ||
3457 | { | 3647 | { |
3458 | int batchcount; | 3648 | int batchcount; |
3459 | struct kmem_list3 *l3; | 3649 | struct kmem_list3 *l3; |
3460 | int node = numa_node_id(); | 3650 | int node = cpu_to_node(*this_cpu); |
3461 | 3651 | ||
3462 | batchcount = ac->batchcount; | 3652 | batchcount = ac->batchcount; |
3463 | #if DEBUG | 3653 | #if DEBUG |
@@ -3479,7 +3669,7 @@ static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac) | |||
3479 | } | 3669 | } |
3480 | } | 3670 | } |
3481 | 3671 | ||
3482 | free_block(cachep, ac->entry, batchcount, node); | 3672 | free_block(cachep, ac->entry, batchcount, node, this_cpu); |
3483 | free_done: | 3673 | free_done: |
3484 | #if STATS | 3674 | #if STATS |
3485 | { | 3675 | { |
@@ -3508,9 +3698,10 @@ free_done: | |||
3508 | * Release an obj back to its cache. If the obj has a constructed state, it must | 3698 | * Release an obj back to its cache. If the obj has a constructed state, it must |
3509 | * be in this state _before_ it is released. Called with disabled ints. | 3699 | * be in this state _before_ it is released. Called with disabled ints. |
3510 | */ | 3700 | */ |
3511 | static inline void __cache_free(struct kmem_cache *cachep, void *objp) | 3701 | static inline void |
3702 | __cache_free(struct kmem_cache *cachep, void *objp, int *this_cpu) | ||
3512 | { | 3703 | { |
3513 | struct array_cache *ac = cpu_cache_get(cachep); | 3704 | struct array_cache *ac = cpu_cache_get(cachep, *this_cpu); |
3514 | 3705 | ||
3515 | check_irq_off(); | 3706 | check_irq_off(); |
3516 | kmemleak_free_recursive(objp, cachep->flags); | 3707 | kmemleak_free_recursive(objp, cachep->flags); |
@@ -3525,7 +3716,7 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) | |||
3525 | * variable to skip the call, which is mostly likely to be present in | 3716 | * variable to skip the call, which is mostly likely to be present in |
3526 | * the cache. | 3717 | * the cache. |
3527 | */ | 3718 | */ |
3528 | if (nr_online_nodes > 1 && cache_free_alien(cachep, objp)) | 3719 | if (nr_online_nodes > 1 && cache_free_alien(cachep, objp, this_cpu)) |
3529 | return; | 3720 | return; |
3530 | 3721 | ||
3531 | if (likely(ac->avail < ac->limit)) { | 3722 | if (likely(ac->avail < ac->limit)) { |
@@ -3534,7 +3725,7 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp) | |||
3534 | return; | 3725 | return; |
3535 | } else { | 3726 | } else { |
3536 | STATS_INC_FREEMISS(cachep); | 3727 | STATS_INC_FREEMISS(cachep); |
3537 | cache_flusharray(cachep, ac); | 3728 | cache_flusharray(cachep, ac, this_cpu); |
3538 | ac->entry[ac->avail++] = objp; | 3729 | ac->entry[ac->avail++] = objp; |
3539 | } | 3730 | } |
3540 | } | 3731 | } |
@@ -3733,13 +3924,14 @@ EXPORT_SYMBOL(__kmalloc); | |||
3733 | void kmem_cache_free(struct kmem_cache *cachep, void *objp) | 3924 | void kmem_cache_free(struct kmem_cache *cachep, void *objp) |
3734 | { | 3925 | { |
3735 | unsigned long flags; | 3926 | unsigned long flags; |
3927 | int this_cpu; | ||
3736 | 3928 | ||
3737 | local_irq_save(flags); | 3929 | slab_irq_save(flags, this_cpu); |
3738 | debug_check_no_locks_freed(objp, obj_size(cachep)); | 3930 | debug_check_no_locks_freed(objp, obj_size(cachep)); |
3739 | if (!(cachep->flags & SLAB_DEBUG_OBJECTS)) | 3931 | if (!(cachep->flags & SLAB_DEBUG_OBJECTS)) |
3740 | debug_check_no_obj_freed(objp, obj_size(cachep)); | 3932 | debug_check_no_obj_freed(objp, obj_size(cachep)); |
3741 | __cache_free(cachep, objp); | 3933 | __cache_free(cachep, objp, &this_cpu); |
3742 | local_irq_restore(flags); | 3934 | slab_irq_restore(flags, this_cpu); |
3743 | 3935 | ||
3744 | trace_kmem_cache_free(_RET_IP_, objp); | 3936 | trace_kmem_cache_free(_RET_IP_, objp); |
3745 | } | 3937 | } |
@@ -3758,18 +3950,19 @@ void kfree(const void *objp) | |||
3758 | { | 3950 | { |
3759 | struct kmem_cache *c; | 3951 | struct kmem_cache *c; |
3760 | unsigned long flags; | 3952 | unsigned long flags; |
3953 | int this_cpu; | ||
3761 | 3954 | ||
3762 | trace_kfree(_RET_IP_, objp); | 3955 | trace_kfree(_RET_IP_, objp); |
3763 | 3956 | ||
3764 | if (unlikely(ZERO_OR_NULL_PTR(objp))) | 3957 | if (unlikely(ZERO_OR_NULL_PTR(objp))) |
3765 | return; | 3958 | return; |
3766 | local_irq_save(flags); | 3959 | slab_irq_save(flags, this_cpu); |
3767 | kfree_debugcheck(objp); | 3960 | kfree_debugcheck(objp); |
3768 | c = virt_to_cache(objp); | 3961 | c = virt_to_cache(objp); |
3769 | debug_check_no_locks_freed(objp, obj_size(c)); | 3962 | debug_check_no_locks_freed(objp, obj_size(c)); |
3770 | debug_check_no_obj_freed(objp, obj_size(c)); | 3963 | debug_check_no_obj_freed(objp, obj_size(c)); |
3771 | __cache_free(c, (void *)objp); | 3964 | __cache_free(c, (void *)objp, &this_cpu); |
3772 | local_irq_restore(flags); | 3965 | slab_irq_restore(flags, this_cpu); |
3773 | } | 3966 | } |
3774 | EXPORT_SYMBOL(kfree); | 3967 | EXPORT_SYMBOL(kfree); |
3775 | 3968 | ||
@@ -3790,7 +3983,7 @@ EXPORT_SYMBOL_GPL(kmem_cache_name); | |||
3790 | */ | 3983 | */ |
3791 | static int alloc_kmemlist(struct kmem_cache *cachep, gfp_t gfp) | 3984 | static int alloc_kmemlist(struct kmem_cache *cachep, gfp_t gfp) |
3792 | { | 3985 | { |
3793 | int node; | 3986 | int node, this_cpu; |
3794 | struct kmem_list3 *l3; | 3987 | struct kmem_list3 *l3; |
3795 | struct array_cache *new_shared; | 3988 | struct array_cache *new_shared; |
3796 | struct array_cache **new_alien = NULL; | 3989 | struct array_cache **new_alien = NULL; |
@@ -3818,11 +4011,11 @@ static int alloc_kmemlist(struct kmem_cache *cachep, gfp_t gfp) | |||
3818 | if (l3) { | 4011 | if (l3) { |
3819 | struct array_cache *shared = l3->shared; | 4012 | struct array_cache *shared = l3->shared; |
3820 | 4013 | ||
3821 | spin_lock_irq(&l3->list_lock); | 4014 | slab_spin_lock_irq(&l3->list_lock, this_cpu); |
3822 | 4015 | ||
3823 | if (shared) | 4016 | if (shared) |
3824 | free_block(cachep, shared->entry, | 4017 | free_block(cachep, shared->entry, |
3825 | shared->avail, node); | 4018 | shared->avail, node, &this_cpu); |
3826 | 4019 | ||
3827 | l3->shared = new_shared; | 4020 | l3->shared = new_shared; |
3828 | if (!l3->alien) { | 4021 | if (!l3->alien) { |
@@ -3831,7 +4024,7 @@ static int alloc_kmemlist(struct kmem_cache *cachep, gfp_t gfp) | |||
3831 | } | 4024 | } |
3832 | l3->free_limit = (1 + nr_cpus_node(node)) * | 4025 | l3->free_limit = (1 + nr_cpus_node(node)) * |
3833 | cachep->batchcount + cachep->num; | 4026 | cachep->batchcount + cachep->num; |
3834 | spin_unlock_irq(&l3->list_lock); | 4027 | slab_spin_unlock_irq(&l3->list_lock, this_cpu); |
3835 | kfree(shared); | 4028 | kfree(shared); |
3836 | free_alien_cache(new_alien); | 4029 | free_alien_cache(new_alien); |
3837 | continue; | 4030 | continue; |
@@ -3878,24 +4071,36 @@ struct ccupdate_struct { | |||
3878 | struct array_cache *new[NR_CPUS]; | 4071 | struct array_cache *new[NR_CPUS]; |
3879 | }; | 4072 | }; |
3880 | 4073 | ||
3881 | static void do_ccupdate_local(void *info) | 4074 | static void __do_ccupdate_local(void *info, int this_cpu) |
3882 | { | 4075 | { |
3883 | struct ccupdate_struct *new = info; | 4076 | struct ccupdate_struct *new = info; |
3884 | struct array_cache *old; | 4077 | struct array_cache *old; |
3885 | 4078 | ||
3886 | check_irq_off(); | 4079 | check_irq_off(); |
3887 | old = cpu_cache_get(new->cachep); | 4080 | old = cpu_cache_get(new->cachep, this_cpu); |
3888 | 4081 | ||
3889 | new->cachep->array[smp_processor_id()] = new->new[smp_processor_id()]; | 4082 | new->cachep->array[this_cpu] = new->new[this_cpu]; |
3890 | new->new[smp_processor_id()] = old; | 4083 | new->new[this_cpu] = old; |
3891 | } | 4084 | } |
3892 | 4085 | ||
4086 | #ifdef CONFIG_PREEMPT_RT | ||
4087 | static void do_ccupdate_local(void *arg, int this_cpu) | ||
4088 | { | ||
4089 | __do_ccupdate_local(arg, this_cpu); | ||
4090 | } | ||
4091 | #else | ||
4092 | static void do_ccupdate_local(void *arg) | ||
4093 | { | ||
4094 | __do_ccupdate_local(arg, smp_processor_id()); | ||
4095 | } | ||
4096 | #endif | ||
4097 | |||
3893 | /* Always called with the cache_chain_mutex held */ | 4098 | /* Always called with the cache_chain_mutex held */ |
3894 | static int do_tune_cpucache(struct kmem_cache *cachep, int limit, | 4099 | static int do_tune_cpucache(struct kmem_cache *cachep, int limit, |
3895 | int batchcount, int shared, gfp_t gfp) | 4100 | int batchcount, int shared, gfp_t gfp) |
3896 | { | 4101 | { |
3897 | struct ccupdate_struct *new; | 4102 | struct ccupdate_struct *new; |
3898 | int i; | 4103 | int i, this_cpu; |
3899 | 4104 | ||
3900 | new = kzalloc(sizeof(*new), gfp); | 4105 | new = kzalloc(sizeof(*new), gfp); |
3901 | if (!new) | 4106 | if (!new) |
@@ -3913,7 +4118,7 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit, | |||
3913 | } | 4118 | } |
3914 | new->cachep = cachep; | 4119 | new->cachep = cachep; |
3915 | 4120 | ||
3916 | on_each_cpu(do_ccupdate_local, (void *)new, 1); | 4121 | slab_on_each_cpu(do_ccupdate_local, (void *)new); |
3917 | 4122 | ||
3918 | check_irq_on(); | 4123 | check_irq_on(); |
3919 | cachep->batchcount = batchcount; | 4124 | cachep->batchcount = batchcount; |
@@ -3924,9 +4129,12 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit, | |||
3924 | struct array_cache *ccold = new->new[i]; | 4129 | struct array_cache *ccold = new->new[i]; |
3925 | if (!ccold) | 4130 | if (!ccold) |
3926 | continue; | 4131 | continue; |
3927 | spin_lock_irq(&cachep->nodelists[cpu_to_node(i)]->list_lock); | 4132 | slab_spin_lock_irq(&cachep->nodelists[cpu_to_node(i)]->list_lock, |
3928 | free_block(cachep, ccold->entry, ccold->avail, cpu_to_node(i)); | 4133 | this_cpu); |
3929 | spin_unlock_irq(&cachep->nodelists[cpu_to_node(i)]->list_lock); | 4134 | free_block(cachep, ccold->entry, ccold->avail, cpu_to_node(i), |
4135 | &this_cpu); | ||
4136 | slab_spin_unlock_irq(&cachep->nodelists[cpu_to_node(i)]->list_lock, | ||
4137 | this_cpu); | ||
3930 | kfree(ccold); | 4138 | kfree(ccold); |
3931 | } | 4139 | } |
3932 | kfree(new); | 4140 | kfree(new); |
@@ -3991,29 +4199,31 @@ static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp) | |||
3991 | * Drain an array if it contains any elements taking the l3 lock only if | 4199 | * Drain an array if it contains any elements taking the l3 lock only if |
3992 | * necessary. Note that the l3 listlock also protects the array_cache | 4200 | * necessary. Note that the l3 listlock also protects the array_cache |
3993 | * if drain_array() is used on the shared array. | 4201 | * if drain_array() is used on the shared array. |
4202 | * returns non-zero if some work is done | ||
3994 | */ | 4203 | */ |
3995 | void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3, | 4204 | int drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3, |
3996 | struct array_cache *ac, int force, int node) | 4205 | struct array_cache *ac, int force, int node) |
3997 | { | 4206 | { |
3998 | int tofree; | 4207 | int tofree, this_cpu; |
3999 | 4208 | ||
4000 | if (!ac || !ac->avail) | 4209 | if (!ac || !ac->avail) |
4001 | return; | 4210 | return 0; |
4002 | if (ac->touched && !force) { | 4211 | if (ac->touched && !force) { |
4003 | ac->touched = 0; | 4212 | ac->touched = 0; |
4004 | } else { | 4213 | } else { |
4005 | spin_lock_irq(&l3->list_lock); | 4214 | slab_spin_lock_irq(&l3->list_lock, this_cpu); |
4006 | if (ac->avail) { | 4215 | if (ac->avail) { |
4007 | tofree = force ? ac->avail : (ac->limit + 4) / 5; | 4216 | tofree = force ? ac->avail : (ac->limit + 4) / 5; |
4008 | if (tofree > ac->avail) | 4217 | if (tofree > ac->avail) |
4009 | tofree = (ac->avail + 1) / 2; | 4218 | tofree = (ac->avail + 1) / 2; |
4010 | free_block(cachep, ac->entry, tofree, node); | 4219 | free_block(cachep, ac->entry, tofree, node, &this_cpu); |
4011 | ac->avail -= tofree; | 4220 | ac->avail -= tofree; |
4012 | memmove(ac->entry, &(ac->entry[tofree]), | 4221 | memmove(ac->entry, &(ac->entry[tofree]), |
4013 | sizeof(void *) * ac->avail); | 4222 | sizeof(void *) * ac->avail); |
4014 | } | 4223 | } |
4015 | spin_unlock_irq(&l3->list_lock); | 4224 | slab_spin_unlock_irq(&l3->list_lock, this_cpu); |
4016 | } | 4225 | } |
4226 | return 1; | ||
4017 | } | 4227 | } |
4018 | 4228 | ||
4019 | /** | 4229 | /** |
@@ -4030,10 +4240,11 @@ void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3, | |||
4030 | */ | 4240 | */ |
4031 | static void cache_reap(struct work_struct *w) | 4241 | static void cache_reap(struct work_struct *w) |
4032 | { | 4242 | { |
4243 | int this_cpu = raw_smp_processor_id(), node = cpu_to_node(this_cpu); | ||
4033 | struct kmem_cache *searchp; | 4244 | struct kmem_cache *searchp; |
4034 | struct kmem_list3 *l3; | 4245 | struct kmem_list3 *l3; |
4035 | int node = numa_node_id(); | ||
4036 | struct delayed_work *work = to_delayed_work(w); | 4246 | struct delayed_work *work = to_delayed_work(w); |
4247 | int work_done = 0; | ||
4037 | 4248 | ||
4038 | if (!mutex_trylock(&cache_chain_mutex)) | 4249 | if (!mutex_trylock(&cache_chain_mutex)) |
4039 | /* Give up. Setup the next iteration. */ | 4250 | /* Give up. Setup the next iteration. */ |
@@ -4049,9 +4260,12 @@ static void cache_reap(struct work_struct *w) | |||
4049 | */ | 4260 | */ |
4050 | l3 = searchp->nodelists[node]; | 4261 | l3 = searchp->nodelists[node]; |
4051 | 4262 | ||
4052 | reap_alien(searchp, l3); | 4263 | work_done += reap_alien(searchp, l3, &this_cpu); |
4264 | |||
4265 | node = cpu_to_node(this_cpu); | ||
4053 | 4266 | ||
4054 | drain_array(searchp, l3, cpu_cache_get(searchp), 0, node); | 4267 | work_done += drain_array(searchp, l3, |
4268 | cpu_cache_get(searchp, this_cpu), 0, node); | ||
4055 | 4269 | ||
4056 | /* | 4270 | /* |
4057 | * These are racy checks but it does not matter | 4271 | * These are racy checks but it does not matter |
@@ -4062,7 +4276,7 @@ static void cache_reap(struct work_struct *w) | |||
4062 | 4276 | ||
4063 | l3->next_reap = jiffies + REAPTIMEOUT_LIST3; | 4277 | l3->next_reap = jiffies + REAPTIMEOUT_LIST3; |
4064 | 4278 | ||
4065 | drain_array(searchp, l3, l3->shared, 0, node); | 4279 | work_done += drain_array(searchp, l3, l3->shared, 0, node); |
4066 | 4280 | ||
4067 | if (l3->free_touched) | 4281 | if (l3->free_touched) |
4068 | l3->free_touched = 0; | 4282 | l3->free_touched = 0; |
@@ -4081,7 +4295,8 @@ next: | |||
4081 | next_reap_node(); | 4295 | next_reap_node(); |
4082 | out: | 4296 | out: |
4083 | /* Set up the next iteration */ | 4297 | /* Set up the next iteration */ |
4084 | schedule_delayed_work(work, round_jiffies_relative(REAPTIMEOUT_CPUC)); | 4298 | schedule_delayed_work(work, |
4299 | round_jiffies_relative((1+!work_done) * REAPTIMEOUT_CPUC)); | ||
4085 | } | 4300 | } |
4086 | 4301 | ||
4087 | #ifdef CONFIG_SLABINFO | 4302 | #ifdef CONFIG_SLABINFO |
@@ -4140,7 +4355,7 @@ static int s_show(struct seq_file *m, void *p) | |||
4140 | unsigned long num_slabs, free_objects = 0, shared_avail = 0; | 4355 | unsigned long num_slabs, free_objects = 0, shared_avail = 0; |
4141 | const char *name; | 4356 | const char *name; |
4142 | char *error = NULL; | 4357 | char *error = NULL; |
4143 | int node; | 4358 | int this_cpu, node; |
4144 | struct kmem_list3 *l3; | 4359 | struct kmem_list3 *l3; |
4145 | 4360 | ||
4146 | active_objs = 0; | 4361 | active_objs = 0; |
@@ -4151,7 +4366,7 @@ static int s_show(struct seq_file *m, void *p) | |||
4151 | continue; | 4366 | continue; |
4152 | 4367 | ||
4153 | check_irq_on(); | 4368 | check_irq_on(); |
4154 | spin_lock_irq(&l3->list_lock); | 4369 | slab_spin_lock_irq(&l3->list_lock, this_cpu); |
4155 | 4370 | ||
4156 | list_for_each_entry(slabp, &l3->slabs_full, list) { | 4371 | list_for_each_entry(slabp, &l3->slabs_full, list) { |
4157 | if (slabp->inuse != cachep->num && !error) | 4372 | if (slabp->inuse != cachep->num && !error) |
@@ -4176,7 +4391,7 @@ static int s_show(struct seq_file *m, void *p) | |||
4176 | if (l3->shared) | 4391 | if (l3->shared) |
4177 | shared_avail += l3->shared->avail; | 4392 | shared_avail += l3->shared->avail; |
4178 | 4393 | ||
4179 | spin_unlock_irq(&l3->list_lock); | 4394 | slab_spin_unlock_irq(&l3->list_lock, this_cpu); |
4180 | } | 4395 | } |
4181 | num_slabs += active_slabs; | 4396 | num_slabs += active_slabs; |
4182 | num_objs = num_slabs * cachep->num; | 4397 | num_objs = num_slabs * cachep->num; |
@@ -4386,7 +4601,7 @@ static int leaks_show(struct seq_file *m, void *p) | |||
4386 | struct kmem_list3 *l3; | 4601 | struct kmem_list3 *l3; |
4387 | const char *name; | 4602 | const char *name; |
4388 | unsigned long *n = m->private; | 4603 | unsigned long *n = m->private; |
4389 | int node; | 4604 | int node, this_cpu; |
4390 | int i; | 4605 | int i; |
4391 | 4606 | ||
4392 | if (!(cachep->flags & SLAB_STORE_USER)) | 4607 | if (!(cachep->flags & SLAB_STORE_USER)) |
@@ -4404,13 +4619,13 @@ static int leaks_show(struct seq_file *m, void *p) | |||
4404 | continue; | 4619 | continue; |
4405 | 4620 | ||
4406 | check_irq_on(); | 4621 | check_irq_on(); |
4407 | spin_lock_irq(&l3->list_lock); | 4622 | slab_spin_lock_irq(&l3->list_lock, this_cpu); |
4408 | 4623 | ||
4409 | list_for_each_entry(slabp, &l3->slabs_full, list) | 4624 | list_for_each_entry(slabp, &l3->slabs_full, list) |
4410 | handle_slab(n, cachep, slabp); | 4625 | handle_slab(n, cachep, slabp); |
4411 | list_for_each_entry(slabp, &l3->slabs_partial, list) | 4626 | list_for_each_entry(slabp, &l3->slabs_partial, list) |
4412 | handle_slab(n, cachep, slabp); | 4627 | handle_slab(n, cachep, slabp); |
4413 | spin_unlock_irq(&l3->list_lock); | 4628 | slab_spin_unlock_irq(&l3->list_lock, this_cpu); |
4414 | } | 4629 | } |
4415 | name = cachep->name; | 4630 | name = cachep->name; |
4416 | if (n[0] == n[1]) { | 4631 | if (n[0] == n[1]) { |