Blame view
mm/slab.c
111 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/* * linux/mm/slab.c * Written by Mark Hemment, 1996/97. * (markhe@nextd.demon.co.uk) * * kmem_cache_destroy() + some cleanup - 1999 Andrea Arcangeli * * Major cleanup, different bufctl logic, per-cpu arrays * (c) 2000 Manfred Spraul * * Cleanup, make the head arrays unconditional, preparation for NUMA * (c) 2002 Manfred Spraul * * An implementation of the Slab Allocator as described in outline in; * UNIX Internals: The New Frontiers by Uresh Vahalia * Pub: Prentice Hall ISBN 0-13-101908-2 * or with a little more detail in; * The Slab Allocator: An Object-Caching Kernel Memory Allocator * Jeff Bonwick (Sun Microsystems). * Presented at: USENIX Summer 1994 Technical Conference * * The memory is organized in caches, one cache for each object type. * (e.g. inode_cache, dentry_cache, buffer_head, vm_area_struct) * Each cache consists out of many slabs (they are small (usually one * page long) and always contiguous), and each slab contains multiple * initialized objects. * * This means, that your constructor is used only for newly allocated |
183ff22bb spelling fixes: mm/ |
29 |
* slabs and you must pass objects with the same initializations to |
1da177e4c Linux-2.6.12-rc2 |
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
* kmem_cache_free. * * Each cache can only support one memory type (GFP_DMA, GFP_HIGHMEM, * normal). If you need a special memory type, then must create a new * cache for that memory type. * * In order to reduce fragmentation, the slabs are sorted in 3 groups: * full slabs with 0 free objects * partial slabs * empty slabs with no allocated objects * * If partial slabs exist, then new allocations come from these slabs, * otherwise from empty slabs or new slabs are allocated. * * kmem_cache_destroy() CAN CRASH if you try to allocate from the cache * during kmem_cache_destroy(). The caller must prevent concurrent allocs. * * Each cache has a short per-cpu head array, most allocs * and frees go into that array, and if that array overflows, then 1/2 * of the entries in the array are given back into the global cache. * The head array is strictly LIFO and should improve the cache hit rates. * On SMP, it additionally reduces the spinlock operations. * |
a737b3e2f [PATCH] slab cleanup |
53 |
* The c_cpuarray may not be read with enabled local interrupts - |
1da177e4c Linux-2.6.12-rc2 |
54 55 56 57 |
* it's changed with a smp_call_function(). * * SMP synchronization: * constructors and destructors are called without any locking. |
343e0d7a9 [PATCH] slab: rep... |
58 |
* Several members in struct kmem_cache and struct slab never change, they |
1da177e4c Linux-2.6.12-rc2 |
59 60 61 62 63 64 65 66 67 68 69 70 |
* are accessed without any locking. * The per-cpu arrays are never accessed from the wrong cpu, no locking, * and local interrupts are disabled so slab code is preempt-safe. * The non-constant members are protected with a per-cache irq spinlock. * * Many thanks to Mark Hemment, who wrote another per-cpu slab patch * in 2000 - many ideas in the current implementation are derived from * his patch. * * Further notes from the original documentation: * * 11 April '97. Started multi-threading - markhe |
18004c5d4 mm, sl[aou]b: Use... |
71 |
* The global cache-chain is protected by the mutex 'slab_mutex'. |
1da177e4c Linux-2.6.12-rc2 |
72 73 74 75 76 77 |
* The sem is only needed when accessing/extending the cache-chain, which * can never happen inside an interrupt (kmem_cache_create(), * kmem_cache_shrink() and kmem_cache_reap()). * * At present, each engine can be growing a cache. This should be blocked. * |
e498be7da [PATCH] Numa-awar... |
78 79 80 81 82 83 84 85 86 |
* 15 March 2005. NUMA slab allocator. * Shai Fultheim <shai@scalex86.org>. * Shobhit Dayal <shobhit@calsoftinc.com> * Alok N Kataria <alokk@calsoftinc.com> * Christoph Lameter <christoph@lameter.com> * * Modified the slab allocator to be node aware on NUMA systems. * Each node has its own list of partial, free and full slabs. * All object allocations for a node occur from node specific slab lists. |
1da177e4c Linux-2.6.12-rc2 |
87 |
*/ |
1da177e4c Linux-2.6.12-rc2 |
88 89 |
#include <linux/slab.h> #include <linux/mm.h> |
c9cf55285 [PATCH] add poiso... |
90 |
#include <linux/poison.h> |
1da177e4c Linux-2.6.12-rc2 |
91 92 93 94 95 |
#include <linux/swap.h> #include <linux/cache.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/compiler.h> |
101a50019 [PATCH] cpuset me... |
96 |
#include <linux/cpuset.h> |
a0ec95a8e proc: move /proc/... |
97 |
#include <linux/proc_fs.h> |
1da177e4c Linux-2.6.12-rc2 |
98 99 100 101 102 103 104 |
#include <linux/seq_file.h> #include <linux/notifier.h> #include <linux/kallsyms.h> #include <linux/cpu.h> #include <linux/sysctl.h> #include <linux/module.h> #include <linux/rcupdate.h> |
543537bd9 [PATCH] create a ... |
105 |
#include <linux/string.h> |
138ae6631 [PATCH] slab: use... |
106 |
#include <linux/uaccess.h> |
e498be7da [PATCH] Numa-awar... |
107 |
#include <linux/nodemask.h> |
d5cff6352 kmemleak: Add the... |
108 |
#include <linux/kmemleak.h> |
dc85da15d [PATCH] NUMA poli... |
109 |
#include <linux/mempolicy.h> |
fc0abb145 [PATCH] sem2mutex... |
110 |
#include <linux/mutex.h> |
8a8b6502f [PATCH] fault-inj... |
111 |
#include <linux/fault-inject.h> |
e7eebaf6a [PATCH] pi-futex:... |
112 |
#include <linux/rtmutex.h> |
6a2d7a955 [PATCH] SLAB: use... |
113 |
#include <linux/reciprocal_div.h> |
3ac7fe5a4 infrastructure to... |
114 |
#include <linux/debugobjects.h> |
c175eea46 slab: add hooks f... |
115 |
#include <linux/kmemcheck.h> |
8f9f8d9e8 slab: add memory ... |
116 |
#include <linux/memory.h> |
268bb0ce3 sanitize <linux/p... |
117 |
#include <linux/prefetch.h> |
1da177e4c Linux-2.6.12-rc2 |
118 |
|
381760ead mm: micro-optimis... |
119 |
#include <net/sock.h> |
1da177e4c Linux-2.6.12-rc2 |
120 121 122 |
#include <asm/cacheflush.h> #include <asm/tlbflush.h> #include <asm/page.h> |
4dee6b64e tracing/mm: Move ... |
123 |
#include <trace/events/kmem.h> |
072bb0aa5 mm: sl[au]b: add ... |
124 |
#include "internal.h" |
b9ce5ef49 sl[au]b: always g... |
125 |
#include "slab.h" |
1da177e4c Linux-2.6.12-rc2 |
126 |
/* |
50953fe9e slab allocators: ... |
127 |
* DEBUG - 1 for kmem_cache_create() to honour; SLAB_RED_ZONE & SLAB_POISON. |
1da177e4c Linux-2.6.12-rc2 |
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
* 0 for faster, smaller code (especially in the critical paths). * * STATS - 1 to collect stats for /proc/slabinfo. * 0 for faster, smaller code (especially in the critical paths). * * FORCED_DEBUG - 1 enables SLAB_RED_ZONE and SLAB_POISON (if possible) */ #ifdef CONFIG_DEBUG_SLAB #define DEBUG 1 #define STATS 1 #define FORCED_DEBUG 1 #else #define DEBUG 0 #define STATS 0 #define FORCED_DEBUG 0 #endif |
1da177e4c Linux-2.6.12-rc2 |
145 146 |
/* Shouldn't this be in a header file somewhere? */ #define BYTES_PER_WORD sizeof(void *) |
87a927c71 Fix slab redzone ... |
147 |
#define REDZONE_ALIGN max(BYTES_PER_WORD, __alignof__(unsigned long long)) |
1da177e4c Linux-2.6.12-rc2 |
148 |
|
1da177e4c Linux-2.6.12-rc2 |
149 150 151 |
#ifndef ARCH_KMALLOC_FLAGS #define ARCH_KMALLOC_FLAGS SLAB_HWCACHE_ALIGN #endif |
f315e3fa1 slab: restrict th... |
152 153 154 155 156 157 158 159 160 161 |
#define FREELIST_BYTE_INDEX (((PAGE_SIZE >> BITS_PER_BYTE) \ <= SLAB_OBJ_MIN_SIZE) ? 1 : 0) #if FREELIST_BYTE_INDEX typedef unsigned char freelist_idx_t; #else typedef unsigned short freelist_idx_t; #endif #define SLAB_OBJ_MAX_NUM (1 << sizeof(freelist_idx_t) * BITS_PER_BYTE) |
072bb0aa5 mm: sl[au]b: add ... |
162 163 164 165 166 |
/* * true if a page was allocated from pfmemalloc reserves for network-based * swap */ static bool pfmemalloc_active __read_mostly; |
1da177e4c Linux-2.6.12-rc2 |
167 |
/* |
1da177e4c Linux-2.6.12-rc2 |
168 169 |
* struct array_cache * |
1da177e4c Linux-2.6.12-rc2 |
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
* Purpose: * - LIFO ordering, to hand out cache-warm objects from _alloc * - reduce the number of linked list operations * - reduce spinlock operations * * The limit is stored in the per-cpu structure to reduce the data cache * footprint. * */ struct array_cache { unsigned int avail; unsigned int limit; unsigned int batchcount; unsigned int touched; |
e498be7da [PATCH] Numa-awar... |
184 |
spinlock_t lock; |
bda5b655f Delete gcc-2.95 c... |
185 |
void *entry[]; /* |
a737b3e2f [PATCH] slab cleanup |
186 187 188 |
* Must have this definition in here for the proper * alignment of array_cache. Also simplifies accessing * the entries. |
072bb0aa5 mm: sl[au]b: add ... |
189 190 191 192 |
* * Entries should not be directly dereferenced as * entries belonging to slabs marked pfmemalloc will * have the lower bits set SLAB_OBJ_PFMEMALLOC |
a737b3e2f [PATCH] slab cleanup |
193 |
*/ |
1da177e4c Linux-2.6.12-rc2 |
194 |
}; |
072bb0aa5 mm: sl[au]b: add ... |
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
#define SLAB_OBJ_PFMEMALLOC 1 static inline bool is_obj_pfmemalloc(void *objp) { return (unsigned long)objp & SLAB_OBJ_PFMEMALLOC; } static inline void set_obj_pfmemalloc(void **objp) { *objp = (void *)((unsigned long)*objp | SLAB_OBJ_PFMEMALLOC); return; } static inline void clear_obj_pfmemalloc(void **objp) { *objp = (void *)((unsigned long)*objp & ~SLAB_OBJ_PFMEMALLOC); } |
a737b3e2f [PATCH] slab cleanup |
211 212 213 |
/* * bootstrap: The caches do not work without cpuarrays anymore, but the * cpuarrays are allocated from the generic caches... |
1da177e4c Linux-2.6.12-rc2 |
214 215 216 217 |
*/ #define BOOT_CPUCACHE_ENTRIES 1 struct arraycache_init { struct array_cache cache; |
b28a02de8 [PATCH] slab: fix... |
218 |
void *entries[BOOT_CPUCACHE_ENTRIES]; |
1da177e4c Linux-2.6.12-rc2 |
219 220 221 |
}; /* |
e498be7da [PATCH] Numa-awar... |
222 223 |
* Need this for bootstrapping a per node allocator. */ |
556a169da slab: fix bootstr... |
224 |
#define NUM_INIT_LISTS (3 * MAX_NUMNODES) |
ce8eb6c42 slab: Rename list... |
225 |
static struct kmem_cache_node __initdata init_kmem_cache_node[NUM_INIT_LISTS]; |
e498be7da [PATCH] Numa-awar... |
226 |
#define CACHE_CACHE 0 |
556a169da slab: fix bootstr... |
227 |
#define SIZE_AC MAX_NUMNODES |
ce8eb6c42 slab: Rename list... |
228 |
#define SIZE_NODE (2 * MAX_NUMNODES) |
e498be7da [PATCH] Numa-awar... |
229 |
|
ed11d9eb2 [PATCH] slab: con... |
230 |
static int drain_freelist(struct kmem_cache *cache, |
ce8eb6c42 slab: Rename list... |
231 |
struct kmem_cache_node *n, int tofree); |
ed11d9eb2 [PATCH] slab: con... |
232 233 |
static void free_block(struct kmem_cache *cachep, void **objpp, int len, int node); |
83b519e8b slab: setup alloc... |
234 |
static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp); |
65f27f384 WorkStruct: Pass ... |
235 |
static void cache_reap(struct work_struct *unused); |
ed11d9eb2 [PATCH] slab: con... |
236 |
|
e0a427267 [PATCH] mm/slab.c... |
237 |
static int slab_early_init = 1; |
e33660165 slab: Use common ... |
238 |
#define INDEX_AC kmalloc_index(sizeof(struct arraycache_init)) |
ce8eb6c42 slab: Rename list... |
239 |
#define INDEX_NODE kmalloc_index(sizeof(struct kmem_cache_node)) |
1da177e4c Linux-2.6.12-rc2 |
240 |
|
ce8eb6c42 slab: Rename list... |
241 |
static void kmem_cache_node_init(struct kmem_cache_node *parent) |
e498be7da [PATCH] Numa-awar... |
242 243 244 245 246 247 |
{ INIT_LIST_HEAD(&parent->slabs_full); INIT_LIST_HEAD(&parent->slabs_partial); INIT_LIST_HEAD(&parent->slabs_free); parent->shared = NULL; parent->alien = NULL; |
2e1217cf9 [PATCH] NUMA slab... |
248 |
parent->colour_next = 0; |
e498be7da [PATCH] Numa-awar... |
249 250 251 252 |
spin_lock_init(&parent->list_lock); parent->free_objects = 0; parent->free_touched = 0; } |
a737b3e2f [PATCH] slab cleanup |
253 254 255 |
#define MAKE_LIST(cachep, listp, slab, nodeid) \ do { \ INIT_LIST_HEAD(listp); \ |
6a67368c3 slab: Rename node... |
256 |
list_splice(&(cachep->node[nodeid]->slab), listp); \ |
e498be7da [PATCH] Numa-awar... |
257 |
} while (0) |
a737b3e2f [PATCH] slab cleanup |
258 259 |
#define MAKE_ALL_LISTS(cachep, ptr, nodeid) \ do { \ |
e498be7da [PATCH] Numa-awar... |
260 261 262 263 |
MAKE_LIST((cachep), (&(ptr)->slabs_full), slabs_full, nodeid); \ MAKE_LIST((cachep), (&(ptr)->slabs_partial), slabs_partial, nodeid); \ MAKE_LIST((cachep), (&(ptr)->slabs_free), slabs_free, nodeid); \ } while (0) |
1da177e4c Linux-2.6.12-rc2 |
264 |
|
1da177e4c Linux-2.6.12-rc2 |
265 266 267 268 |
#define CFLGS_OFF_SLAB (0x80000000UL) #define OFF_SLAB(x) ((x)->flags & CFLGS_OFF_SLAB) #define BATCHREFILL_LIMIT 16 |
a737b3e2f [PATCH] slab cleanup |
269 270 271 |
/* * Optimization question: fewer reaps means less probability for unnessary * cpucache drain/refill cycles. |
1da177e4c Linux-2.6.12-rc2 |
272 |
* |
dc6f3f276 mm/slab.c: fix a ... |
273 |
* OTOH the cpuarrays can contain lots of objects, |
1da177e4c Linux-2.6.12-rc2 |
274 275 |
* which could lock up otherwise freeable slabs. */ |
5f0985bb1 mm/slab.c: cleanu... |
276 277 |
#define REAPTIMEOUT_AC (2*HZ) #define REAPTIMEOUT_NODE (4*HZ) |
1da177e4c Linux-2.6.12-rc2 |
278 279 280 281 282 283 |
#if STATS #define STATS_INC_ACTIVE(x) ((x)->num_active++) #define STATS_DEC_ACTIVE(x) ((x)->num_active--) #define STATS_INC_ALLOCED(x) ((x)->num_allocations++) #define STATS_INC_GROWN(x) ((x)->grown++) |
ed11d9eb2 [PATCH] slab: con... |
284 |
#define STATS_ADD_REAPED(x,y) ((x)->reaped += (y)) |
a737b3e2f [PATCH] slab cleanup |
285 286 287 288 289 |
#define STATS_SET_HIGH(x) \ do { \ if ((x)->num_active > (x)->high_mark) \ (x)->high_mark = (x)->num_active; \ } while (0) |
1da177e4c Linux-2.6.12-rc2 |
290 291 |
#define STATS_INC_ERR(x) ((x)->errors++) #define STATS_INC_NODEALLOCS(x) ((x)->node_allocs++) |
e498be7da [PATCH] Numa-awar... |
292 |
#define STATS_INC_NODEFREES(x) ((x)->node_frees++) |
fb7faf331 [PATCH] slab: add... |
293 |
#define STATS_INC_ACOVERFLOW(x) ((x)->node_overflow++) |
a737b3e2f [PATCH] slab cleanup |
294 295 296 297 298 |
#define STATS_SET_FREEABLE(x, i) \ do { \ if ((x)->max_freeable < i) \ (x)->max_freeable = i; \ } while (0) |
1da177e4c Linux-2.6.12-rc2 |
299 300 301 302 303 304 305 306 307 |
#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit) #define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss) #define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit) #define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss) #else #define STATS_INC_ACTIVE(x) do { } while (0) #define STATS_DEC_ACTIVE(x) do { } while (0) #define STATS_INC_ALLOCED(x) do { } while (0) #define STATS_INC_GROWN(x) do { } while (0) |
4e60c86bd gcc-4.6: mm: fix ... |
308 |
#define STATS_ADD_REAPED(x,y) do { (void)(y); } while (0) |
1da177e4c Linux-2.6.12-rc2 |
309 310 311 |
#define STATS_SET_HIGH(x) do { } while (0) #define STATS_INC_ERR(x) do { } while (0) #define STATS_INC_NODEALLOCS(x) do { } while (0) |
e498be7da [PATCH] Numa-awar... |
312 |
#define STATS_INC_NODEFREES(x) do { } while (0) |
fb7faf331 [PATCH] slab: add... |
313 |
#define STATS_INC_ACOVERFLOW(x) do { } while (0) |
a737b3e2f [PATCH] slab cleanup |
314 |
#define STATS_SET_FREEABLE(x, i) do { } while (0) |
1da177e4c Linux-2.6.12-rc2 |
315 316 317 318 319 320 321 |
#define STATS_INC_ALLOCHIT(x) do { } while (0) #define STATS_INC_ALLOCMISS(x) do { } while (0) #define STATS_INC_FREEHIT(x) do { } while (0) #define STATS_INC_FREEMISS(x) do { } while (0) #endif #if DEBUG |
1da177e4c Linux-2.6.12-rc2 |
322 |
|
a737b3e2f [PATCH] slab cleanup |
323 324 |
/* * memory layout of objects: |
1da177e4c Linux-2.6.12-rc2 |
325 |
* 0 : objp |
3dafccf22 [PATCH] slab: dis... |
326 |
* 0 .. cachep->obj_offset - BYTES_PER_WORD - 1: padding. This ensures that |
1da177e4c Linux-2.6.12-rc2 |
327 328 |
* the end of an object is aligned with the end of the real * allocation. Catches writes behind the end of the allocation. |
3dafccf22 [PATCH] slab: dis... |
329 |
* cachep->obj_offset - BYTES_PER_WORD .. cachep->obj_offset - 1: |
1da177e4c Linux-2.6.12-rc2 |
330 |
* redzone word. |
3dafccf22 [PATCH] slab: dis... |
331 |
* cachep->obj_offset: The real object. |
3b0efdfa1 mm, sl[aou]b: Ext... |
332 333 |
* cachep->size - 2* BYTES_PER_WORD: redzone word [BYTES_PER_WORD long] * cachep->size - 1* BYTES_PER_WORD: last caller address |
a737b3e2f [PATCH] slab cleanup |
334 |
* [BYTES_PER_WORD long] |
1da177e4c Linux-2.6.12-rc2 |
335 |
*/ |
343e0d7a9 [PATCH] slab: rep... |
336 |
static int obj_offset(struct kmem_cache *cachep) |
1da177e4c Linux-2.6.12-rc2 |
337 |
{ |
3dafccf22 [PATCH] slab: dis... |
338 |
return cachep->obj_offset; |
1da177e4c Linux-2.6.12-rc2 |
339 |
} |
b46b8f19c Increase slab red... |
340 |
static unsigned long long *dbg_redzone1(struct kmem_cache *cachep, void *objp) |
1da177e4c Linux-2.6.12-rc2 |
341 342 |
{ BUG_ON(!(cachep->flags & SLAB_RED_ZONE)); |
b46b8f19c Increase slab red... |
343 344 |
return (unsigned long long*) (objp + obj_offset(cachep) - sizeof(unsigned long long)); |
1da177e4c Linux-2.6.12-rc2 |
345 |
} |
b46b8f19c Increase slab red... |
346 |
static unsigned long long *dbg_redzone2(struct kmem_cache *cachep, void *objp) |
1da177e4c Linux-2.6.12-rc2 |
347 348 349 |
{ BUG_ON(!(cachep->flags & SLAB_RED_ZONE)); if (cachep->flags & SLAB_STORE_USER) |
3b0efdfa1 mm, sl[aou]b: Ext... |
350 |
return (unsigned long long *)(objp + cachep->size - |
b46b8f19c Increase slab red... |
351 |
sizeof(unsigned long long) - |
87a927c71 Fix slab redzone ... |
352 |
REDZONE_ALIGN); |
3b0efdfa1 mm, sl[aou]b: Ext... |
353 |
return (unsigned long long *) (objp + cachep->size - |
b46b8f19c Increase slab red... |
354 |
sizeof(unsigned long long)); |
1da177e4c Linux-2.6.12-rc2 |
355 |
} |
343e0d7a9 [PATCH] slab: rep... |
356 |
static void **dbg_userword(struct kmem_cache *cachep, void *objp) |
1da177e4c Linux-2.6.12-rc2 |
357 358 |
{ BUG_ON(!(cachep->flags & SLAB_STORE_USER)); |
3b0efdfa1 mm, sl[aou]b: Ext... |
359 |
return (void **)(objp + cachep->size - BYTES_PER_WORD); |
1da177e4c Linux-2.6.12-rc2 |
360 361 362 |
} #else |
3dafccf22 [PATCH] slab: dis... |
363 |
#define obj_offset(x) 0 |
b46b8f19c Increase slab red... |
364 365 |
#define dbg_redzone1(cachep, objp) ({BUG(); (unsigned long long *)NULL;}) #define dbg_redzone2(cachep, objp) ({BUG(); (unsigned long long *)NULL;}) |
1da177e4c Linux-2.6.12-rc2 |
366 367 368 369 370 |
#define dbg_userword(cachep, objp) ({BUG(); (void **)NULL;}) #endif /* |
3df1cccdf slab: introduce s... |
371 372 |
* Do not go above this order unless 0 objects fit into the slab or * overridden on the command line. |
1da177e4c Linux-2.6.12-rc2 |
373 |
*/ |
543585cc5 slab: rename slab... |
374 375 376 |
#define SLAB_MAX_ORDER_HI 1 #define SLAB_MAX_ORDER_LO 0 static int slab_max_order = SLAB_MAX_ORDER_LO; |
3df1cccdf slab: introduce s... |
377 |
static bool slab_max_order_set __initdata; |
1da177e4c Linux-2.6.12-rc2 |
378 |
|
6ed5eb221 [PATCH] slab: ext... |
379 380 |
static inline struct kmem_cache *virt_to_cache(const void *obj) { |
b49af68ff Add virt_to_head_... |
381 |
struct page *page = virt_to_head_page(obj); |
350260889 slab: Remove some... |
382 |
return page->slab_cache; |
6ed5eb221 [PATCH] slab: ext... |
383 |
} |
8456a648c slab: use struct ... |
384 |
static inline void *index_to_obj(struct kmem_cache *cache, struct page *page, |
8fea4e96a [PATCH] slab: obj... |
385 386 |
unsigned int idx) { |
8456a648c slab: use struct ... |
387 |
return page->s_mem + cache->size * idx; |
8fea4e96a [PATCH] slab: obj... |
388 |
} |
6a2d7a955 [PATCH] SLAB: use... |
389 |
/* |
3b0efdfa1 mm, sl[aou]b: Ext... |
390 391 392 |
* We want to avoid an expensive divide : (offset / cache->size) * Using the fact that size is a constant for a particular cache, * we can replace (offset / cache->size) by |
6a2d7a955 [PATCH] SLAB: use... |
393 394 395 |
* reciprocal_divide(offset, cache->reciprocal_buffer_size) */ static inline unsigned int obj_to_index(const struct kmem_cache *cache, |
8456a648c slab: use struct ... |
396 |
const struct page *page, void *obj) |
8fea4e96a [PATCH] slab: obj... |
397 |
{ |
8456a648c slab: use struct ... |
398 |
u32 offset = (obj - page->s_mem); |
6a2d7a955 [PATCH] SLAB: use... |
399 |
return reciprocal_divide(offset, cache->reciprocal_buffer_size); |
8fea4e96a [PATCH] slab: obj... |
400 |
} |
1da177e4c Linux-2.6.12-rc2 |
401 |
static struct arraycache_init initarray_generic = |
b28a02de8 [PATCH] slab: fix... |
402 |
{ {0, BOOT_CPUCACHE_ENTRIES, 1, 0} }; |
1da177e4c Linux-2.6.12-rc2 |
403 404 |
/* internal cache of cache description objs */ |
9b030cb86 mm/sl[aou]b: Use ... |
405 |
static struct kmem_cache kmem_cache_boot = { |
b28a02de8 [PATCH] slab: fix... |
406 407 408 |
.batchcount = 1, .limit = BOOT_CPUCACHE_ENTRIES, .shared = 1, |
3b0efdfa1 mm, sl[aou]b: Ext... |
409 |
.size = sizeof(struct kmem_cache), |
b28a02de8 [PATCH] slab: fix... |
410 |
.name = "kmem_cache", |
1da177e4c Linux-2.6.12-rc2 |
411 |
}; |
056c62418 [PATCH] slab: fix... |
412 |
#define BAD_ALIEN_MAGIC 0x01020304ul |
f1aaee53f [PATCH] lockdep: ... |
413 414 415 416 417 418 419 420 |
#ifdef CONFIG_LOCKDEP /* * Slab sometimes uses the kmalloc slabs to store the slab headers * for other slabs "off slab". * The locking for this is tricky in that it nests within the locks * of all other slabs in a few places; to deal with this special * locking we put on-slab caches into a separate lock-class. |
056c62418 [PATCH] slab: fix... |
421 422 423 424 |
* * We set lock class for alien array caches which are up during init. * The lock annotation will be lost if all cpus of a node goes down and * then comes back up during hotplug |
f1aaee53f [PATCH] lockdep: ... |
425 |
*/ |
056c62418 [PATCH] slab: fix... |
426 427 |
static struct lock_class_key on_slab_l3_key; static struct lock_class_key on_slab_alc_key; |
83835b3d9 slab, lockdep: An... |
428 429 430 431 432 433 434 435 |
static struct lock_class_key debugobj_l3_key; static struct lock_class_key debugobj_alc_key; static void slab_set_lock_classes(struct kmem_cache *cachep, struct lock_class_key *l3_key, struct lock_class_key *alc_key, int q) { struct array_cache **alc; |
ce8eb6c42 slab: Rename list... |
436 |
struct kmem_cache_node *n; |
83835b3d9 slab, lockdep: An... |
437 |
int r; |
ce8eb6c42 slab: Rename list... |
438 439 |
n = cachep->node[q]; if (!n) |
83835b3d9 slab, lockdep: An... |
440 |
return; |
ce8eb6c42 slab: Rename list... |
441 442 |
lockdep_set_class(&n->list_lock, l3_key); alc = n->alien; |
83835b3d9 slab, lockdep: An... |
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
/* * FIXME: This check for BAD_ALIEN_MAGIC * should go away when common slab code is taught to * work even without alien caches. * Currently, non NUMA code returns BAD_ALIEN_MAGIC * for alloc_alien_cache, */ if (!alc || (unsigned long)alc == BAD_ALIEN_MAGIC) return; for_each_node(r) { if (alc[r]) lockdep_set_class(&alc[r]->lock, alc_key); } } static void slab_set_debugobj_lock_classes_node(struct kmem_cache *cachep, int node) { slab_set_lock_classes(cachep, &debugobj_l3_key, &debugobj_alc_key, node); } static void slab_set_debugobj_lock_classes(struct kmem_cache *cachep) { int node; for_each_online_node(node) slab_set_debugobj_lock_classes_node(cachep, node); } |
ce79ddc8e SLAB: Fix lockdep... |
470 |
static void init_node_lock_keys(int q) |
f1aaee53f [PATCH] lockdep: ... |
471 |
{ |
e33660165 slab: Use common ... |
472 |
int i; |
056c62418 [PATCH] slab: fix... |
473 |
|
97d066091 mm, sl[aou]b: Com... |
474 |
if (slab_state < UP) |
ce79ddc8e SLAB: Fix lockdep... |
475 |
return; |
0f8f8094d slab: fix init_lo... |
476 |
for (i = 1; i <= KMALLOC_SHIFT_HIGH; i++) { |
ce8eb6c42 slab: Rename list... |
477 |
struct kmem_cache_node *n; |
e33660165 slab: Use common ... |
478 479 480 481 |
struct kmem_cache *cache = kmalloc_caches[i]; if (!cache) continue; |
ce79ddc8e SLAB: Fix lockdep... |
482 |
|
ce8eb6c42 slab: Rename list... |
483 484 |
n = cache->node[q]; if (!n || OFF_SLAB(cache)) |
00afa7580 SLAB: Fix lockdep... |
485 |
continue; |
83835b3d9 slab, lockdep: An... |
486 |
|
e33660165 slab: Use common ... |
487 |
slab_set_lock_classes(cache, &on_slab_l3_key, |
83835b3d9 slab, lockdep: An... |
488 |
&on_slab_alc_key, q); |
f1aaee53f [PATCH] lockdep: ... |
489 490 |
} } |
ce79ddc8e SLAB: Fix lockdep... |
491 |
|
6ccfb5bcf slab: annotate on... |
492 493 |
static void on_slab_lock_classes_node(struct kmem_cache *cachep, int q) { |
6a67368c3 slab: Rename node... |
494 |
if (!cachep->node[q]) |
6ccfb5bcf slab: annotate on... |
495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
return; slab_set_lock_classes(cachep, &on_slab_l3_key, &on_slab_alc_key, q); } static inline void on_slab_lock_classes(struct kmem_cache *cachep) { int node; VM_BUG_ON(OFF_SLAB(cachep)); for_each_node(node) on_slab_lock_classes_node(cachep, node); } |
ce79ddc8e SLAB: Fix lockdep... |
509 510 511 512 513 514 515 |
static inline void init_lock_keys(void) { int node; for_each_node(node) init_node_lock_keys(node); } |
f1aaee53f [PATCH] lockdep: ... |
516 |
#else |
ce79ddc8e SLAB: Fix lockdep... |
517 518 519 |
static void init_node_lock_keys(int q) { } |
056c62418 [PATCH] slab: fix... |
520 |
static inline void init_lock_keys(void) |
f1aaee53f [PATCH] lockdep: ... |
521 522 |
{ } |
83835b3d9 slab, lockdep: An... |
523 |
|
6ccfb5bcf slab: annotate on... |
524 525 526 527 528 529 530 |
static inline void on_slab_lock_classes(struct kmem_cache *cachep) { } static inline void on_slab_lock_classes_node(struct kmem_cache *cachep, int node) { } |
83835b3d9 slab, lockdep: An... |
531 532 533 534 535 536 537 |
static void slab_set_debugobj_lock_classes_node(struct kmem_cache *cachep, int node) { } static void slab_set_debugobj_lock_classes(struct kmem_cache *cachep) { } |
f1aaee53f [PATCH] lockdep: ... |
538 |
#endif |
1871e52c7 percpu: make perc... |
539 |
static DEFINE_PER_CPU(struct delayed_work, slab_reap_work); |
1da177e4c Linux-2.6.12-rc2 |
540 |
|
343e0d7a9 [PATCH] slab: rep... |
541 |
static inline struct array_cache *cpu_cache_get(struct kmem_cache *cachep) |
1da177e4c Linux-2.6.12-rc2 |
542 543 544 |
{ return cachep->array[smp_processor_id()]; } |
9cef2e2b6 slab: factor out ... |
545 546 |
static int calculate_nr_objs(size_t slab_size, size_t buffer_size, size_t idx_size, size_t align) |
1da177e4c Linux-2.6.12-rc2 |
547 |
{ |
9cef2e2b6 slab: factor out ... |
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
int nr_objs; size_t freelist_size; /* * Ignore padding for the initial guess. The padding * is at most @align-1 bytes, and @buffer_size is at * least @align. In the worst case, this result will * be one greater than the number of objects that fit * into the memory allocation when taking the padding * into account. */ nr_objs = slab_size / (buffer_size + idx_size); /* * This calculated number will be either the right * amount, or one greater than what we want. */ freelist_size = slab_size - nr_objs * buffer_size; if (freelist_size < ALIGN(nr_objs * idx_size, align)) nr_objs--; return nr_objs; |
fbaccacff [PATCH] slab: cac... |
570 |
} |
1da177e4c Linux-2.6.12-rc2 |
571 |
|
a737b3e2f [PATCH] slab cleanup |
572 573 574 |
/* * Calculate the number of objects and left-over bytes for a given buffer size. */ |
fbaccacff [PATCH] slab: cac... |
575 576 577 578 579 580 581 |
static void cache_estimate(unsigned long gfporder, size_t buffer_size, size_t align, int flags, size_t *left_over, unsigned int *num) { int nr_objs; size_t mgmt_size; size_t slab_size = PAGE_SIZE << gfporder; |
1da177e4c Linux-2.6.12-rc2 |
582 |
|
fbaccacff [PATCH] slab: cac... |
583 584 585 586 587 |
/* * The slab management structure can be either off the slab or * on it. For the latter case, the memory allocated for a * slab is used for: * |
16025177e slab: remove kmem... |
588 |
* - One unsigned int for each object |
fbaccacff [PATCH] slab: cac... |
589 590 591 592 593 594 595 596 597 598 599 |
* - Padding to respect alignment of @align * - @buffer_size bytes for each object * * If the slab management structure is off the slab, then the * alignment will already be calculated into the size. Because * the slabs are all pages aligned, the objects will be at the * correct alignment when allocated. */ if (flags & CFLGS_OFF_SLAB) { mgmt_size = 0; nr_objs = slab_size / buffer_size; |
fbaccacff [PATCH] slab: cac... |
600 |
} else { |
9cef2e2b6 slab: factor out ... |
601 |
nr_objs = calculate_nr_objs(slab_size, buffer_size, |
a41adfaa2 slab: introduce b... |
602 603 |
sizeof(freelist_idx_t), align); mgmt_size = ALIGN(nr_objs * sizeof(freelist_idx_t), align); |
fbaccacff [PATCH] slab: cac... |
604 605 606 |
} *num = nr_objs; *left_over = slab_size - nr_objs*buffer_size - mgmt_size; |
1da177e4c Linux-2.6.12-rc2 |
607 |
} |
f28510d30 slab: Only define... |
608 |
#if DEBUG |
d40cee245 mm: remove remain... |
609 |
#define slab_error(cachep, msg) __slab_error(__func__, cachep, msg) |
1da177e4c Linux-2.6.12-rc2 |
610 |
|
a737b3e2f [PATCH] slab cleanup |
611 612 |
static void __slab_error(const char *function, struct kmem_cache *cachep, char *msg) |
1da177e4c Linux-2.6.12-rc2 |
613 614 615 |
{ printk(KERN_ERR "slab error in %s(): cache `%s': %s ", |
b28a02de8 [PATCH] slab: fix... |
616 |
function, cachep->name, msg); |
1da177e4c Linux-2.6.12-rc2 |
617 |
dump_stack(); |
373d4d099 taint: add explic... |
618 |
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); |
1da177e4c Linux-2.6.12-rc2 |
619 |
} |
f28510d30 slab: Only define... |
620 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
621 |
|
3395ee058 [PATCH] mm: add n... |
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
/* * By default on NUMA we use alien caches to stage the freeing of * objects allocated from other nodes. This causes massive memory * inefficiencies when using fake NUMA setup to split memory into a * large number of small nodes, so it can be disabled on the command * line */ static int use_alien_caches __read_mostly = 1; static int __init noaliencache_setup(char *s) { use_alien_caches = 0; return 1; } __setup("noaliencache", noaliencache_setup); |
3df1cccdf slab: introduce s... |
637 638 639 640 641 642 643 644 645 646 |
static int __init slab_max_order_setup(char *str) { get_option(&str, &slab_max_order); slab_max_order = slab_max_order < 0 ? 0 : min(slab_max_order, MAX_ORDER - 1); slab_max_order_set = true; return 1; } __setup("slab_max_order=", slab_max_order_setup); |
8fce4d8e3 [PATCH] slab: Nod... |
647 648 649 650 651 652 653 |
#ifdef CONFIG_NUMA /* * Special reaping functions for NUMA systems called from cache_reap(). * These take care of doing round robin flushing of alien caches (containing * objects freed on different nodes from which they were allocated) and the * flushing of remote pcps by calling drain_node_pages. */ |
1871e52c7 percpu: make perc... |
654 |
static DEFINE_PER_CPU(unsigned long, slab_reap_node); |
8fce4d8e3 [PATCH] slab: Nod... |
655 656 657 658 |
static void init_reap_node(int cpu) { int node; |
7d6e6d09d numa: slab: use n... |
659 |
node = next_node(cpu_to_mem(cpu), node_online_map); |
8fce4d8e3 [PATCH] slab: Nod... |
660 |
if (node == MAX_NUMNODES) |
442295c94 [PATCH] mm: slab ... |
661 |
node = first_node(node_online_map); |
8fce4d8e3 [PATCH] slab: Nod... |
662 |
|
1871e52c7 percpu: make perc... |
663 |
per_cpu(slab_reap_node, cpu) = node; |
8fce4d8e3 [PATCH] slab: Nod... |
664 665 666 667 |
} static void next_reap_node(void) { |
909ea9646 core: Replace __g... |
668 |
int node = __this_cpu_read(slab_reap_node); |
8fce4d8e3 [PATCH] slab: Nod... |
669 |
|
8fce4d8e3 [PATCH] slab: Nod... |
670 671 672 |
node = next_node(node, node_online_map); if (unlikely(node >= MAX_NUMNODES)) node = first_node(node_online_map); |
909ea9646 core: Replace __g... |
673 |
__this_cpu_write(slab_reap_node, node); |
8fce4d8e3 [PATCH] slab: Nod... |
674 675 676 677 678 679 |
} #else #define init_reap_node(cpu) do { } while (0) #define next_reap_node(void) do { } while (0) #endif |
1da177e4c Linux-2.6.12-rc2 |
680 681 682 683 684 685 686 |
/* * Initiate the reap timer running on the target CPU. We run at around 1 to 2Hz * via the workqueue/eventd. * Add the CPU number into the expiration time to minimize the possibility of * the CPUs getting into lockstep and contending for the global cache chain * lock. */ |
0db0628d9 kernel: delete __... |
687 |
static void start_cpu_timer(int cpu) |
1da177e4c Linux-2.6.12-rc2 |
688 |
{ |
1871e52c7 percpu: make perc... |
689 |
struct delayed_work *reap_work = &per_cpu(slab_reap_work, cpu); |
1da177e4c Linux-2.6.12-rc2 |
690 691 692 693 694 695 |
/* * When this gets called from do_initcalls via cpucache_init(), * init_workqueues() has already run, so keventd will be setup * at that time. */ |
52bad64d9 WorkStruct: Separ... |
696 |
if (keventd_up() && reap_work->work.func == NULL) { |
8fce4d8e3 [PATCH] slab: Nod... |
697 |
init_reap_node(cpu); |
203b42f73 workqueue: make d... |
698 |
INIT_DEFERRABLE_WORK(reap_work, cache_reap); |
2b2842146 [PATCH] user of t... |
699 700 |
schedule_delayed_work_on(cpu, reap_work, __round_jiffies_relative(HZ, cpu)); |
1da177e4c Linux-2.6.12-rc2 |
701 702 |
} } |
e498be7da [PATCH] Numa-awar... |
703 |
static struct array_cache *alloc_arraycache(int node, int entries, |
83b519e8b slab: setup alloc... |
704 |
int batchcount, gfp_t gfp) |
1da177e4c Linux-2.6.12-rc2 |
705 |
{ |
b28a02de8 [PATCH] slab: fix... |
706 |
int memsize = sizeof(void *) * entries + sizeof(struct array_cache); |
1da177e4c Linux-2.6.12-rc2 |
707 |
struct array_cache *nc = NULL; |
83b519e8b slab: setup alloc... |
708 |
nc = kmalloc_node(memsize, gfp, node); |
d5cff6352 kmemleak: Add the... |
709 710 |
/* * The array_cache structures contain pointers to free object. |
25985edce Fix common misspe... |
711 |
* However, when such objects are allocated or transferred to another |
d5cff6352 kmemleak: Add the... |
712 713 714 715 716 |
* cache the pointers are not cleared and they could be counted as * valid references during a kmemleak scan. Therefore, kmemleak must * not scan such objects. */ kmemleak_no_scan(nc); |
1da177e4c Linux-2.6.12-rc2 |
717 718 719 720 721 |
if (nc) { nc->avail = 0; nc->limit = entries; nc->batchcount = batchcount; nc->touched = 0; |
e498be7da [PATCH] Numa-awar... |
722 |
spin_lock_init(&nc->lock); |
1da177e4c Linux-2.6.12-rc2 |
723 724 725 |
} return nc; } |
8456a648c slab: use struct ... |
726 |
static inline bool is_slab_pfmemalloc(struct page *page) |
072bb0aa5 mm: sl[au]b: add ... |
727 |
{ |
072bb0aa5 mm: sl[au]b: add ... |
728 729 730 731 732 733 734 |
return PageSlabPfmemalloc(page); } /* Clears pfmemalloc_active if no slabs have pfmalloc set */ static void recheck_pfmemalloc_active(struct kmem_cache *cachep, struct array_cache *ac) { |
ce8eb6c42 slab: Rename list... |
735 |
struct kmem_cache_node *n = cachep->node[numa_mem_id()]; |
8456a648c slab: use struct ... |
736 |
struct page *page; |
072bb0aa5 mm: sl[au]b: add ... |
737 738 739 740 |
unsigned long flags; if (!pfmemalloc_active) return; |
ce8eb6c42 slab: Rename list... |
741 |
spin_lock_irqsave(&n->list_lock, flags); |
8456a648c slab: use struct ... |
742 743 |
list_for_each_entry(page, &n->slabs_full, lru) if (is_slab_pfmemalloc(page)) |
072bb0aa5 mm: sl[au]b: add ... |
744 |
goto out; |
8456a648c slab: use struct ... |
745 746 |
list_for_each_entry(page, &n->slabs_partial, lru) if (is_slab_pfmemalloc(page)) |
072bb0aa5 mm: sl[au]b: add ... |
747 |
goto out; |
8456a648c slab: use struct ... |
748 749 |
list_for_each_entry(page, &n->slabs_free, lru) if (is_slab_pfmemalloc(page)) |
072bb0aa5 mm: sl[au]b: add ... |
750 751 752 753 |
goto out; pfmemalloc_active = false; out: |
ce8eb6c42 slab: Rename list... |
754 |
spin_unlock_irqrestore(&n->list_lock, flags); |
072bb0aa5 mm: sl[au]b: add ... |
755 |
} |
381760ead mm: micro-optimis... |
756 |
static void *__ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac, |
072bb0aa5 mm: sl[au]b: add ... |
757 758 759 760 761 762 763 |
gfp_t flags, bool force_refill) { int i; void *objp = ac->entry[--ac->avail]; /* Ensure the caller is allowed to use objects from PFMEMALLOC slab */ if (unlikely(is_obj_pfmemalloc(objp))) { |
ce8eb6c42 slab: Rename list... |
764 |
struct kmem_cache_node *n; |
072bb0aa5 mm: sl[au]b: add ... |
765 766 767 768 769 770 771 |
if (gfp_pfmemalloc_allowed(flags)) { clear_obj_pfmemalloc(&objp); return objp; } /* The caller cannot use PFMEMALLOC objects, find another one */ |
d014dc2ed slab: fix startin... |
772 |
for (i = 0; i < ac->avail; i++) { |
072bb0aa5 mm: sl[au]b: add ... |
773 774 775 776 777 778 779 780 781 782 783 784 785 |
/* If a !PFMEMALLOC object is found, swap them */ if (!is_obj_pfmemalloc(ac->entry[i])) { objp = ac->entry[i]; ac->entry[i] = ac->entry[ac->avail]; ac->entry[ac->avail] = objp; return objp; } } /* * If there are empty slabs on the slabs_free list and we are * being forced to refill the cache, mark this one !pfmemalloc. */ |
ce8eb6c42 slab: Rename list... |
786 787 |
n = cachep->node[numa_mem_id()]; if (!list_empty(&n->slabs_free) && force_refill) { |
8456a648c slab: use struct ... |
788 |
struct page *page = virt_to_head_page(objp); |
7ecccf9d1 slab: remove usel... |
789 |
ClearPageSlabPfmemalloc(page); |
072bb0aa5 mm: sl[au]b: add ... |
790 791 792 793 794 795 796 797 798 799 800 801 |
clear_obj_pfmemalloc(&objp); recheck_pfmemalloc_active(cachep, ac); return objp; } /* No !PFMEMALLOC objects available */ ac->avail++; objp = NULL; } return objp; } |
381760ead mm: micro-optimis... |
802 803 804 805 806 807 808 809 810 811 812 813 814 815 |
static inline void *ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac, gfp_t flags, bool force_refill) { void *objp; if (unlikely(sk_memalloc_socks())) objp = __ac_get_obj(cachep, ac, flags, force_refill); else objp = ac->entry[--ac->avail]; return objp; } static void *__ac_put_obj(struct kmem_cache *cachep, struct array_cache *ac, |
072bb0aa5 mm: sl[au]b: add ... |
816 817 818 819 |
void *objp) { if (unlikely(pfmemalloc_active)) { /* Some pfmemalloc slabs exist, check if this is one */ |
30c29bea6 slab: do ClearSla... |
820 |
struct page *page = virt_to_head_page(objp); |
072bb0aa5 mm: sl[au]b: add ... |
821 822 823 |
if (PageSlabPfmemalloc(page)) set_obj_pfmemalloc(&objp); } |
381760ead mm: micro-optimis... |
824 825 826 827 828 829 830 831 |
return objp; } static inline void ac_put_obj(struct kmem_cache *cachep, struct array_cache *ac, void *objp) { if (unlikely(sk_memalloc_socks())) objp = __ac_put_obj(cachep, ac, objp); |
072bb0aa5 mm: sl[au]b: add ... |
832 833 |
ac->entry[ac->avail++] = objp; } |
3ded175a4 [PATCH] slab: add... |
834 835 836 837 838 839 840 841 842 843 |
/* * Transfer objects in one arraycache to another. * Locking must be handled by the caller. * * Return the number of entries transferred. */ static int transfer_objects(struct array_cache *to, struct array_cache *from, unsigned int max) { /* Figure out how many entries to transfer */ |
732eacc05 replace nested ma... |
844 |
int nr = min3(from->avail, max, to->limit - to->avail); |
3ded175a4 [PATCH] slab: add... |
845 846 847 848 849 850 851 852 853 |
if (!nr) return 0; memcpy(to->entry + to->avail, from->entry + from->avail -nr, sizeof(void *) *nr); from->avail -= nr; to->avail += nr; |
3ded175a4 [PATCH] slab: add... |
854 855 |
return nr; } |
765c4507a [PATCH] GFP_THISN... |
856 857 858 |
#ifndef CONFIG_NUMA #define drain_alien_cache(cachep, alien) do { } while (0) |
ce8eb6c42 slab: Rename list... |
859 |
#define reap_alien(cachep, n) do { } while (0) |
765c4507a [PATCH] GFP_THISN... |
860 |
|
83b519e8b slab: setup alloc... |
861 |
static inline struct array_cache **alloc_alien_cache(int node, int limit, gfp_t gfp) |
765c4507a [PATCH] GFP_THISN... |
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 |
{ return (struct array_cache **)BAD_ALIEN_MAGIC; } static inline void free_alien_cache(struct array_cache **ac_ptr) { } static inline int cache_free_alien(struct kmem_cache *cachep, void *objp) { return 0; } static inline void *alternate_node_alloc(struct kmem_cache *cachep, gfp_t flags) { return NULL; } |
8b98c1699 [PATCH] leak trac... |
880 |
static inline void *____cache_alloc_node(struct kmem_cache *cachep, |
765c4507a [PATCH] GFP_THISN... |
881 882 883 884 885 886 |
gfp_t flags, int nodeid) { return NULL; } #else /* CONFIG_NUMA */ |
8b98c1699 [PATCH] leak trac... |
887 |
static void *____cache_alloc_node(struct kmem_cache *, gfp_t, int); |
c61afb181 [PATCH] cpuset me... |
888 |
static void *alternate_node_alloc(struct kmem_cache *, gfp_t); |
dc85da15d [PATCH] NUMA poli... |
889 |
|
83b519e8b slab: setup alloc... |
890 |
static struct array_cache **alloc_alien_cache(int node, int limit, gfp_t gfp) |
e498be7da [PATCH] Numa-awar... |
891 892 |
{ struct array_cache **ac_ptr; |
8ef828668 [PATCH] slab: red... |
893 |
int memsize = sizeof(void *) * nr_node_ids; |
e498be7da [PATCH] Numa-awar... |
894 895 896 897 |
int i; if (limit > 1) limit = 12; |
f3186a9c5 slab: initialize ... |
898 |
ac_ptr = kzalloc_node(memsize, gfp, node); |
e498be7da [PATCH] Numa-awar... |
899 900 |
if (ac_ptr) { for_each_node(i) { |
f3186a9c5 slab: initialize ... |
901 |
if (i == node || !node_online(i)) |
e498be7da [PATCH] Numa-awar... |
902 |
continue; |
83b519e8b slab: setup alloc... |
903 |
ac_ptr[i] = alloc_arraycache(node, limit, 0xbaadf00d, gfp); |
e498be7da [PATCH] Numa-awar... |
904 |
if (!ac_ptr[i]) { |
cc550defe slab: fix typo in... |
905 |
for (i--; i >= 0; i--) |
e498be7da [PATCH] Numa-awar... |
906 907 908 909 910 911 912 913 |
kfree(ac_ptr[i]); kfree(ac_ptr); return NULL; } } } return ac_ptr; } |
5295a74cc [PATCH] slab: red... |
914 |
static void free_alien_cache(struct array_cache **ac_ptr) |
e498be7da [PATCH] Numa-awar... |
915 916 917 918 919 |
{ int i; if (!ac_ptr) return; |
e498be7da [PATCH] Numa-awar... |
920 |
for_each_node(i) |
b28a02de8 [PATCH] slab: fix... |
921 |
kfree(ac_ptr[i]); |
e498be7da [PATCH] Numa-awar... |
922 923 |
kfree(ac_ptr); } |
343e0d7a9 [PATCH] slab: rep... |
924 |
static void __drain_alien_cache(struct kmem_cache *cachep, |
5295a74cc [PATCH] slab: red... |
925 |
struct array_cache *ac, int node) |
e498be7da [PATCH] Numa-awar... |
926 |
{ |
ce8eb6c42 slab: Rename list... |
927 |
struct kmem_cache_node *n = cachep->node[node]; |
e498be7da [PATCH] Numa-awar... |
928 929 |
if (ac->avail) { |
ce8eb6c42 slab: Rename list... |
930 |
spin_lock(&n->list_lock); |
e00946fe2 [PATCH] slab: Byp... |
931 932 933 934 935 |
/* * Stuff objects into the remote nodes shared array first. * That way we could avoid the overhead of putting the objects * into the free lists and getting them back later. */ |
ce8eb6c42 slab: Rename list... |
936 937 |
if (n->shared) transfer_objects(n->shared, ac, ac->limit); |
e00946fe2 [PATCH] slab: Byp... |
938 |
|
ff69416e6 [PATCH] slab: fix... |
939 |
free_block(cachep, ac->entry, ac->avail, node); |
e498be7da [PATCH] Numa-awar... |
940 |
ac->avail = 0; |
ce8eb6c42 slab: Rename list... |
941 |
spin_unlock(&n->list_lock); |
e498be7da [PATCH] Numa-awar... |
942 943 |
} } |
8fce4d8e3 [PATCH] slab: Nod... |
944 945 946 |
/* * Called from cache_reap() to regularly drain alien caches round robin. */ |
ce8eb6c42 slab: Rename list... |
947 |
static void reap_alien(struct kmem_cache *cachep, struct kmem_cache_node *n) |
8fce4d8e3 [PATCH] slab: Nod... |
948 |
{ |
909ea9646 core: Replace __g... |
949 |
int node = __this_cpu_read(slab_reap_node); |
8fce4d8e3 [PATCH] slab: Nod... |
950 |
|
ce8eb6c42 slab: Rename list... |
951 952 |
if (n->alien) { struct array_cache *ac = n->alien[node]; |
e00946fe2 [PATCH] slab: Byp... |
953 954 |
if (ac && ac->avail && spin_trylock_irq(&ac->lock)) { |
8fce4d8e3 [PATCH] slab: Nod... |
955 956 957 958 959 |
__drain_alien_cache(cachep, ac, node); spin_unlock_irq(&ac->lock); } } } |
a737b3e2f [PATCH] slab cleanup |
960 961 |
static void drain_alien_cache(struct kmem_cache *cachep, struct array_cache **alien) |
e498be7da [PATCH] Numa-awar... |
962 |
{ |
b28a02de8 [PATCH] slab: fix... |
963 |
int i = 0; |
e498be7da [PATCH] Numa-awar... |
964 965 966 967 |
struct array_cache *ac; unsigned long flags; for_each_online_node(i) { |
4484ebf12 [PATCH] NUMA slab... |
968 |
ac = alien[i]; |
e498be7da [PATCH] Numa-awar... |
969 970 971 972 973 974 975 |
if (ac) { spin_lock_irqsave(&ac->lock, flags); __drain_alien_cache(cachep, ac, i); spin_unlock_irqrestore(&ac->lock, flags); } } } |
729bd0b74 [PATCH] slab: ext... |
976 |
|
873623dfa [PATCH] lockdep: ... |
977 |
static inline int cache_free_alien(struct kmem_cache *cachep, void *objp) |
729bd0b74 [PATCH] slab: ext... |
978 |
{ |
1ea991b00 slab: remove node... |
979 |
int nodeid = page_to_nid(virt_to_page(objp)); |
ce8eb6c42 slab: Rename list... |
980 |
struct kmem_cache_node *n; |
729bd0b74 [PATCH] slab: ext... |
981 |
struct array_cache *alien = NULL; |
1ca4cb241 [PATCH] slab: red... |
982 |
int node; |
7d6e6d09d numa: slab: use n... |
983 |
node = numa_mem_id(); |
729bd0b74 [PATCH] slab: ext... |
984 985 986 987 988 |
/* * Make sure we are not freeing a object from another node to the array * cache on this cpu. */ |
1ea991b00 slab: remove node... |
989 |
if (likely(nodeid == node)) |
729bd0b74 [PATCH] slab: ext... |
990 |
return 0; |
ce8eb6c42 slab: Rename list... |
991 |
n = cachep->node[node]; |
729bd0b74 [PATCH] slab: ext... |
992 |
STATS_INC_NODEFREES(cachep); |
ce8eb6c42 slab: Rename list... |
993 994 |
if (n->alien && n->alien[nodeid]) { alien = n->alien[nodeid]; |
873623dfa [PATCH] lockdep: ... |
995 |
spin_lock(&alien->lock); |
729bd0b74 [PATCH] slab: ext... |
996 997 998 999 |
if (unlikely(alien->avail == alien->limit)) { STATS_INC_ACOVERFLOW(cachep); __drain_alien_cache(cachep, alien, nodeid); } |
072bb0aa5 mm: sl[au]b: add ... |
1000 |
ac_put_obj(cachep, alien, objp); |
729bd0b74 [PATCH] slab: ext... |
1001 1002 |
spin_unlock(&alien->lock); } else { |
6a67368c3 slab: Rename node... |
1003 |
spin_lock(&(cachep->node[nodeid])->list_lock); |
729bd0b74 [PATCH] slab: ext... |
1004 |
free_block(cachep, &objp, 1, nodeid); |
6a67368c3 slab: Rename node... |
1005 |
spin_unlock(&(cachep->node[nodeid])->list_lock); |
729bd0b74 [PATCH] slab: ext... |
1006 1007 1008 |
} return 1; } |
e498be7da [PATCH] Numa-awar... |
1009 |
#endif |
8f9f8d9e8 slab: add memory ... |
1010 |
/* |
6a67368c3 slab: Rename node... |
1011 |
* Allocates and initializes node for a node on each slab cache, used for |
ce8eb6c42 slab: Rename list... |
1012 |
* either memory or cpu hotplug. If memory is being hot-added, the kmem_cache_node |
8f9f8d9e8 slab: add memory ... |
1013 |
* will be allocated off-node since memory is not yet online for the new node. |
6a67368c3 slab: Rename node... |
1014 |
* When hotplugging memory or a cpu, existing node are not replaced if |
8f9f8d9e8 slab: add memory ... |
1015 1016 |
* already in use. * |
18004c5d4 mm, sl[aou]b: Use... |
1017 |
* Must hold slab_mutex. |
8f9f8d9e8 slab: add memory ... |
1018 |
*/ |
6a67368c3 slab: Rename node... |
1019 |
static int init_cache_node_node(int node) |
8f9f8d9e8 slab: add memory ... |
1020 1021 |
{ struct kmem_cache *cachep; |
ce8eb6c42 slab: Rename list... |
1022 |
struct kmem_cache_node *n; |
6744f087b slab: Common name... |
1023 |
const int memsize = sizeof(struct kmem_cache_node); |
8f9f8d9e8 slab: add memory ... |
1024 |
|
18004c5d4 mm, sl[aou]b: Use... |
1025 |
list_for_each_entry(cachep, &slab_caches, list) { |
8f9f8d9e8 slab: add memory ... |
1026 |
/* |
5f0985bb1 mm/slab.c: cleanu... |
1027 |
* Set up the kmem_cache_node for cpu before we can |
8f9f8d9e8 slab: add memory ... |
1028 1029 1030 |
* begin anything. Make sure some other cpu on this * node has not already allocated this */ |
6a67368c3 slab: Rename node... |
1031 |
if (!cachep->node[node]) { |
ce8eb6c42 slab: Rename list... |
1032 1033 |
n = kmalloc_node(memsize, GFP_KERNEL, node); if (!n) |
8f9f8d9e8 slab: add memory ... |
1034 |
return -ENOMEM; |
ce8eb6c42 slab: Rename list... |
1035 |
kmem_cache_node_init(n); |
5f0985bb1 mm/slab.c: cleanu... |
1036 1037 |
n->next_reap = jiffies + REAPTIMEOUT_NODE + ((unsigned long)cachep) % REAPTIMEOUT_NODE; |
8f9f8d9e8 slab: add memory ... |
1038 1039 |
/* |
5f0985bb1 mm/slab.c: cleanu... |
1040 1041 |
* The kmem_cache_nodes don't come and go as CPUs * come and go. slab_mutex is sufficient |
8f9f8d9e8 slab: add memory ... |
1042 1043 |
* protection here. */ |
ce8eb6c42 slab: Rename list... |
1044 |
cachep->node[node] = n; |
8f9f8d9e8 slab: add memory ... |
1045 |
} |
6a67368c3 slab: Rename node... |
1046 1047 |
spin_lock_irq(&cachep->node[node]->list_lock); cachep->node[node]->free_limit = |
8f9f8d9e8 slab: add memory ... |
1048 1049 |
(1 + nr_cpus_node(node)) * cachep->batchcount + cachep->num; |
6a67368c3 slab: Rename node... |
1050 |
spin_unlock_irq(&cachep->node[node]->list_lock); |
8f9f8d9e8 slab: add memory ... |
1051 1052 1053 |
} return 0; } |
0fa8103be mm/slab: Fix drai... |
1054 1055 1056 1057 1058 |
static inline int slabs_tofree(struct kmem_cache *cachep, struct kmem_cache_node *n) { return (n->free_objects + cachep->num - 1) / cachep->num; } |
0db0628d9 kernel: delete __... |
1059 |
static void cpuup_canceled(long cpu) |
fbf1e473b cpu hotplug: slab... |
1060 1061 |
{ struct kmem_cache *cachep; |
ce8eb6c42 slab: Rename list... |
1062 |
struct kmem_cache_node *n = NULL; |
7d6e6d09d numa: slab: use n... |
1063 |
int node = cpu_to_mem(cpu); |
a70f73028 cpumask: replace ... |
1064 |
const struct cpumask *mask = cpumask_of_node(node); |
fbf1e473b cpu hotplug: slab... |
1065 |
|
18004c5d4 mm, sl[aou]b: Use... |
1066 |
list_for_each_entry(cachep, &slab_caches, list) { |
fbf1e473b cpu hotplug: slab... |
1067 1068 1069 |
struct array_cache *nc; struct array_cache *shared; struct array_cache **alien; |
fbf1e473b cpu hotplug: slab... |
1070 |
|
fbf1e473b cpu hotplug: slab... |
1071 1072 1073 |
/* cpu is dead; no one can alloc from it. */ nc = cachep->array[cpu]; cachep->array[cpu] = NULL; |
ce8eb6c42 slab: Rename list... |
1074 |
n = cachep->node[node]; |
fbf1e473b cpu hotplug: slab... |
1075 |
|
ce8eb6c42 slab: Rename list... |
1076 |
if (!n) |
fbf1e473b cpu hotplug: slab... |
1077 |
goto free_array_cache; |
ce8eb6c42 slab: Rename list... |
1078 |
spin_lock_irq(&n->list_lock); |
fbf1e473b cpu hotplug: slab... |
1079 |
|
ce8eb6c42 slab: Rename list... |
1080 1081 |
/* Free limit for this kmem_cache_node */ n->free_limit -= cachep->batchcount; |
fbf1e473b cpu hotplug: slab... |
1082 1083 |
if (nc) free_block(cachep, nc->entry, nc->avail, node); |
58463c1fe cpumask: avoid de... |
1084 |
if (!cpumask_empty(mask)) { |
ce8eb6c42 slab: Rename list... |
1085 |
spin_unlock_irq(&n->list_lock); |
fbf1e473b cpu hotplug: slab... |
1086 1087 |
goto free_array_cache; } |
ce8eb6c42 slab: Rename list... |
1088 |
shared = n->shared; |
fbf1e473b cpu hotplug: slab... |
1089 1090 1091 |
if (shared) { free_block(cachep, shared->entry, shared->avail, node); |
ce8eb6c42 slab: Rename list... |
1092 |
n->shared = NULL; |
fbf1e473b cpu hotplug: slab... |
1093 |
} |
ce8eb6c42 slab: Rename list... |
1094 1095 |
alien = n->alien; n->alien = NULL; |
fbf1e473b cpu hotplug: slab... |
1096 |
|
ce8eb6c42 slab: Rename list... |
1097 |
spin_unlock_irq(&n->list_lock); |
fbf1e473b cpu hotplug: slab... |
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 |
kfree(shared); if (alien) { drain_alien_cache(cachep, alien); free_alien_cache(alien); } free_array_cache: kfree(nc); } /* * In the previous loop, all the objects were freed to * the respective cache's slabs, now we can go ahead and * shrink each nodelist to its limit. */ |
18004c5d4 mm, sl[aou]b: Use... |
1112 |
list_for_each_entry(cachep, &slab_caches, list) { |
ce8eb6c42 slab: Rename list... |
1113 1114 |
n = cachep->node[node]; if (!n) |
fbf1e473b cpu hotplug: slab... |
1115 |
continue; |
0fa8103be mm/slab: Fix drai... |
1116 |
drain_freelist(cachep, n, slabs_tofree(cachep, n)); |
fbf1e473b cpu hotplug: slab... |
1117 1118 |
} } |
0db0628d9 kernel: delete __... |
1119 |
static int cpuup_prepare(long cpu) |
1da177e4c Linux-2.6.12-rc2 |
1120 |
{ |
343e0d7a9 [PATCH] slab: rep... |
1121 |
struct kmem_cache *cachep; |
ce8eb6c42 slab: Rename list... |
1122 |
struct kmem_cache_node *n = NULL; |
7d6e6d09d numa: slab: use n... |
1123 |
int node = cpu_to_mem(cpu); |
8f9f8d9e8 slab: add memory ... |
1124 |
int err; |
1da177e4c Linux-2.6.12-rc2 |
1125 |
|
fbf1e473b cpu hotplug: slab... |
1126 1127 1128 1129 |
/* * We need to do this right in the beginning since * alloc_arraycache's are going to use this list. * kmalloc_node allows us to add the slab to the right |
ce8eb6c42 slab: Rename list... |
1130 |
* kmem_cache_node and not this cpu's kmem_cache_node |
fbf1e473b cpu hotplug: slab... |
1131 |
*/ |
6a67368c3 slab: Rename node... |
1132 |
err = init_cache_node_node(node); |
8f9f8d9e8 slab: add memory ... |
1133 1134 |
if (err < 0) goto bad; |
fbf1e473b cpu hotplug: slab... |
1135 1136 1137 1138 1139 |
/* * Now we can go ahead with allocating the shared arrays and * array caches */ |
18004c5d4 mm, sl[aou]b: Use... |
1140 |
list_for_each_entry(cachep, &slab_caches, list) { |
fbf1e473b cpu hotplug: slab... |
1141 1142 1143 1144 1145 |
struct array_cache *nc; struct array_cache *shared = NULL; struct array_cache **alien = NULL; nc = alloc_arraycache(node, cachep->limit, |
83b519e8b slab: setup alloc... |
1146 |
cachep->batchcount, GFP_KERNEL); |
fbf1e473b cpu hotplug: slab... |
1147 1148 1149 1150 1151 |
if (!nc) goto bad; if (cachep->shared) { shared = alloc_arraycache(node, cachep->shared * cachep->batchcount, |
83b519e8b slab: setup alloc... |
1152 |
0xbaadf00d, GFP_KERNEL); |
12d00f6a1 cpu hotplug: slab... |
1153 1154 |
if (!shared) { kfree(nc); |
1da177e4c Linux-2.6.12-rc2 |
1155 |
goto bad; |
12d00f6a1 cpu hotplug: slab... |
1156 |
} |
fbf1e473b cpu hotplug: slab... |
1157 1158 |
} if (use_alien_caches) { |
83b519e8b slab: setup alloc... |
1159 |
alien = alloc_alien_cache(node, cachep->limit, GFP_KERNEL); |
12d00f6a1 cpu hotplug: slab... |
1160 1161 1162 |
if (!alien) { kfree(shared); kfree(nc); |
fbf1e473b cpu hotplug: slab... |
1163 |
goto bad; |
12d00f6a1 cpu hotplug: slab... |
1164 |
} |
fbf1e473b cpu hotplug: slab... |
1165 1166 |
} cachep->array[cpu] = nc; |
ce8eb6c42 slab: Rename list... |
1167 1168 |
n = cachep->node[node]; BUG_ON(!n); |
fbf1e473b cpu hotplug: slab... |
1169 |
|
ce8eb6c42 slab: Rename list... |
1170 1171 |
spin_lock_irq(&n->list_lock); if (!n->shared) { |
fbf1e473b cpu hotplug: slab... |
1172 1173 1174 1175 |
/* * We are serialised from CPU_DEAD or * CPU_UP_CANCELLED by the cpucontrol lock */ |
ce8eb6c42 slab: Rename list... |
1176 |
n->shared = shared; |
fbf1e473b cpu hotplug: slab... |
1177 1178 |
shared = NULL; } |
4484ebf12 [PATCH] NUMA slab... |
1179 |
#ifdef CONFIG_NUMA |
ce8eb6c42 slab: Rename list... |
1180 1181 |
if (!n->alien) { n->alien = alien; |
fbf1e473b cpu hotplug: slab... |
1182 |
alien = NULL; |
1da177e4c Linux-2.6.12-rc2 |
1183 |
} |
fbf1e473b cpu hotplug: slab... |
1184 |
#endif |
ce8eb6c42 slab: Rename list... |
1185 |
spin_unlock_irq(&n->list_lock); |
fbf1e473b cpu hotplug: slab... |
1186 1187 |
kfree(shared); free_alien_cache(alien); |
83835b3d9 slab, lockdep: An... |
1188 1189 |
if (cachep->flags & SLAB_DEBUG_OBJECTS) slab_set_debugobj_lock_classes_node(cachep, node); |
6ccfb5bcf slab: annotate on... |
1190 1191 1192 |
else if (!OFF_SLAB(cachep) && !(cachep->flags & SLAB_DESTROY_BY_RCU)) on_slab_lock_classes_node(cachep, node); |
fbf1e473b cpu hotplug: slab... |
1193 |
} |
ce79ddc8e SLAB: Fix lockdep... |
1194 |
init_node_lock_keys(node); |
fbf1e473b cpu hotplug: slab... |
1195 1196 |
return 0; bad: |
12d00f6a1 cpu hotplug: slab... |
1197 |
cpuup_canceled(cpu); |
fbf1e473b cpu hotplug: slab... |
1198 1199 |
return -ENOMEM; } |
0db0628d9 kernel: delete __... |
1200 |
static int cpuup_callback(struct notifier_block *nfb, |
fbf1e473b cpu hotplug: slab... |
1201 1202 1203 1204 1205 1206 |
unsigned long action, void *hcpu) { long cpu = (long)hcpu; int err = 0; switch (action) { |
fbf1e473b cpu hotplug: slab... |
1207 1208 |
case CPU_UP_PREPARE: case CPU_UP_PREPARE_FROZEN: |
18004c5d4 mm, sl[aou]b: Use... |
1209 |
mutex_lock(&slab_mutex); |
fbf1e473b cpu hotplug: slab... |
1210 |
err = cpuup_prepare(cpu); |
18004c5d4 mm, sl[aou]b: Use... |
1211 |
mutex_unlock(&slab_mutex); |
1da177e4c Linux-2.6.12-rc2 |
1212 1213 |
break; case CPU_ONLINE: |
8bb784428 Add suspend-relat... |
1214 |
case CPU_ONLINE_FROZEN: |
1da177e4c Linux-2.6.12-rc2 |
1215 1216 1217 |
start_cpu_timer(cpu); break; #ifdef CONFIG_HOTPLUG_CPU |
5830c5902 slab: shut down c... |
1218 |
case CPU_DOWN_PREPARE: |
8bb784428 Add suspend-relat... |
1219 |
case CPU_DOWN_PREPARE_FROZEN: |
5830c5902 slab: shut down c... |
1220 |
/* |
18004c5d4 mm, sl[aou]b: Use... |
1221 |
* Shutdown cache reaper. Note that the slab_mutex is |
5830c5902 slab: shut down c... |
1222 1223 1224 1225 |
* held so that if cache_reap() is invoked it cannot do * anything expensive but will only modify reap_work * and reschedule the timer. */ |
afe2c511f workqueue: conver... |
1226 |
cancel_delayed_work_sync(&per_cpu(slab_reap_work, cpu)); |
5830c5902 slab: shut down c... |
1227 |
/* Now the cache_reaper is guaranteed to be not running. */ |
1871e52c7 percpu: make perc... |
1228 |
per_cpu(slab_reap_work, cpu).work.func = NULL; |
5830c5902 slab: shut down c... |
1229 1230 |
break; case CPU_DOWN_FAILED: |
8bb784428 Add suspend-relat... |
1231 |
case CPU_DOWN_FAILED_FROZEN: |
5830c5902 slab: shut down c... |
1232 1233 |
start_cpu_timer(cpu); break; |
1da177e4c Linux-2.6.12-rc2 |
1234 |
case CPU_DEAD: |
8bb784428 Add suspend-relat... |
1235 |
case CPU_DEAD_FROZEN: |
4484ebf12 [PATCH] NUMA slab... |
1236 1237 |
/* * Even if all the cpus of a node are down, we don't free the |
ce8eb6c42 slab: Rename list... |
1238 |
* kmem_cache_node of any cache. This to avoid a race between |
4484ebf12 [PATCH] NUMA slab... |
1239 |
* cpu_down, and a kmalloc allocation from another cpu for |
ce8eb6c42 slab: Rename list... |
1240 |
* memory from the node of the cpu going down. The node |
4484ebf12 [PATCH] NUMA slab... |
1241 1242 1243 |
* structure is usually allocated from kmem_cache_create() and * gets destroyed at kmem_cache_destroy(). */ |
183ff22bb spelling fixes: mm/ |
1244 |
/* fall through */ |
8f5be20bf [PATCH] mm: slab:... |
1245 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
1246 |
case CPU_UP_CANCELED: |
8bb784428 Add suspend-relat... |
1247 |
case CPU_UP_CANCELED_FROZEN: |
18004c5d4 mm, sl[aou]b: Use... |
1248 |
mutex_lock(&slab_mutex); |
fbf1e473b cpu hotplug: slab... |
1249 |
cpuup_canceled(cpu); |
18004c5d4 mm, sl[aou]b: Use... |
1250 |
mutex_unlock(&slab_mutex); |
1da177e4c Linux-2.6.12-rc2 |
1251 |
break; |
1da177e4c Linux-2.6.12-rc2 |
1252 |
} |
eac406801 slab: convert cpu... |
1253 |
return notifier_from_errno(err); |
1da177e4c Linux-2.6.12-rc2 |
1254 |
} |
0db0628d9 kernel: delete __... |
1255 |
static struct notifier_block cpucache_notifier = { |
74b85f379 [PATCH] cpu hotpl... |
1256 1257 |
&cpuup_callback, NULL, 0 }; |
1da177e4c Linux-2.6.12-rc2 |
1258 |
|
8f9f8d9e8 slab: add memory ... |
1259 1260 1261 1262 1263 1264 |
#if defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG) /* * Drains freelist for a node on each slab cache, used for memory hot-remove. * Returns -EBUSY if all objects cannot be drained so that the node is not * removed. * |
18004c5d4 mm, sl[aou]b: Use... |
1265 |
* Must hold slab_mutex. |
8f9f8d9e8 slab: add memory ... |
1266 |
*/ |
6a67368c3 slab: Rename node... |
1267 |
static int __meminit drain_cache_node_node(int node) |
8f9f8d9e8 slab: add memory ... |
1268 1269 1270 |
{ struct kmem_cache *cachep; int ret = 0; |
18004c5d4 mm, sl[aou]b: Use... |
1271 |
list_for_each_entry(cachep, &slab_caches, list) { |
ce8eb6c42 slab: Rename list... |
1272 |
struct kmem_cache_node *n; |
8f9f8d9e8 slab: add memory ... |
1273 |
|
ce8eb6c42 slab: Rename list... |
1274 1275 |
n = cachep->node[node]; if (!n) |
8f9f8d9e8 slab: add memory ... |
1276 |
continue; |
0fa8103be mm/slab: Fix drai... |
1277 |
drain_freelist(cachep, n, slabs_tofree(cachep, n)); |
8f9f8d9e8 slab: add memory ... |
1278 |
|
ce8eb6c42 slab: Rename list... |
1279 1280 |
if (!list_empty(&n->slabs_full) || !list_empty(&n->slabs_partial)) { |
8f9f8d9e8 slab: add memory ... |
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 |
ret = -EBUSY; break; } } return ret; } static int __meminit slab_memory_callback(struct notifier_block *self, unsigned long action, void *arg) { struct memory_notify *mnb = arg; int ret = 0; int nid; nid = mnb->status_change_nid; if (nid < 0) goto out; switch (action) { case MEM_GOING_ONLINE: |
18004c5d4 mm, sl[aou]b: Use... |
1301 |
mutex_lock(&slab_mutex); |
6a67368c3 slab: Rename node... |
1302 |
ret = init_cache_node_node(nid); |
18004c5d4 mm, sl[aou]b: Use... |
1303 |
mutex_unlock(&slab_mutex); |
8f9f8d9e8 slab: add memory ... |
1304 1305 |
break; case MEM_GOING_OFFLINE: |
18004c5d4 mm, sl[aou]b: Use... |
1306 |
mutex_lock(&slab_mutex); |
6a67368c3 slab: Rename node... |
1307 |
ret = drain_cache_node_node(nid); |
18004c5d4 mm, sl[aou]b: Use... |
1308 |
mutex_unlock(&slab_mutex); |
8f9f8d9e8 slab: add memory ... |
1309 1310 1311 1312 1313 1314 1315 1316 |
break; case MEM_ONLINE: case MEM_OFFLINE: case MEM_CANCEL_ONLINE: case MEM_CANCEL_OFFLINE: break; } out: |
5fda1bd5b mm: notifier_from... |
1317 |
return notifier_from_errno(ret); |
8f9f8d9e8 slab: add memory ... |
1318 1319 |
} #endif /* CONFIG_NUMA && CONFIG_MEMORY_HOTPLUG */ |
e498be7da [PATCH] Numa-awar... |
1320 |
/* |
ce8eb6c42 slab: Rename list... |
1321 |
* swap the static kmem_cache_node with kmalloced memory |
e498be7da [PATCH] Numa-awar... |
1322 |
*/ |
6744f087b slab: Common name... |
1323 |
static void __init init_list(struct kmem_cache *cachep, struct kmem_cache_node *list, |
8f9f8d9e8 slab: add memory ... |
1324 |
int nodeid) |
e498be7da [PATCH] Numa-awar... |
1325 |
{ |
6744f087b slab: Common name... |
1326 |
struct kmem_cache_node *ptr; |
e498be7da [PATCH] Numa-awar... |
1327 |
|
6744f087b slab: Common name... |
1328 |
ptr = kmalloc_node(sizeof(struct kmem_cache_node), GFP_NOWAIT, nodeid); |
e498be7da [PATCH] Numa-awar... |
1329 |
BUG_ON(!ptr); |
6744f087b slab: Common name... |
1330 |
memcpy(ptr, list, sizeof(struct kmem_cache_node)); |
2b2d5493e [PATCH] lockdep: ... |
1331 1332 1333 1334 |
/* * Do not assume that spinlocks can be initialized via memcpy: */ spin_lock_init(&ptr->list_lock); |
e498be7da [PATCH] Numa-awar... |
1335 |
MAKE_ALL_LISTS(cachep, ptr, nodeid); |
6a67368c3 slab: Rename node... |
1336 |
cachep->node[nodeid] = ptr; |
e498be7da [PATCH] Numa-awar... |
1337 |
} |
a737b3e2f [PATCH] slab cleanup |
1338 |
/* |
ce8eb6c42 slab: Rename list... |
1339 1340 |
* For setting up all the kmem_cache_node for cache whose buffer_size is same as * size of kmem_cache_node. |
556a169da slab: fix bootstr... |
1341 |
*/ |
ce8eb6c42 slab: Rename list... |
1342 |
static void __init set_up_node(struct kmem_cache *cachep, int index) |
556a169da slab: fix bootstr... |
1343 1344 1345 1346 |
{ int node; for_each_online_node(node) { |
ce8eb6c42 slab: Rename list... |
1347 |
cachep->node[node] = &init_kmem_cache_node[index + node]; |
6a67368c3 slab: Rename node... |
1348 |
cachep->node[node]->next_reap = jiffies + |
5f0985bb1 mm/slab.c: cleanu... |
1349 1350 |
REAPTIMEOUT_NODE + ((unsigned long)cachep) % REAPTIMEOUT_NODE; |
556a169da slab: fix bootstr... |
1351 1352 1353 1354 |
} } /* |
3c5834652 slab: Simplify bo... |
1355 |
* The memory after the last cpu cache pointer is used for the |
6a67368c3 slab: Rename node... |
1356 |
* the node pointer. |
3c5834652 slab: Simplify bo... |
1357 |
*/ |
6a67368c3 slab: Rename node... |
1358 |
static void setup_node_pointer(struct kmem_cache *cachep) |
3c5834652 slab: Simplify bo... |
1359 |
{ |
6a67368c3 slab: Rename node... |
1360 |
cachep->node = (struct kmem_cache_node **)&cachep->array[nr_cpu_ids]; |
3c5834652 slab: Simplify bo... |
1361 1362 1363 |
} /* |
a737b3e2f [PATCH] slab cleanup |
1364 1365 |
* Initialisation. Called after the page allocator have been initialised and * before smp_init(). |
1da177e4c Linux-2.6.12-rc2 |
1366 1367 1368 |
*/ void __init kmem_cache_init(void) { |
e498be7da [PATCH] Numa-awar... |
1369 |
int i; |
68126702b slab: overloading... |
1370 1371 |
BUILD_BUG_ON(sizeof(((struct page *)NULL)->lru) < sizeof(struct rcu_head)); |
9b030cb86 mm/sl[aou]b: Use ... |
1372 |
kmem_cache = &kmem_cache_boot; |
6a67368c3 slab: Rename node... |
1373 |
setup_node_pointer(kmem_cache); |
9b030cb86 mm/sl[aou]b: Use ... |
1374 |
|
b6e68bc1b page allocator: s... |
1375 |
if (num_possible_nodes() == 1) |
62918a036 [PATCH] x86-64: s... |
1376 |
use_alien_caches = 0; |
3c5834652 slab: Simplify bo... |
1377 |
for (i = 0; i < NUM_INIT_LISTS; i++) |
ce8eb6c42 slab: Rename list... |
1378 |
kmem_cache_node_init(&init_kmem_cache_node[i]); |
3c5834652 slab: Simplify bo... |
1379 |
|
ce8eb6c42 slab: Rename list... |
1380 |
set_up_node(kmem_cache, CACHE_CACHE); |
1da177e4c Linux-2.6.12-rc2 |
1381 1382 1383 |
/* * Fragmentation resistance on low memory - only use bigger |
3df1cccdf slab: introduce s... |
1384 1385 |
* page orders on machines with more than 32MB of memory if * not overridden on the command line. |
1da177e4c Linux-2.6.12-rc2 |
1386 |
*/ |
3df1cccdf slab: introduce s... |
1387 |
if (!slab_max_order_set && totalram_pages > (32 << 20) >> PAGE_SHIFT) |
543585cc5 slab: rename slab... |
1388 |
slab_max_order = SLAB_MAX_ORDER_HI; |
1da177e4c Linux-2.6.12-rc2 |
1389 |
|
1da177e4c Linux-2.6.12-rc2 |
1390 1391 |
/* Bootstrap is tricky, because several objects are allocated * from caches that do not exist yet: |
9b030cb86 mm/sl[aou]b: Use ... |
1392 1393 1394 |
* 1) initialize the kmem_cache cache: it contains the struct * kmem_cache structures of all caches, except kmem_cache itself: * kmem_cache is statically allocated. |
e498be7da [PATCH] Numa-awar... |
1395 |
* Initially an __init data area is used for the head array and the |
ce8eb6c42 slab: Rename list... |
1396 |
* kmem_cache_node structures, it's replaced with a kmalloc allocated |
e498be7da [PATCH] Numa-awar... |
1397 |
* array at the end of the bootstrap. |
1da177e4c Linux-2.6.12-rc2 |
1398 |
* 2) Create the first kmalloc cache. |
343e0d7a9 [PATCH] slab: rep... |
1399 |
* The struct kmem_cache for the new cache is allocated normally. |
e498be7da [PATCH] Numa-awar... |
1400 1401 1402 |
* An __init data area is used for the head array. * 3) Create the remaining kmalloc caches, with minimally sized * head arrays. |
9b030cb86 mm/sl[aou]b: Use ... |
1403 |
* 4) Replace the __init data head arrays for kmem_cache and the first |
1da177e4c Linux-2.6.12-rc2 |
1404 |
* kmalloc cache with kmalloc allocated arrays. |
ce8eb6c42 slab: Rename list... |
1405 |
* 5) Replace the __init data for kmem_cache_node for kmem_cache and |
e498be7da [PATCH] Numa-awar... |
1406 1407 |
* the other cache's with kmalloc allocated memory. * 6) Resize the head arrays of the kmalloc caches to their final sizes. |
1da177e4c Linux-2.6.12-rc2 |
1408 |
*/ |
9b030cb86 mm/sl[aou]b: Use ... |
1409 |
/* 1) create the kmem_cache */ |
1da177e4c Linux-2.6.12-rc2 |
1410 |
|
8da3430d8 slab: NUMA kmem_c... |
1411 |
/* |
b56efcf0a slab: shrink size... |
1412 |
* struct kmem_cache size depends on nr_node_ids & nr_cpu_ids |
8da3430d8 slab: NUMA kmem_c... |
1413 |
*/ |
2f9baa9fc slab: Use the new... |
1414 1415 |
create_boot_cache(kmem_cache, "kmem_cache", offsetof(struct kmem_cache, array[nr_cpu_ids]) + |
6744f087b slab: Common name... |
1416 |
nr_node_ids * sizeof(struct kmem_cache_node *), |
2f9baa9fc slab: Use the new... |
1417 1418 |
SLAB_HWCACHE_ALIGN); list_add(&kmem_cache->list, &slab_caches); |
1da177e4c Linux-2.6.12-rc2 |
1419 1420 |
/* 2+3) create the kmalloc caches */ |
1da177e4c Linux-2.6.12-rc2 |
1421 |
|
a737b3e2f [PATCH] slab cleanup |
1422 1423 |
/* * Initialize the caches that provide memory for the array cache and the |
ce8eb6c42 slab: Rename list... |
1424 |
* kmem_cache_node structures first. Without this, further allocations will |
a737b3e2f [PATCH] slab cleanup |
1425 |
* bug. |
e498be7da [PATCH] Numa-awar... |
1426 |
*/ |
e33660165 slab: Use common ... |
1427 1428 |
kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac", kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS); |
45530c447 mm, sl[au]b: crea... |
1429 |
|
ce8eb6c42 slab: Rename list... |
1430 1431 1432 1433 |
if (INDEX_AC != INDEX_NODE) kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node", kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS); |
e498be7da [PATCH] Numa-awar... |
1434 |
|
e0a427267 [PATCH] mm/slab.c... |
1435 |
slab_early_init = 0; |
1da177e4c Linux-2.6.12-rc2 |
1436 1437 |
/* 4) Replace the bootstrap head arrays */ { |
2b2d5493e [PATCH] lockdep: ... |
1438 |
struct array_cache *ptr; |
e498be7da [PATCH] Numa-awar... |
1439 |
|
83b519e8b slab: setup alloc... |
1440 |
ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT); |
e498be7da [PATCH] Numa-awar... |
1441 |
|
9b030cb86 mm/sl[aou]b: Use ... |
1442 |
memcpy(ptr, cpu_cache_get(kmem_cache), |
b28a02de8 [PATCH] slab: fix... |
1443 |
sizeof(struct arraycache_init)); |
2b2d5493e [PATCH] lockdep: ... |
1444 1445 1446 1447 |
/* * Do not assume that spinlocks can be initialized via memcpy: */ spin_lock_init(&ptr->lock); |
9b030cb86 mm/sl[aou]b: Use ... |
1448 |
kmem_cache->array[smp_processor_id()] = ptr; |
e498be7da [PATCH] Numa-awar... |
1449 |
|
83b519e8b slab: setup alloc... |
1450 |
ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT); |
e498be7da [PATCH] Numa-awar... |
1451 |
|
e33660165 slab: Use common ... |
1452 |
BUG_ON(cpu_cache_get(kmalloc_caches[INDEX_AC]) |
b28a02de8 [PATCH] slab: fix... |
1453 |
!= &initarray_generic.cache); |
e33660165 slab: Use common ... |
1454 |
memcpy(ptr, cpu_cache_get(kmalloc_caches[INDEX_AC]), |
b28a02de8 [PATCH] slab: fix... |
1455 |
sizeof(struct arraycache_init)); |
2b2d5493e [PATCH] lockdep: ... |
1456 1457 1458 1459 |
/* * Do not assume that spinlocks can be initialized via memcpy: */ spin_lock_init(&ptr->lock); |
e33660165 slab: Use common ... |
1460 |
kmalloc_caches[INDEX_AC]->array[smp_processor_id()] = ptr; |
1da177e4c Linux-2.6.12-rc2 |
1461 |
} |
ce8eb6c42 slab: Rename list... |
1462 |
/* 5) Replace the bootstrap kmem_cache_node */ |
e498be7da [PATCH] Numa-awar... |
1463 |
{ |
1ca4cb241 [PATCH] slab: red... |
1464 |
int nid; |
9c09a95cf slab: partially r... |
1465 |
for_each_online_node(nid) { |
ce8eb6c42 slab: Rename list... |
1466 |
init_list(kmem_cache, &init_kmem_cache_node[CACHE_CACHE + nid], nid); |
556a169da slab: fix bootstr... |
1467 |
|
e33660165 slab: Use common ... |
1468 |
init_list(kmalloc_caches[INDEX_AC], |
ce8eb6c42 slab: Rename list... |
1469 |
&init_kmem_cache_node[SIZE_AC + nid], nid); |
e498be7da [PATCH] Numa-awar... |
1470 |
|
ce8eb6c42 slab: Rename list... |
1471 1472 1473 |
if (INDEX_AC != INDEX_NODE) { init_list(kmalloc_caches[INDEX_NODE], &init_kmem_cache_node[SIZE_NODE + nid], nid); |
e498be7da [PATCH] Numa-awar... |
1474 1475 1476 |
} } } |
1da177e4c Linux-2.6.12-rc2 |
1477 |
|
f97d5f634 slab: Common func... |
1478 |
create_kmalloc_caches(ARCH_KMALLOC_FLAGS); |
8429db5c6 slab: setup cpu c... |
1479 1480 1481 1482 1483 |
} void __init kmem_cache_init_late(void) { struct kmem_cache *cachep; |
97d066091 mm, sl[aou]b: Com... |
1484 |
slab_state = UP; |
52cef1891 slab, lockdep: Fi... |
1485 |
|
8429db5c6 slab: setup cpu c... |
1486 |
/* 6) resize the head arrays to their final sizes */ |
18004c5d4 mm, sl[aou]b: Use... |
1487 1488 |
mutex_lock(&slab_mutex); list_for_each_entry(cachep, &slab_caches, list) |
8429db5c6 slab: setup cpu c... |
1489 1490 |
if (enable_cpucache(cachep, GFP_NOWAIT)) BUG(); |
18004c5d4 mm, sl[aou]b: Use... |
1491 |
mutex_unlock(&slab_mutex); |
056c62418 [PATCH] slab: fix... |
1492 |
|
947ca1856 slab: fix the DEA... |
1493 1494 |
/* Annotate slab for lockdep -- annotate the malloc caches */ init_lock_keys(); |
97d066091 mm, sl[aou]b: Com... |
1495 1496 |
/* Done! */ slab_state = FULL; |
a737b3e2f [PATCH] slab cleanup |
1497 1498 1499 |
/* * Register a cpu startup notifier callback that initializes * cpu_cache_get for all new cpus |
1da177e4c Linux-2.6.12-rc2 |
1500 1501 |
*/ register_cpu_notifier(&cpucache_notifier); |
1da177e4c Linux-2.6.12-rc2 |
1502 |
|
8f9f8d9e8 slab: add memory ... |
1503 1504 1505 |
#ifdef CONFIG_NUMA /* * Register a memory hotplug callback that initializes and frees |
6a67368c3 slab: Rename node... |
1506 |
* node. |
8f9f8d9e8 slab: add memory ... |
1507 1508 1509 |
*/ hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI); #endif |
a737b3e2f [PATCH] slab cleanup |
1510 1511 1512 |
/* * The reap timers are started later, with a module init call: That part * of the kernel is not yet operational. |
1da177e4c Linux-2.6.12-rc2 |
1513 1514 1515 1516 1517 1518 |
*/ } static int __init cpucache_init(void) { int cpu; |
a737b3e2f [PATCH] slab cleanup |
1519 1520 |
/* * Register the timers that return unneeded pages to the page allocator |
1da177e4c Linux-2.6.12-rc2 |
1521 |
*/ |
e498be7da [PATCH] Numa-awar... |
1522 |
for_each_online_cpu(cpu) |
a737b3e2f [PATCH] slab cleanup |
1523 |
start_cpu_timer(cpu); |
a164f8962 slab: move FULL s... |
1524 1525 |
/* Done! */ |
97d066091 mm, sl[aou]b: Com... |
1526 |
slab_state = FULL; |
1da177e4c Linux-2.6.12-rc2 |
1527 1528 |
return 0; } |
1da177e4c Linux-2.6.12-rc2 |
1529 |
__initcall(cpucache_init); |
8bdec192b mm: SLAB Out-of-m... |
1530 1531 1532 |
static noinline void slab_out_of_memory(struct kmem_cache *cachep, gfp_t gfpflags, int nodeid) { |
ce8eb6c42 slab: Rename list... |
1533 |
struct kmem_cache_node *n; |
8456a648c slab: use struct ... |
1534 |
struct page *page; |
8bdec192b mm: SLAB Out-of-m... |
1535 1536 1537 1538 1539 1540 1541 1542 1543 |
unsigned long flags; int node; printk(KERN_WARNING "SLAB: Unable to allocate memory on node %d (gfp=0x%x) ", nodeid, gfpflags); printk(KERN_WARNING " cache: %s, object size: %d, order: %d ", |
3b0efdfa1 mm, sl[aou]b: Ext... |
1544 |
cachep->name, cachep->size, cachep->gfporder); |
8bdec192b mm: SLAB Out-of-m... |
1545 1546 1547 1548 |
for_each_online_node(node) { unsigned long active_objs = 0, num_objs = 0, free_objects = 0; unsigned long active_slabs = 0, num_slabs = 0; |
ce8eb6c42 slab: Rename list... |
1549 1550 |
n = cachep->node[node]; if (!n) |
8bdec192b mm: SLAB Out-of-m... |
1551 |
continue; |
ce8eb6c42 slab: Rename list... |
1552 |
spin_lock_irqsave(&n->list_lock, flags); |
8456a648c slab: use struct ... |
1553 |
list_for_each_entry(page, &n->slabs_full, lru) { |
8bdec192b mm: SLAB Out-of-m... |
1554 1555 1556 |
active_objs += cachep->num; active_slabs++; } |
8456a648c slab: use struct ... |
1557 1558 |
list_for_each_entry(page, &n->slabs_partial, lru) { active_objs += page->active; |
8bdec192b mm: SLAB Out-of-m... |
1559 1560 |
active_slabs++; } |
8456a648c slab: use struct ... |
1561 |
list_for_each_entry(page, &n->slabs_free, lru) |
8bdec192b mm: SLAB Out-of-m... |
1562 |
num_slabs++; |
ce8eb6c42 slab: Rename list... |
1563 1564 |
free_objects += n->free_objects; spin_unlock_irqrestore(&n->list_lock, flags); |
8bdec192b mm: SLAB Out-of-m... |
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 |
num_slabs += active_slabs; num_objs = num_slabs * cachep->num; printk(KERN_WARNING " node %d: slabs: %ld/%ld, objs: %ld/%ld, free: %ld ", node, active_slabs, num_slabs, active_objs, num_objs, free_objects); } } |
1da177e4c Linux-2.6.12-rc2 |
1575 1576 1577 1578 1579 1580 1581 |
/* * Interface to system's page allocator. No need to hold the cache-lock. * * If we requested dmaable memory, we will get it. Even if we * did not request dmaable memory, we might get it, but that * would be relatively rare and ignorable. */ |
0c3aa83e0 slab: change retu... |
1582 1583 |
static struct page *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, int nodeid) |
1da177e4c Linux-2.6.12-rc2 |
1584 1585 |
{ struct page *page; |
e1b6aa6f1 [PATCH] slab: cle... |
1586 |
int nr_pages; |
765c4507a [PATCH] GFP_THISN... |
1587 |
|
a618e89f1 slab: rename gfpf... |
1588 |
flags |= cachep->allocflags; |
e12ba74d8 Group short-lived... |
1589 1590 |
if (cachep->flags & SLAB_RECLAIM_ACCOUNT) flags |= __GFP_RECLAIMABLE; |
e1b6aa6f1 [PATCH] slab: cle... |
1591 |
|
517d08699 Merge branch 'akpm' |
1592 |
page = alloc_pages_exact_node(nodeid, flags | __GFP_NOTRACK, cachep->gfporder); |
8bdec192b mm: SLAB Out-of-m... |
1593 1594 1595 |
if (!page) { if (!(flags & __GFP_NOWARN) && printk_ratelimit()) slab_out_of_memory(cachep, flags, nodeid); |
1da177e4c Linux-2.6.12-rc2 |
1596 |
return NULL; |
8bdec192b mm: SLAB Out-of-m... |
1597 |
} |
1da177e4c Linux-2.6.12-rc2 |
1598 |
|
b37f1dd0f mm: introduce __G... |
1599 |
/* Record if ALLOC_NO_WATERMARKS was set when allocating the slab */ |
072bb0aa5 mm: sl[au]b: add ... |
1600 1601 |
if (unlikely(page->pfmemalloc)) pfmemalloc_active = true; |
e1b6aa6f1 [PATCH] slab: cle... |
1602 |
nr_pages = (1 << cachep->gfporder); |
1da177e4c Linux-2.6.12-rc2 |
1603 |
if (cachep->flags & SLAB_RECLAIM_ACCOUNT) |
972d1a7b1 [PATCH] ZVC: Supp... |
1604 1605 1606 1607 1608 |
add_zone_page_state(page_zone(page), NR_SLAB_RECLAIMABLE, nr_pages); else add_zone_page_state(page_zone(page), NR_SLAB_UNRECLAIMABLE, nr_pages); |
a57a49887 slab: use __GFP_C... |
1609 1610 1611 |
__SetPageSlab(page); if (page->pfmemalloc) SetPageSlabPfmemalloc(page); |
1f458cbf1 memcg: destroy me... |
1612 |
memcg_bind_pages(cachep, cachep->gfporder); |
072bb0aa5 mm: sl[au]b: add ... |
1613 |
|
b1eeab676 kmemcheck: add ho... |
1614 1615 1616 1617 1618 1619 1620 1621 |
if (kmemcheck_enabled && !(cachep->flags & SLAB_NOTRACK)) { kmemcheck_alloc_shadow(page, cachep->gfporder, flags, nodeid); if (cachep->ctor) kmemcheck_mark_uninitialized_pages(page, nr_pages); else kmemcheck_mark_unallocated_pages(page, nr_pages); } |
c175eea46 slab: add hooks f... |
1622 |
|
0c3aa83e0 slab: change retu... |
1623 |
return page; |
1da177e4c Linux-2.6.12-rc2 |
1624 1625 1626 1627 1628 |
} /* * Interface to system's page release. */ |
0c3aa83e0 slab: change retu... |
1629 |
static void kmem_freepages(struct kmem_cache *cachep, struct page *page) |
1da177e4c Linux-2.6.12-rc2 |
1630 |
{ |
a57a49887 slab: use __GFP_C... |
1631 |
const unsigned long nr_freed = (1 << cachep->gfporder); |
1da177e4c Linux-2.6.12-rc2 |
1632 |
|
b1eeab676 kmemcheck: add ho... |
1633 |
kmemcheck_free_shadow(page, cachep->gfporder); |
c175eea46 slab: add hooks f... |
1634 |
|
972d1a7b1 [PATCH] ZVC: Supp... |
1635 1636 1637 1638 1639 1640 |
if (cachep->flags & SLAB_RECLAIM_ACCOUNT) sub_zone_page_state(page_zone(page), NR_SLAB_RECLAIMABLE, nr_freed); else sub_zone_page_state(page_zone(page), NR_SLAB_UNRECLAIMABLE, nr_freed); |
73293c2f9 slab: correct pfm... |
1641 |
|
a57a49887 slab: use __GFP_C... |
1642 |
BUG_ON(!PageSlab(page)); |
73293c2f9 slab: correct pfm... |
1643 |
__ClearPageSlabPfmemalloc(page); |
a57a49887 slab: use __GFP_C... |
1644 |
__ClearPageSlab(page); |
8456a648c slab: use struct ... |
1645 1646 |
page_mapcount_reset(page); page->mapping = NULL; |
1f458cbf1 memcg: destroy me... |
1647 1648 |
memcg_release_pages(cachep, cachep->gfporder); |
1da177e4c Linux-2.6.12-rc2 |
1649 1650 |
if (current->reclaim_state) current->reclaim_state->reclaimed_slab += nr_freed; |
0c3aa83e0 slab: change retu... |
1651 |
__free_memcg_kmem_pages(page, cachep->gfporder); |
1da177e4c Linux-2.6.12-rc2 |
1652 1653 1654 1655 |
} static void kmem_rcu_free(struct rcu_head *head) { |
68126702b slab: overloading... |
1656 1657 |
struct kmem_cache *cachep; struct page *page; |
1da177e4c Linux-2.6.12-rc2 |
1658 |
|
68126702b slab: overloading... |
1659 1660 1661 1662 |
page = container_of(head, struct page, rcu_head); cachep = page->slab_cache; kmem_freepages(cachep, page); |
1da177e4c Linux-2.6.12-rc2 |
1663 1664 1665 1666 1667 |
} #if DEBUG #ifdef CONFIG_DEBUG_PAGEALLOC |
343e0d7a9 [PATCH] slab: rep... |
1668 |
static void store_stackinfo(struct kmem_cache *cachep, unsigned long *addr, |
b28a02de8 [PATCH] slab: fix... |
1669 |
unsigned long caller) |
1da177e4c Linux-2.6.12-rc2 |
1670 |
{ |
8c138bc00 slab: Get rid of ... |
1671 |
int size = cachep->object_size; |
1da177e4c Linux-2.6.12-rc2 |
1672 |
|
3dafccf22 [PATCH] slab: dis... |
1673 |
addr = (unsigned long *)&((char *)addr)[obj_offset(cachep)]; |
1da177e4c Linux-2.6.12-rc2 |
1674 |
|
b28a02de8 [PATCH] slab: fix... |
1675 |
if (size < 5 * sizeof(unsigned long)) |
1da177e4c Linux-2.6.12-rc2 |
1676 |
return; |
b28a02de8 [PATCH] slab: fix... |
1677 1678 1679 1680 |
*addr++ = 0x12345678; *addr++ = caller; *addr++ = smp_processor_id(); size -= 3 * sizeof(unsigned long); |
1da177e4c Linux-2.6.12-rc2 |
1681 1682 1683 1684 1685 1686 1687 |
{ unsigned long *sptr = &caller; unsigned long svalue; while (!kstack_end(sptr)) { svalue = *sptr++; if (kernel_text_address(svalue)) { |
b28a02de8 [PATCH] slab: fix... |
1688 |
*addr++ = svalue; |
1da177e4c Linux-2.6.12-rc2 |
1689 1690 1691 1692 1693 1694 1695 |
size -= sizeof(unsigned long); if (size <= sizeof(unsigned long)) break; } } } |
b28a02de8 [PATCH] slab: fix... |
1696 |
*addr++ = 0x87654321; |
1da177e4c Linux-2.6.12-rc2 |
1697 1698 |
} #endif |
343e0d7a9 [PATCH] slab: rep... |
1699 |
static void poison_obj(struct kmem_cache *cachep, void *addr, unsigned char val) |
1da177e4c Linux-2.6.12-rc2 |
1700 |
{ |
8c138bc00 slab: Get rid of ... |
1701 |
int size = cachep->object_size; |
3dafccf22 [PATCH] slab: dis... |
1702 |
addr = &((char *)addr)[obj_offset(cachep)]; |
1da177e4c Linux-2.6.12-rc2 |
1703 1704 |
memset(addr, val, size); |
b28a02de8 [PATCH] slab: fix... |
1705 |
*(unsigned char *)(addr + size - 1) = POISON_END; |
1da177e4c Linux-2.6.12-rc2 |
1706 1707 1708 1709 1710 |
} static void dump_line(char *data, int offset, int limit) { int i; |
aa83aa40e [PATCH] single bi... |
1711 1712 |
unsigned char error = 0; int bad_count = 0; |
fdde6abb3 slab: use print_h... |
1713 |
printk(KERN_ERR "%03x: ", offset); |
aa83aa40e [PATCH] single bi... |
1714 1715 1716 1717 1718 |
for (i = 0; i < limit; i++) { if (data[offset + i] != POISON_FREE) { error = data[offset + i]; bad_count++; } |
aa83aa40e [PATCH] single bi... |
1719 |
} |
fdde6abb3 slab: use print_h... |
1720 1721 |
print_hex_dump(KERN_CONT, "", 0, 16, 1, &data[offset], limit, 1); |
aa83aa40e [PATCH] single bi... |
1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 |
if (bad_count == 1) { error ^= POISON_FREE; if (!(error & (error - 1))) { printk(KERN_ERR "Single bit error detected. Probably " "bad RAM. "); #ifdef CONFIG_X86 printk(KERN_ERR "Run memtest86+ or a similar memory " "test tool. "); #else printk(KERN_ERR "Run a memory test tool. "); #endif } } |
1da177e4c Linux-2.6.12-rc2 |
1739 1740 1741 1742 |
} #endif #if DEBUG |
343e0d7a9 [PATCH] slab: rep... |
1743 |
static void print_objinfo(struct kmem_cache *cachep, void *objp, int lines) |
1da177e4c Linux-2.6.12-rc2 |
1744 1745 1746 1747 1748 |
{ int i, size; char *realobj; if (cachep->flags & SLAB_RED_ZONE) { |
b46b8f19c Increase slab red... |
1749 1750 |
printk(KERN_ERR "Redzone: 0x%llx/0x%llx. ", |
a737b3e2f [PATCH] slab cleanup |
1751 1752 |
*dbg_redzone1(cachep, objp), *dbg_redzone2(cachep, objp)); |
1da177e4c Linux-2.6.12-rc2 |
1753 1754 1755 |
} if (cachep->flags & SLAB_STORE_USER) { |
071361d34 mm: Convert print... |
1756 1757 1758 1759 |
printk(KERN_ERR "Last user: [<%p>](%pSR) ", *dbg_userword(cachep, objp), *dbg_userword(cachep, objp)); |
1da177e4c Linux-2.6.12-rc2 |
1760 |
} |
3dafccf22 [PATCH] slab: dis... |
1761 |
realobj = (char *)objp + obj_offset(cachep); |
8c138bc00 slab: Get rid of ... |
1762 |
size = cachep->object_size; |
b28a02de8 [PATCH] slab: fix... |
1763 |
for (i = 0; i < size && lines; i += 16, lines--) { |
1da177e4c Linux-2.6.12-rc2 |
1764 1765 |
int limit; limit = 16; |
b28a02de8 [PATCH] slab: fix... |
1766 1767 |
if (i + limit > size) limit = size - i; |
1da177e4c Linux-2.6.12-rc2 |
1768 1769 1770 |
dump_line(realobj, i, limit); } } |
343e0d7a9 [PATCH] slab: rep... |
1771 |
static void check_poison_obj(struct kmem_cache *cachep, void *objp) |
1da177e4c Linux-2.6.12-rc2 |
1772 1773 1774 1775 |
{ char *realobj; int size, i; int lines = 0; |
3dafccf22 [PATCH] slab: dis... |
1776 |
realobj = (char *)objp + obj_offset(cachep); |
8c138bc00 slab: Get rid of ... |
1777 |
size = cachep->object_size; |
1da177e4c Linux-2.6.12-rc2 |
1778 |
|
b28a02de8 [PATCH] slab: fix... |
1779 |
for (i = 0; i < size; i++) { |
1da177e4c Linux-2.6.12-rc2 |
1780 |
char exp = POISON_FREE; |
b28a02de8 [PATCH] slab: fix... |
1781 |
if (i == size - 1) |
1da177e4c Linux-2.6.12-rc2 |
1782 1783 1784 1785 1786 1787 |
exp = POISON_END; if (realobj[i] != exp) { int limit; /* Mismatch ! */ /* Print header */ if (lines == 0) { |
b28a02de8 [PATCH] slab: fix... |
1788 |
printk(KERN_ERR |
face37f5e slab: add taint f... |
1789 1790 1791 |
"Slab corruption (%s): %s start=%p, len=%d ", print_tainted(), cachep->name, realobj, size); |
1da177e4c Linux-2.6.12-rc2 |
1792 1793 1794 |
print_objinfo(cachep, objp, 0); } /* Hexdump the affected line */ |
b28a02de8 [PATCH] slab: fix... |
1795 |
i = (i / 16) * 16; |
1da177e4c Linux-2.6.12-rc2 |
1796 |
limit = 16; |
b28a02de8 [PATCH] slab: fix... |
1797 1798 |
if (i + limit > size) limit = size - i; |
1da177e4c Linux-2.6.12-rc2 |
1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 |
dump_line(realobj, i, limit); i += 16; lines++; /* Limit to 5 lines */ if (lines > 5) break; } } if (lines != 0) { /* Print some data about the neighboring objects, if they * exist: */ |
8456a648c slab: use struct ... |
1811 |
struct page *page = virt_to_head_page(objp); |
8fea4e96a [PATCH] slab: obj... |
1812 |
unsigned int objnr; |
1da177e4c Linux-2.6.12-rc2 |
1813 |
|
8456a648c slab: use struct ... |
1814 |
objnr = obj_to_index(cachep, page, objp); |
1da177e4c Linux-2.6.12-rc2 |
1815 |
if (objnr) { |
8456a648c slab: use struct ... |
1816 |
objp = index_to_obj(cachep, page, objnr - 1); |
3dafccf22 [PATCH] slab: dis... |
1817 |
realobj = (char *)objp + obj_offset(cachep); |
1da177e4c Linux-2.6.12-rc2 |
1818 1819 |
printk(KERN_ERR "Prev obj: start=%p, len=%d ", |
b28a02de8 [PATCH] slab: fix... |
1820 |
realobj, size); |
1da177e4c Linux-2.6.12-rc2 |
1821 1822 |
print_objinfo(cachep, objp, 2); } |
b28a02de8 [PATCH] slab: fix... |
1823 |
if (objnr + 1 < cachep->num) { |
8456a648c slab: use struct ... |
1824 |
objp = index_to_obj(cachep, page, objnr + 1); |
3dafccf22 [PATCH] slab: dis... |
1825 |
realobj = (char *)objp + obj_offset(cachep); |
1da177e4c Linux-2.6.12-rc2 |
1826 1827 |
printk(KERN_ERR "Next obj: start=%p, len=%d ", |
b28a02de8 [PATCH] slab: fix... |
1828 |
realobj, size); |
1da177e4c Linux-2.6.12-rc2 |
1829 1830 1831 1832 1833 |
print_objinfo(cachep, objp, 2); } } } #endif |
12dd36fae [PATCH] slab: ext... |
1834 |
#if DEBUG |
8456a648c slab: use struct ... |
1835 1836 |
static void slab_destroy_debugcheck(struct kmem_cache *cachep, struct page *page) |
1da177e4c Linux-2.6.12-rc2 |
1837 |
{ |
1da177e4c Linux-2.6.12-rc2 |
1838 1839 |
int i; for (i = 0; i < cachep->num; i++) { |
8456a648c slab: use struct ... |
1840 |
void *objp = index_to_obj(cachep, page, i); |
1da177e4c Linux-2.6.12-rc2 |
1841 1842 1843 |
if (cachep->flags & SLAB_POISON) { #ifdef CONFIG_DEBUG_PAGEALLOC |
3b0efdfa1 mm, sl[aou]b: Ext... |
1844 |
if (cachep->size % PAGE_SIZE == 0 && |
a737b3e2f [PATCH] slab cleanup |
1845 |
OFF_SLAB(cachep)) |
b28a02de8 [PATCH] slab: fix... |
1846 |
kernel_map_pages(virt_to_page(objp), |
3b0efdfa1 mm, sl[aou]b: Ext... |
1847 |
cachep->size / PAGE_SIZE, 1); |
1da177e4c Linux-2.6.12-rc2 |
1848 1849 1850 1851 1852 1853 1854 1855 1856 |
else check_poison_obj(cachep, objp); #else check_poison_obj(cachep, objp); #endif } if (cachep->flags & SLAB_RED_ZONE) { if (*dbg_redzone1(cachep, objp) != RED_INACTIVE) slab_error(cachep, "start of a freed object " |
b28a02de8 [PATCH] slab: fix... |
1857 |
"was overwritten"); |
1da177e4c Linux-2.6.12-rc2 |
1858 1859 |
if (*dbg_redzone2(cachep, objp) != RED_INACTIVE) slab_error(cachep, "end of a freed object " |
b28a02de8 [PATCH] slab: fix... |
1860 |
"was overwritten"); |
1da177e4c Linux-2.6.12-rc2 |
1861 |
} |
1da177e4c Linux-2.6.12-rc2 |
1862 |
} |
12dd36fae [PATCH] slab: ext... |
1863 |
} |
1da177e4c Linux-2.6.12-rc2 |
1864 |
#else |
8456a648c slab: use struct ... |
1865 1866 |
static void slab_destroy_debugcheck(struct kmem_cache *cachep, struct page *page) |
12dd36fae [PATCH] slab: ext... |
1867 |
{ |
12dd36fae [PATCH] slab: ext... |
1868 |
} |
1da177e4c Linux-2.6.12-rc2 |
1869 |
#endif |
911851e6e [PATCH] slab: fix... |
1870 1871 1872 |
/** * slab_destroy - destroy and release all objects in a slab * @cachep: cache pointer being destroyed |
cb8ee1a3d mm: Fix warning o... |
1873 |
* @page: page pointer being destroyed |
911851e6e [PATCH] slab: fix... |
1874 |
* |
12dd36fae [PATCH] slab: ext... |
1875 |
* Destroy all the objs in a slab, and release the mem back to the system. |
a737b3e2f [PATCH] slab cleanup |
1876 1877 |
* Before calling the slab must have been unlinked from the cache. The * cache-lock is not held/needed. |
12dd36fae [PATCH] slab: ext... |
1878 |
*/ |
8456a648c slab: use struct ... |
1879 |
static void slab_destroy(struct kmem_cache *cachep, struct page *page) |
12dd36fae [PATCH] slab: ext... |
1880 |
{ |
7e0073552 slab: replace non... |
1881 |
void *freelist; |
12dd36fae [PATCH] slab: ext... |
1882 |
|
8456a648c slab: use struct ... |
1883 1884 |
freelist = page->freelist; slab_destroy_debugcheck(cachep, page); |
1da177e4c Linux-2.6.12-rc2 |
1885 |
if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU)) { |
68126702b slab: overloading... |
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 |
struct rcu_head *head; /* * RCU free overloads the RCU head over the LRU. * slab_page has been overloeaded over the LRU, * however it is not used from now on so that * we can use it safely. */ head = (void *)&page->rcu_head; call_rcu(head, kmem_rcu_free); |
1da177e4c Linux-2.6.12-rc2 |
1896 |
|
1da177e4c Linux-2.6.12-rc2 |
1897 |
} else { |
0c3aa83e0 slab: change retu... |
1898 |
kmem_freepages(cachep, page); |
1da177e4c Linux-2.6.12-rc2 |
1899 |
} |
68126702b slab: overloading... |
1900 1901 |
/* |
8456a648c slab: use struct ... |
1902 |
* From now on, we don't use freelist |
68126702b slab: overloading... |
1903 1904 1905 |
* although actual page can be freed in rcu context */ if (OFF_SLAB(cachep)) |
8456a648c slab: use struct ... |
1906 |
kmem_cache_free(cachep->freelist_cache, freelist); |
1da177e4c Linux-2.6.12-rc2 |
1907 1908 1909 |
} /** |
a70773ddb [PATCH] mm/slab: ... |
1910 1911 1912 1913 1914 1915 1916 |
* calculate_slab_order - calculate size (page order) of slabs * @cachep: pointer to the cache that is being created * @size: size of objects to be created in this cache. * @align: required alignment for the objects. * @flags: slab allocation flags * * Also calculates the number of objects per slab. |
4d268eba1 [PATCH] slab: ext... |
1917 1918 1919 1920 1921 |
* * This could be made much more intelligent. For now, try to avoid using * high order pages for slabs. When the gfp() functions are more friendly * towards high-order requests, this should be changed. */ |
a737b3e2f [PATCH] slab cleanup |
1922 |
static size_t calculate_slab_order(struct kmem_cache *cachep, |
ee13d785e [PATCH] slab: fix... |
1923 |
size_t size, size_t align, unsigned long flags) |
4d268eba1 [PATCH] slab: ext... |
1924 |
{ |
b1ab41c49 [PATCH] slab.c: f... |
1925 |
unsigned long offslab_limit; |
4d268eba1 [PATCH] slab: ext... |
1926 |
size_t left_over = 0; |
9888e6fa7 slab: clarify and... |
1927 |
int gfporder; |
4d268eba1 [PATCH] slab: ext... |
1928 |
|
0aa817f07 Slab allocators: ... |
1929 |
for (gfporder = 0; gfporder <= KMALLOC_MAX_ORDER; gfporder++) { |
4d268eba1 [PATCH] slab: ext... |
1930 1931 |
unsigned int num; size_t remainder; |
9888e6fa7 slab: clarify and... |
1932 |
cache_estimate(gfporder, size, align, flags, &remainder, &num); |
4d268eba1 [PATCH] slab: ext... |
1933 1934 |
if (!num) continue; |
9888e6fa7 slab: clarify and... |
1935 |
|
f315e3fa1 slab: restrict th... |
1936 1937 1938 |
/* Can't handle number of objects more than SLAB_OBJ_MAX_NUM */ if (num > SLAB_OBJ_MAX_NUM) break; |
b1ab41c49 [PATCH] slab.c: f... |
1939 1940 1941 1942 1943 1944 |
if (flags & CFLGS_OFF_SLAB) { /* * Max number of objs-per-slab for caches which * use off-slab slabs. Needed to avoid a possible * looping condition in cache_grow(). */ |
8456a648c slab: use struct ... |
1945 |
offslab_limit = size; |
a41adfaa2 slab: introduce b... |
1946 |
offslab_limit /= sizeof(freelist_idx_t); |
b1ab41c49 [PATCH] slab.c: f... |
1947 1948 1949 1950 |
if (num > offslab_limit) break; } |
4d268eba1 [PATCH] slab: ext... |
1951 |
|
9888e6fa7 slab: clarify and... |
1952 |
/* Found something acceptable - save it away */ |
4d268eba1 [PATCH] slab: ext... |
1953 |
cachep->num = num; |
9888e6fa7 slab: clarify and... |
1954 |
cachep->gfporder = gfporder; |
4d268eba1 [PATCH] slab: ext... |
1955 1956 1957 |
left_over = remainder; /* |
f78bb8ad4 slab: fix calcula... |
1958 1959 1960 1961 1962 1963 1964 1965 |
* A VFS-reclaimable slab tends to have most allocations * as GFP_NOFS and we really don't want to have to be allocating * higher-order pages when we are unable to shrink dcache. */ if (flags & SLAB_RECLAIM_ACCOUNT) break; /* |
4d268eba1 [PATCH] slab: ext... |
1966 1967 1968 |
* Large number of objects is good, but very large slabs are * currently bad for the gfp()s. */ |
543585cc5 slab: rename slab... |
1969 |
if (gfporder >= slab_max_order) |
4d268eba1 [PATCH] slab: ext... |
1970 |
break; |
9888e6fa7 slab: clarify and... |
1971 1972 1973 |
/* * Acceptable internal fragmentation? */ |
a737b3e2f [PATCH] slab cleanup |
1974 |
if (left_over * 8 <= (PAGE_SIZE << gfporder)) |
4d268eba1 [PATCH] slab: ext... |
1975 1976 1977 1978 |
break; } return left_over; } |
83b519e8b slab: setup alloc... |
1979 |
static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp) |
f30cf7d13 [PATCH] slab: ext... |
1980 |
{ |
97d066091 mm, sl[aou]b: Com... |
1981 |
if (slab_state >= FULL) |
83b519e8b slab: setup alloc... |
1982 |
return enable_cpucache(cachep, gfp); |
2ed3a4ef9 [PATCH] slab: do ... |
1983 |
|
97d066091 mm, sl[aou]b: Com... |
1984 |
if (slab_state == DOWN) { |
f30cf7d13 [PATCH] slab: ext... |
1985 |
/* |
2f9baa9fc slab: Use the new... |
1986 |
* Note: Creation of first cache (kmem_cache). |
ce8eb6c42 slab: Rename list... |
1987 |
* The setup_node is taken care |
2f9baa9fc slab: Use the new... |
1988 1989 1990 1991 1992 1993 1994 |
* of by the caller of __kmem_cache_create */ cachep->array[smp_processor_id()] = &initarray_generic.cache; slab_state = PARTIAL; } else if (slab_state == PARTIAL) { /* * Note: the second kmem_cache_create must create the cache |
f30cf7d13 [PATCH] slab: ext... |
1995 1996 1997 1998 1999 2000 |
* that's used by kmalloc(24), otherwise the creation of * further caches will BUG(). */ cachep->array[smp_processor_id()] = &initarray_generic.cache; /* |
ce8eb6c42 slab: Rename list... |
2001 2002 |
* If the cache that's used by kmalloc(sizeof(kmem_cache_node)) is * the second cache, then we need to set up all its node/, |
f30cf7d13 [PATCH] slab: ext... |
2003 2004 |
* otherwise the creation of further caches will BUG(). */ |
ce8eb6c42 slab: Rename list... |
2005 2006 2007 |
set_up_node(cachep, SIZE_AC); if (INDEX_AC == INDEX_NODE) slab_state = PARTIAL_NODE; |
f30cf7d13 [PATCH] slab: ext... |
2008 |
else |
97d066091 mm, sl[aou]b: Com... |
2009 |
slab_state = PARTIAL_ARRAYCACHE; |
f30cf7d13 [PATCH] slab: ext... |
2010 |
} else { |
2f9baa9fc slab: Use the new... |
2011 |
/* Remaining boot caches */ |
f30cf7d13 [PATCH] slab: ext... |
2012 |
cachep->array[smp_processor_id()] = |
83b519e8b slab: setup alloc... |
2013 |
kmalloc(sizeof(struct arraycache_init), gfp); |
f30cf7d13 [PATCH] slab: ext... |
2014 |
|
97d066091 mm, sl[aou]b: Com... |
2015 |
if (slab_state == PARTIAL_ARRAYCACHE) { |
ce8eb6c42 slab: Rename list... |
2016 2017 |
set_up_node(cachep, SIZE_NODE); slab_state = PARTIAL_NODE; |
f30cf7d13 [PATCH] slab: ext... |
2018 2019 |
} else { int node; |
556a169da slab: fix bootstr... |
2020 |
for_each_online_node(node) { |
6a67368c3 slab: Rename node... |
2021 |
cachep->node[node] = |
6744f087b slab: Common name... |
2022 |
kmalloc_node(sizeof(struct kmem_cache_node), |
eb91f1d0a slab: fix gfp fla... |
2023 |
gfp, node); |
6a67368c3 slab: Rename node... |
2024 |
BUG_ON(!cachep->node[node]); |
ce8eb6c42 slab: Rename list... |
2025 |
kmem_cache_node_init(cachep->node[node]); |
f30cf7d13 [PATCH] slab: ext... |
2026 2027 2028 |
} } } |
6a67368c3 slab: Rename node... |
2029 |
cachep->node[numa_mem_id()]->next_reap = |
5f0985bb1 mm/slab.c: cleanu... |
2030 2031 |
jiffies + REAPTIMEOUT_NODE + ((unsigned long)cachep) % REAPTIMEOUT_NODE; |
f30cf7d13 [PATCH] slab: ext... |
2032 2033 2034 2035 2036 2037 2038 |
cpu_cache_get(cachep)->avail = 0; cpu_cache_get(cachep)->limit = BOOT_CPUCACHE_ENTRIES; cpu_cache_get(cachep)->batchcount = 1; cpu_cache_get(cachep)->touched = 0; cachep->batchcount = 1; cachep->limit = BOOT_CPUCACHE_ENTRIES; |
2ed3a4ef9 [PATCH] slab: do ... |
2039 |
return 0; |
f30cf7d13 [PATCH] slab: ext... |
2040 |
} |
4d268eba1 [PATCH] slab: ext... |
2041 |
/** |
039363f38 mm, sl[aou]b: Ext... |
2042 |
* __kmem_cache_create - Create a cache. |
a755b76ab mm: fix slab.c ke... |
2043 |
* @cachep: cache management descriptor |
1da177e4c Linux-2.6.12-rc2 |
2044 |
* @flags: SLAB flags |
1da177e4c Linux-2.6.12-rc2 |
2045 2046 2047 |
* * Returns a ptr to the cache on success, NULL on failure. * Cannot be called within a int, but can be interrupted. |
20c2df83d mm: Remove slab d... |
2048 |
* The @ctor is run when new pages are allocated by the cache. |
1da177e4c Linux-2.6.12-rc2 |
2049 |
* |
1da177e4c Linux-2.6.12-rc2 |
2050 2051 2052 2053 2054 2055 2056 2057 |
* The flags are * * %SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5) * to catch references to uninitialised memory. * * %SLAB_RED_ZONE - Insert `Red' zones around the allocated memory to check * for buffer overruns. * |
1da177e4c Linux-2.6.12-rc2 |
2058 2059 2060 2061 |
* %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware * cacheline. This can be beneficial if you're counting cycles as closely * as davem. */ |
278b1bb13 mm/sl[aou]b: Move... |
2062 |
int |
8a13a4cc8 mm/sl[aou]b: Shri... |
2063 |
__kmem_cache_create (struct kmem_cache *cachep, unsigned long flags) |
1da177e4c Linux-2.6.12-rc2 |
2064 |
{ |
8456a648c slab: use struct ... |
2065 |
size_t left_over, freelist_size, ralign; |
83b519e8b slab: setup alloc... |
2066 |
gfp_t gfp; |
278b1bb13 mm/sl[aou]b: Move... |
2067 |
int err; |
8a13a4cc8 mm/sl[aou]b: Shri... |
2068 |
size_t size = cachep->size; |
1da177e4c Linux-2.6.12-rc2 |
2069 |
|
1da177e4c Linux-2.6.12-rc2 |
2070 |
#if DEBUG |
1da177e4c Linux-2.6.12-rc2 |
2071 2072 2073 2074 2075 2076 2077 |
#if FORCED_DEBUG /* * Enable redzoning and last user accounting, except for caches with * large objects, if the increased size would increase the object size * above the next power of two: caches with object sizes just above a * power of two have a significant amount of internal fragmentation. */ |
87a927c71 Fix slab redzone ... |
2078 2079 |
if (size < 4096 || fls(size - 1) == fls(size-1 + REDZONE_ALIGN + 2 * sizeof(unsigned long long))) |
b28a02de8 [PATCH] slab: fix... |
2080 |
flags |= SLAB_RED_ZONE | SLAB_STORE_USER; |
1da177e4c Linux-2.6.12-rc2 |
2081 2082 2083 2084 2085 2086 |
if (!(flags & SLAB_DESTROY_BY_RCU)) flags |= SLAB_POISON; #endif if (flags & SLAB_DESTROY_BY_RCU) BUG_ON(flags & SLAB_POISON); #endif |
1da177e4c Linux-2.6.12-rc2 |
2087 |
|
a737b3e2f [PATCH] slab cleanup |
2088 2089 |
/* * Check that size is in terms of words. This is needed to avoid |
1da177e4c Linux-2.6.12-rc2 |
2090 2091 2092 |
* unaligned accesses for some archs when redzoning is used, and makes * sure any on-slab bufctl's are also correctly aligned. */ |
b28a02de8 [PATCH] slab: fix... |
2093 2094 2095 |
if (size & (BYTES_PER_WORD - 1)) { size += (BYTES_PER_WORD - 1); size &= ~(BYTES_PER_WORD - 1); |
1da177e4c Linux-2.6.12-rc2 |
2096 |
} |
ca5f9703d [PATCH] slab: res... |
2097 |
/* |
87a927c71 Fix slab redzone ... |
2098 2099 2100 |
* Redzoning and user store require word alignment or possibly larger. * Note this will be overridden by architecture or caller mandated * alignment if either is greater than BYTES_PER_WORD. |
ca5f9703d [PATCH] slab: res... |
2101 |
*/ |
87a927c71 Fix slab redzone ... |
2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 |
if (flags & SLAB_STORE_USER) ralign = BYTES_PER_WORD; if (flags & SLAB_RED_ZONE) { ralign = REDZONE_ALIGN; /* If redzoning, ensure that the second redzone is suitably * aligned, by adjusting the object size accordingly. */ size += REDZONE_ALIGN - 1; size &= ~(REDZONE_ALIGN - 1); } |
ca5f9703d [PATCH] slab: res... |
2112 |
|
a44b56d35 [PATCH] slab debu... |
2113 |
/* 3) caller mandated alignment */ |
8a13a4cc8 mm/sl[aou]b: Shri... |
2114 2115 |
if (ralign < cachep->align) { ralign = cachep->align; |
1da177e4c Linux-2.6.12-rc2 |
2116 |
} |
3ff84a7f3 Revert "slab: Fix... |
2117 2118 |
/* disable debug if necessary */ if (ralign > __alignof__(unsigned long long)) |
a44b56d35 [PATCH] slab debu... |
2119 |
flags &= ~(SLAB_RED_ZONE | SLAB_STORE_USER); |
a737b3e2f [PATCH] slab cleanup |
2120 |
/* |
ca5f9703d [PATCH] slab: res... |
2121 |
* 4) Store it. |
1da177e4c Linux-2.6.12-rc2 |
2122 |
*/ |
8a13a4cc8 mm/sl[aou]b: Shri... |
2123 |
cachep->align = ralign; |
1da177e4c Linux-2.6.12-rc2 |
2124 |
|
83b519e8b slab: setup alloc... |
2125 2126 2127 2128 |
if (slab_is_available()) gfp = GFP_KERNEL; else gfp = GFP_NOWAIT; |
6a67368c3 slab: Rename node... |
2129 |
setup_node_pointer(cachep); |
1da177e4c Linux-2.6.12-rc2 |
2130 |
#if DEBUG |
1da177e4c Linux-2.6.12-rc2 |
2131 |
|
ca5f9703d [PATCH] slab: res... |
2132 2133 2134 2135 |
/* * Both debugging options require word-alignment which is calculated * into align above. */ |
1da177e4c Linux-2.6.12-rc2 |
2136 |
if (flags & SLAB_RED_ZONE) { |
1da177e4c Linux-2.6.12-rc2 |
2137 |
/* add space for red zone words */ |
3ff84a7f3 Revert "slab: Fix... |
2138 2139 |
cachep->obj_offset += sizeof(unsigned long long); size += 2 * sizeof(unsigned long long); |
1da177e4c Linux-2.6.12-rc2 |
2140 2141 |
} if (flags & SLAB_STORE_USER) { |
ca5f9703d [PATCH] slab: res... |
2142 |
/* user store requires one word storage behind the end of |
87a927c71 Fix slab redzone ... |
2143 2144 |
* the real object. But if the second red zone needs to be * aligned to 64 bits, we must allow that much space. |
1da177e4c Linux-2.6.12-rc2 |
2145 |
*/ |
87a927c71 Fix slab redzone ... |
2146 2147 2148 2149 |
if (flags & SLAB_RED_ZONE) size += REDZONE_ALIGN; else size += BYTES_PER_WORD; |
1da177e4c Linux-2.6.12-rc2 |
2150 2151 |
} #if FORCED_DEBUG && defined(CONFIG_DEBUG_PAGEALLOC) |
ce8eb6c42 slab: Rename list... |
2152 |
if (size >= kmalloc_size(INDEX_NODE + 1) |
608da7e3f slab: Fix build f... |
2153 2154 2155 |
&& cachep->object_size > cache_line_size() && ALIGN(size, cachep->align) < PAGE_SIZE) { cachep->obj_offset += PAGE_SIZE - ALIGN(size, cachep->align); |
1da177e4c Linux-2.6.12-rc2 |
2156 2157 2158 2159 |
size = PAGE_SIZE; } #endif #endif |
e0a427267 [PATCH] mm/slab.c... |
2160 2161 2162 |
/* * Determine if the slab management is 'on' or 'off' slab. * (bootstrapping cannot cope with offslab caches so don't do |
e7cb55b94 kmemleak: Do not ... |
2163 2164 |
* it too early on. Always use on-slab management when * SLAB_NOLEAKTRACE to avoid recursive calls into kmemleak) |
e0a427267 [PATCH] mm/slab.c... |
2165 |
*/ |
8fc9cf420 slab: make more s... |
2166 |
if ((size >= (PAGE_SIZE >> 5)) && !slab_early_init && |
e7cb55b94 kmemleak: Do not ... |
2167 |
!(flags & SLAB_NOLEAKTRACE)) |
1da177e4c Linux-2.6.12-rc2 |
2168 2169 2170 2171 2172 |
/* * Size is large, assume best to place the slab management obj * off-slab (should allow better packing of objs). */ flags |= CFLGS_OFF_SLAB; |
8a13a4cc8 mm/sl[aou]b: Shri... |
2173 |
size = ALIGN(size, cachep->align); |
f315e3fa1 slab: restrict th... |
2174 2175 2176 2177 2178 2179 |
/* * We should restrict the number of objects in a slab to implement * byte sized index. Refer comment on SLAB_OBJ_MIN_SIZE definition. */ if (FREELIST_BYTE_INDEX && size < SLAB_OBJ_MIN_SIZE) size = ALIGN(SLAB_OBJ_MIN_SIZE, cachep->align); |
1da177e4c Linux-2.6.12-rc2 |
2180 |
|
8a13a4cc8 mm/sl[aou]b: Shri... |
2181 |
left_over = calculate_slab_order(cachep, size, cachep->align, flags); |
1da177e4c Linux-2.6.12-rc2 |
2182 |
|
8a13a4cc8 mm/sl[aou]b: Shri... |
2183 |
if (!cachep->num) |
278b1bb13 mm/sl[aou]b: Move... |
2184 |
return -E2BIG; |
1da177e4c Linux-2.6.12-rc2 |
2185 |
|
8456a648c slab: use struct ... |
2186 |
freelist_size = |
a41adfaa2 slab: introduce b... |
2187 |
ALIGN(cachep->num * sizeof(freelist_idx_t), cachep->align); |
1da177e4c Linux-2.6.12-rc2 |
2188 2189 2190 2191 2192 |
/* * If the slab has been placed off-slab, and we have enough space then * move it on-slab. This is at the expense of any extra colouring. */ |
8456a648c slab: use struct ... |
2193 |
if (flags & CFLGS_OFF_SLAB && left_over >= freelist_size) { |
1da177e4c Linux-2.6.12-rc2 |
2194 |
flags &= ~CFLGS_OFF_SLAB; |
8456a648c slab: use struct ... |
2195 |
left_over -= freelist_size; |
1da177e4c Linux-2.6.12-rc2 |
2196 2197 2198 2199 |
} if (flags & CFLGS_OFF_SLAB) { /* really off slab. No need for manual alignment */ |
a41adfaa2 slab: introduce b... |
2200 |
freelist_size = cachep->num * sizeof(freelist_idx_t); |
674613652 slab: fix generic... |
2201 2202 2203 2204 2205 2206 2207 2208 2209 |
#ifdef CONFIG_PAGE_POISONING /* If we're going to use the generic kernel_map_pages() * poisoning, then it's going to smash the contents of * the redzone and userword anyhow, so switch them off. */ if (size % PAGE_SIZE == 0 && flags & SLAB_POISON) flags &= ~(SLAB_RED_ZONE | SLAB_STORE_USER); #endif |
1da177e4c Linux-2.6.12-rc2 |
2210 2211 2212 2213 |
} cachep->colour_off = cache_line_size(); /* Offset must be a multiple of the alignment. */ |
8a13a4cc8 mm/sl[aou]b: Shri... |
2214 2215 |
if (cachep->colour_off < cachep->align) cachep->colour_off = cachep->align; |
b28a02de8 [PATCH] slab: fix... |
2216 |
cachep->colour = left_over / cachep->colour_off; |
8456a648c slab: use struct ... |
2217 |
cachep->freelist_size = freelist_size; |
1da177e4c Linux-2.6.12-rc2 |
2218 |
cachep->flags = flags; |
a57a49887 slab: use __GFP_C... |
2219 |
cachep->allocflags = __GFP_COMP; |
4b51d6698 [PATCH] optional ... |
2220 |
if (CONFIG_ZONE_DMA_FLAG && (flags & SLAB_CACHE_DMA)) |
a618e89f1 slab: rename gfpf... |
2221 |
cachep->allocflags |= GFP_DMA; |
3b0efdfa1 mm, sl[aou]b: Ext... |
2222 |
cachep->size = size; |
6a2d7a955 [PATCH] SLAB: use... |
2223 |
cachep->reciprocal_buffer_size = reciprocal_value(size); |
1da177e4c Linux-2.6.12-rc2 |
2224 |
|
e5ac9c5ae [PATCH] Add some ... |
2225 |
if (flags & CFLGS_OFF_SLAB) { |
8456a648c slab: use struct ... |
2226 |
cachep->freelist_cache = kmalloc_slab(freelist_size, 0u); |
e5ac9c5ae [PATCH] Add some ... |
2227 |
/* |
5f0985bb1 mm/slab.c: cleanu... |
2228 |
* This is a possibility for one of the kmalloc_{dma,}_caches. |
e5ac9c5ae [PATCH] Add some ... |
2229 |
* But since we go off slab only for object size greater than |
5f0985bb1 mm/slab.c: cleanu... |
2230 2231 |
* PAGE_SIZE/8, and kmalloc_{dma,}_caches get created * in ascending order,this should not happen at all. |
e5ac9c5ae [PATCH] Add some ... |
2232 2233 |
* But leave a BUG_ON for some lucky dude. */ |
8456a648c slab: use struct ... |
2234 |
BUG_ON(ZERO_OR_NULL_PTR(cachep->freelist_cache)); |
e5ac9c5ae [PATCH] Add some ... |
2235 |
} |
1da177e4c Linux-2.6.12-rc2 |
2236 |
|
278b1bb13 mm/sl[aou]b: Move... |
2237 2238 |
err = setup_cpu_cache(cachep, gfp); if (err) { |
12c3667fb mm/sl[aou]b: Get ... |
2239 |
__kmem_cache_shutdown(cachep); |
278b1bb13 mm/sl[aou]b: Move... |
2240 |
return err; |
2ed3a4ef9 [PATCH] slab: do ... |
2241 |
} |
1da177e4c Linux-2.6.12-rc2 |
2242 |
|
83835b3d9 slab, lockdep: An... |
2243 2244 2245 2246 2247 2248 2249 2250 |
if (flags & SLAB_DEBUG_OBJECTS) { /* * Would deadlock through slab_destroy()->call_rcu()-> * debug_object_activate()->kmem_cache_alloc(). */ WARN_ON_ONCE(flags & SLAB_DESTROY_BY_RCU); slab_set_debugobj_lock_classes(cachep); |
6ccfb5bcf slab: annotate on... |
2251 2252 |
} else if (!OFF_SLAB(cachep) && !(flags & SLAB_DESTROY_BY_RCU)) on_slab_lock_classes(cachep); |
83835b3d9 slab, lockdep: An... |
2253 |
|
278b1bb13 mm/sl[aou]b: Move... |
2254 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
2255 |
} |
1da177e4c Linux-2.6.12-rc2 |
2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 |
#if DEBUG static void check_irq_off(void) { BUG_ON(!irqs_disabled()); } static void check_irq_on(void) { BUG_ON(irqs_disabled()); } |
343e0d7a9 [PATCH] slab: rep... |
2267 |
static void check_spinlock_acquired(struct kmem_cache *cachep) |
1da177e4c Linux-2.6.12-rc2 |
2268 2269 2270 |
{ #ifdef CONFIG_SMP check_irq_off(); |
6a67368c3 slab: Rename node... |
2271 |
assert_spin_locked(&cachep->node[numa_mem_id()]->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
2272 2273 |
#endif } |
e498be7da [PATCH] Numa-awar... |
2274 |
|
343e0d7a9 [PATCH] slab: rep... |
2275 |
static void check_spinlock_acquired_node(struct kmem_cache *cachep, int node) |
e498be7da [PATCH] Numa-awar... |
2276 2277 2278 |
{ #ifdef CONFIG_SMP check_irq_off(); |
6a67368c3 slab: Rename node... |
2279 |
assert_spin_locked(&cachep->node[node]->list_lock); |
e498be7da [PATCH] Numa-awar... |
2280 2281 |
#endif } |
1da177e4c Linux-2.6.12-rc2 |
2282 2283 2284 2285 |
#else #define check_irq_off() do { } while(0) #define check_irq_on() do { } while(0) #define check_spinlock_acquired(x) do { } while(0) |
e498be7da [PATCH] Numa-awar... |
2286 |
#define check_spinlock_acquired_node(x, y) do { } while(0) |
1da177e4c Linux-2.6.12-rc2 |
2287 |
#endif |
ce8eb6c42 slab: Rename list... |
2288 |
static void drain_array(struct kmem_cache *cachep, struct kmem_cache_node *n, |
aab2207cf [PATCH] slab: mak... |
2289 2290 |
struct array_cache *ac, int force, int node); |
1da177e4c Linux-2.6.12-rc2 |
2291 2292 |
static void do_drain(void *arg) { |
a737b3e2f [PATCH] slab cleanup |
2293 |
struct kmem_cache *cachep = arg; |
1da177e4c Linux-2.6.12-rc2 |
2294 |
struct array_cache *ac; |
7d6e6d09d numa: slab: use n... |
2295 |
int node = numa_mem_id(); |
1da177e4c Linux-2.6.12-rc2 |
2296 2297 |
check_irq_off(); |
9a2dba4b4 [PATCH] slab: ren... |
2298 |
ac = cpu_cache_get(cachep); |
6a67368c3 slab: Rename node... |
2299 |
spin_lock(&cachep->node[node]->list_lock); |
ff69416e6 [PATCH] slab: fix... |
2300 |
free_block(cachep, ac->entry, ac->avail, node); |
6a67368c3 slab: Rename node... |
2301 |
spin_unlock(&cachep->node[node]->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
2302 2303 |
ac->avail = 0; } |
343e0d7a9 [PATCH] slab: rep... |
2304 |
static void drain_cpu_caches(struct kmem_cache *cachep) |
1da177e4c Linux-2.6.12-rc2 |
2305 |
{ |
ce8eb6c42 slab: Rename list... |
2306 |
struct kmem_cache_node *n; |
e498be7da [PATCH] Numa-awar... |
2307 |
int node; |
15c8b6c1a on_each_cpu(): ki... |
2308 |
on_each_cpu(do_drain, cachep, 1); |
1da177e4c Linux-2.6.12-rc2 |
2309 |
check_irq_on(); |
b28a02de8 [PATCH] slab: fix... |
2310 |
for_each_online_node(node) { |
ce8eb6c42 slab: Rename list... |
2311 2312 2313 |
n = cachep->node[node]; if (n && n->alien) drain_alien_cache(cachep, n->alien); |
a4523a8b3 [PATCH] slab: Fix... |
2314 2315 2316 |
} for_each_online_node(node) { |
ce8eb6c42 slab: Rename list... |
2317 2318 2319 |
n = cachep->node[node]; if (n) drain_array(cachep, n, n->shared, 1, node); |
e498be7da [PATCH] Numa-awar... |
2320 |
} |
1da177e4c Linux-2.6.12-rc2 |
2321 |
} |
ed11d9eb2 [PATCH] slab: con... |
2322 2323 2324 2325 2326 2327 2328 |
/* * Remove slabs from the list of free slabs. * Specify the number of slabs to drain in tofree. * * Returns the actual number of slabs released. */ static int drain_freelist(struct kmem_cache *cache, |
ce8eb6c42 slab: Rename list... |
2329 |
struct kmem_cache_node *n, int tofree) |
1da177e4c Linux-2.6.12-rc2 |
2330 |
{ |
ed11d9eb2 [PATCH] slab: con... |
2331 2332 |
struct list_head *p; int nr_freed; |
8456a648c slab: use struct ... |
2333 |
struct page *page; |
1da177e4c Linux-2.6.12-rc2 |
2334 |
|
ed11d9eb2 [PATCH] slab: con... |
2335 |
nr_freed = 0; |
ce8eb6c42 slab: Rename list... |
2336 |
while (nr_freed < tofree && !list_empty(&n->slabs_free)) { |
1da177e4c Linux-2.6.12-rc2 |
2337 |
|
ce8eb6c42 slab: Rename list... |
2338 2339 2340 2341 |
spin_lock_irq(&n->list_lock); p = n->slabs_free.prev; if (p == &n->slabs_free) { spin_unlock_irq(&n->list_lock); |
ed11d9eb2 [PATCH] slab: con... |
2342 2343 |
goto out; } |
1da177e4c Linux-2.6.12-rc2 |
2344 |
|
8456a648c slab: use struct ... |
2345 |
page = list_entry(p, struct page, lru); |
1da177e4c Linux-2.6.12-rc2 |
2346 |
#if DEBUG |
8456a648c slab: use struct ... |
2347 |
BUG_ON(page->active); |
1da177e4c Linux-2.6.12-rc2 |
2348 |
#endif |
8456a648c slab: use struct ... |
2349 |
list_del(&page->lru); |
ed11d9eb2 [PATCH] slab: con... |
2350 2351 2352 2353 |
/* * Safe to drop the lock. The slab is no longer linked * to the cache. */ |
ce8eb6c42 slab: Rename list... |
2354 2355 |
n->free_objects -= cache->num; spin_unlock_irq(&n->list_lock); |
8456a648c slab: use struct ... |
2356 |
slab_destroy(cache, page); |
ed11d9eb2 [PATCH] slab: con... |
2357 |
nr_freed++; |
1da177e4c Linux-2.6.12-rc2 |
2358 |
} |
ed11d9eb2 [PATCH] slab: con... |
2359 2360 |
out: return nr_freed; |
1da177e4c Linux-2.6.12-rc2 |
2361 |
} |
18004c5d4 mm, sl[aou]b: Use... |
2362 |
/* Called with slab_mutex held to protect against cpu hotplug */ |
343e0d7a9 [PATCH] slab: rep... |
2363 |
static int __cache_shrink(struct kmem_cache *cachep) |
e498be7da [PATCH] Numa-awar... |
2364 2365 |
{ int ret = 0, i = 0; |
ce8eb6c42 slab: Rename list... |
2366 |
struct kmem_cache_node *n; |
e498be7da [PATCH] Numa-awar... |
2367 2368 2369 2370 2371 |
drain_cpu_caches(cachep); check_irq_on(); for_each_online_node(i) { |
ce8eb6c42 slab: Rename list... |
2372 2373 |
n = cachep->node[i]; if (!n) |
ed11d9eb2 [PATCH] slab: con... |
2374 |
continue; |
0fa8103be mm/slab: Fix drai... |
2375 |
drain_freelist(cachep, n, slabs_tofree(cachep, n)); |
ed11d9eb2 [PATCH] slab: con... |
2376 |
|
ce8eb6c42 slab: Rename list... |
2377 2378 |
ret += !list_empty(&n->slabs_full) || !list_empty(&n->slabs_partial); |
e498be7da [PATCH] Numa-awar... |
2379 2380 2381 |
} return (ret ? 1 : 0); } |
1da177e4c Linux-2.6.12-rc2 |
2382 2383 2384 2385 2386 2387 2388 |
/** * kmem_cache_shrink - Shrink a cache. * @cachep: The cache to shrink. * * Releases as many slabs as possible for a cache. * To help debugging, a zero exit status indicates all slabs were released. */ |
343e0d7a9 [PATCH] slab: rep... |
2389 |
int kmem_cache_shrink(struct kmem_cache *cachep) |
1da177e4c Linux-2.6.12-rc2 |
2390 |
{ |
8f5be20bf [PATCH] mm: slab:... |
2391 |
int ret; |
40094fa65 BUG_ON() Conversi... |
2392 |
BUG_ON(!cachep || in_interrupt()); |
1da177e4c Linux-2.6.12-rc2 |
2393 |
|
95402b382 cpu-hotplug: repl... |
2394 |
get_online_cpus(); |
18004c5d4 mm, sl[aou]b: Use... |
2395 |
mutex_lock(&slab_mutex); |
8f5be20bf [PATCH] mm: slab:... |
2396 |
ret = __cache_shrink(cachep); |
18004c5d4 mm, sl[aou]b: Use... |
2397 |
mutex_unlock(&slab_mutex); |
95402b382 cpu-hotplug: repl... |
2398 |
put_online_cpus(); |
8f5be20bf [PATCH] mm: slab:... |
2399 |
return ret; |
1da177e4c Linux-2.6.12-rc2 |
2400 2401 |
} EXPORT_SYMBOL(kmem_cache_shrink); |
945cf2b61 mm/sl[aou]b: Extr... |
2402 |
int __kmem_cache_shutdown(struct kmem_cache *cachep) |
1da177e4c Linux-2.6.12-rc2 |
2403 |
{ |
12c3667fb mm/sl[aou]b: Get ... |
2404 |
int i; |
ce8eb6c42 slab: Rename list... |
2405 |
struct kmem_cache_node *n; |
12c3667fb mm/sl[aou]b: Get ... |
2406 |
int rc = __cache_shrink(cachep); |
1da177e4c Linux-2.6.12-rc2 |
2407 |
|
12c3667fb mm/sl[aou]b: Get ... |
2408 2409 |
if (rc) return rc; |
1da177e4c Linux-2.6.12-rc2 |
2410 |
|
12c3667fb mm/sl[aou]b: Get ... |
2411 2412 |
for_each_online_cpu(i) kfree(cachep->array[i]); |
1da177e4c Linux-2.6.12-rc2 |
2413 |
|
ce8eb6c42 slab: Rename list... |
2414 |
/* NUMA: free the node structures */ |
12c3667fb mm/sl[aou]b: Get ... |
2415 |
for_each_online_node(i) { |
ce8eb6c42 slab: Rename list... |
2416 2417 2418 2419 2420 |
n = cachep->node[i]; if (n) { kfree(n->shared); free_alien_cache(n->alien); kfree(n); |
12c3667fb mm/sl[aou]b: Get ... |
2421 2422 2423 |
} } return 0; |
1da177e4c Linux-2.6.12-rc2 |
2424 |
} |
1da177e4c Linux-2.6.12-rc2 |
2425 |
|
e5ac9c5ae [PATCH] Add some ... |
2426 2427 |
/* * Get the memory for a slab management obj. |
5f0985bb1 mm/slab.c: cleanu... |
2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 |
* * For a slab cache when the slab descriptor is off-slab, the * slab descriptor can't come from the same cache which is being created, * Because if it is the case, that means we defer the creation of * the kmalloc_{dma,}_cache of size sizeof(slab descriptor) to this point. * And we eventually call down to __kmem_cache_create(), which * in turn looks up in the kmalloc_{dma,}_caches for the disired-size one. * This is a "chicken-and-egg" problem. * * So the off-slab slab descriptor shall come from the kmalloc_{dma,}_caches, * which are all initialized during kmem_cache_init(). |
e5ac9c5ae [PATCH] Add some ... |
2439 |
*/ |
7e0073552 slab: replace non... |
2440 |
static void *alloc_slabmgmt(struct kmem_cache *cachep, |
0c3aa83e0 slab: change retu... |
2441 2442 |
struct page *page, int colour_off, gfp_t local_flags, int nodeid) |
1da177e4c Linux-2.6.12-rc2 |
2443 |
{ |
7e0073552 slab: replace non... |
2444 |
void *freelist; |
0c3aa83e0 slab: change retu... |
2445 |
void *addr = page_address(page); |
b28a02de8 [PATCH] slab: fix... |
2446 |
|
1da177e4c Linux-2.6.12-rc2 |
2447 2448 |
if (OFF_SLAB(cachep)) { /* Slab management obj is off-slab. */ |
8456a648c slab: use struct ... |
2449 |
freelist = kmem_cache_alloc_node(cachep->freelist_cache, |
8759ec50a slab: remove GFP_... |
2450 |
local_flags, nodeid); |
8456a648c slab: use struct ... |
2451 |
if (!freelist) |
1da177e4c Linux-2.6.12-rc2 |
2452 2453 |
return NULL; } else { |
8456a648c slab: use struct ... |
2454 2455 |
freelist = addr + colour_off; colour_off += cachep->freelist_size; |
1da177e4c Linux-2.6.12-rc2 |
2456 |
} |
8456a648c slab: use struct ... |
2457 2458 2459 |
page->active = 0; page->s_mem = addr + colour_off; return freelist; |
1da177e4c Linux-2.6.12-rc2 |
2460 |
} |
a41adfaa2 slab: introduce b... |
2461 |
static inline freelist_idx_t get_free_obj(struct page *page, unsigned char idx) |
1da177e4c Linux-2.6.12-rc2 |
2462 |
{ |
a41adfaa2 slab: introduce b... |
2463 |
return ((freelist_idx_t *)page->freelist)[idx]; |
e5c58dfdc slab: introduce h... |
2464 2465 2466 |
} static inline void set_free_obj(struct page *page, |
a41adfaa2 slab: introduce b... |
2467 |
unsigned char idx, freelist_idx_t val) |
e5c58dfdc slab: introduce h... |
2468 |
{ |
a41adfaa2 slab: introduce b... |
2469 |
((freelist_idx_t *)(page->freelist))[idx] = val; |
1da177e4c Linux-2.6.12-rc2 |
2470 |
} |
343e0d7a9 [PATCH] slab: rep... |
2471 |
static void cache_init_objs(struct kmem_cache *cachep, |
8456a648c slab: use struct ... |
2472 |
struct page *page) |
1da177e4c Linux-2.6.12-rc2 |
2473 2474 2475 2476 |
{ int i; for (i = 0; i < cachep->num; i++) { |
8456a648c slab: use struct ... |
2477 |
void *objp = index_to_obj(cachep, page, i); |
1da177e4c Linux-2.6.12-rc2 |
2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 |
#if DEBUG /* need to poison the objs? */ if (cachep->flags & SLAB_POISON) poison_obj(cachep, objp, POISON_FREE); if (cachep->flags & SLAB_STORE_USER) *dbg_userword(cachep, objp) = NULL; if (cachep->flags & SLAB_RED_ZONE) { *dbg_redzone1(cachep, objp) = RED_INACTIVE; *dbg_redzone2(cachep, objp) = RED_INACTIVE; } /* |
a737b3e2f [PATCH] slab cleanup |
2490 2491 2492 |
* Constructors are not allowed to allocate memory from the same * cache which they are a constructor for. Otherwise, deadlock. * They must also be threaded. |
1da177e4c Linux-2.6.12-rc2 |
2493 2494 |
*/ if (cachep->ctor && !(cachep->flags & SLAB_POISON)) |
51cc50685 SL*B: drop kmem c... |
2495 |
cachep->ctor(objp + obj_offset(cachep)); |
1da177e4c Linux-2.6.12-rc2 |
2496 2497 2498 2499 |
if (cachep->flags & SLAB_RED_ZONE) { if (*dbg_redzone2(cachep, objp) != RED_INACTIVE) slab_error(cachep, "constructor overwrote the" |
b28a02de8 [PATCH] slab: fix... |
2500 |
" end of an object"); |
1da177e4c Linux-2.6.12-rc2 |
2501 2502 |
if (*dbg_redzone1(cachep, objp) != RED_INACTIVE) slab_error(cachep, "constructor overwrote the" |
b28a02de8 [PATCH] slab: fix... |
2503 |
" start of an object"); |
1da177e4c Linux-2.6.12-rc2 |
2504 |
} |
3b0efdfa1 mm, sl[aou]b: Ext... |
2505 |
if ((cachep->size % PAGE_SIZE) == 0 && |
a737b3e2f [PATCH] slab cleanup |
2506 |
OFF_SLAB(cachep) && cachep->flags & SLAB_POISON) |
b28a02de8 [PATCH] slab: fix... |
2507 |
kernel_map_pages(virt_to_page(objp), |
3b0efdfa1 mm, sl[aou]b: Ext... |
2508 |
cachep->size / PAGE_SIZE, 0); |
1da177e4c Linux-2.6.12-rc2 |
2509 2510 |
#else if (cachep->ctor) |
51cc50685 SL*B: drop kmem c... |
2511 |
cachep->ctor(objp); |
1da177e4c Linux-2.6.12-rc2 |
2512 |
#endif |
e5c58dfdc slab: introduce h... |
2513 |
set_free_obj(page, i, i); |
1da177e4c Linux-2.6.12-rc2 |
2514 |
} |
1da177e4c Linux-2.6.12-rc2 |
2515 |
} |
343e0d7a9 [PATCH] slab: rep... |
2516 |
static void kmem_flagcheck(struct kmem_cache *cachep, gfp_t flags) |
1da177e4c Linux-2.6.12-rc2 |
2517 |
{ |
4b51d6698 [PATCH] optional ... |
2518 2519 |
if (CONFIG_ZONE_DMA_FLAG) { if (flags & GFP_DMA) |
a618e89f1 slab: rename gfpf... |
2520 |
BUG_ON(!(cachep->allocflags & GFP_DMA)); |
4b51d6698 [PATCH] optional ... |
2521 |
else |
a618e89f1 slab: rename gfpf... |
2522 |
BUG_ON(cachep->allocflags & GFP_DMA); |
4b51d6698 [PATCH] optional ... |
2523 |
} |
1da177e4c Linux-2.6.12-rc2 |
2524 |
} |
8456a648c slab: use struct ... |
2525 |
static void *slab_get_obj(struct kmem_cache *cachep, struct page *page, |
a737b3e2f [PATCH] slab cleanup |
2526 |
int nodeid) |
78d382d77 [PATCH] slab: ext... |
2527 |
{ |
b1cb0982b slab: change the ... |
2528 |
void *objp; |
78d382d77 [PATCH] slab: ext... |
2529 |
|
e5c58dfdc slab: introduce h... |
2530 |
objp = index_to_obj(cachep, page, get_free_obj(page, page->active)); |
8456a648c slab: use struct ... |
2531 |
page->active++; |
78d382d77 [PATCH] slab: ext... |
2532 |
#if DEBUG |
1ea991b00 slab: remove node... |
2533 |
WARN_ON(page_to_nid(virt_to_page(objp)) != nodeid); |
78d382d77 [PATCH] slab: ext... |
2534 |
#endif |
78d382d77 [PATCH] slab: ext... |
2535 2536 2537 |
return objp; } |
8456a648c slab: use struct ... |
2538 |
static void slab_put_obj(struct kmem_cache *cachep, struct page *page, |
a737b3e2f [PATCH] slab cleanup |
2539 |
void *objp, int nodeid) |
78d382d77 [PATCH] slab: ext... |
2540 |
{ |
8456a648c slab: use struct ... |
2541 |
unsigned int objnr = obj_to_index(cachep, page, objp); |
78d382d77 [PATCH] slab: ext... |
2542 |
#if DEBUG |
16025177e slab: remove kmem... |
2543 |
unsigned int i; |
b1cb0982b slab: change the ... |
2544 |
|
78d382d77 [PATCH] slab: ext... |
2545 |
/* Verify that the slab belongs to the intended node */ |
1ea991b00 slab: remove node... |
2546 |
WARN_ON(page_to_nid(virt_to_page(objp)) != nodeid); |
78d382d77 [PATCH] slab: ext... |
2547 |
|
b1cb0982b slab: change the ... |
2548 |
/* Verify double free bug */ |
8456a648c slab: use struct ... |
2549 |
for (i = page->active; i < cachep->num; i++) { |
e5c58dfdc slab: introduce h... |
2550 |
if (get_free_obj(page, i) == objnr) { |
b1cb0982b slab: change the ... |
2551 2552 2553 2554 2555 |
printk(KERN_ERR "slab: double free detected in cache " "'%s', objp %p ", cachep->name, objp); BUG(); } |
78d382d77 [PATCH] slab: ext... |
2556 2557 |
} #endif |
8456a648c slab: use struct ... |
2558 |
page->active--; |
e5c58dfdc slab: introduce h... |
2559 |
set_free_obj(page, page->active, objnr); |
78d382d77 [PATCH] slab: ext... |
2560 |
} |
4776874ff [PATCH] slab: pag... |
2561 2562 2563 |
/* * Map pages beginning at addr to the given cache and slab. This is required * for the slab allocator to be able to lookup the cache and slab of a |
ccd35fb9f kernel: kmem_ptr_... |
2564 |
* virtual address for kfree, ksize, and slab debugging. |
4776874ff [PATCH] slab: pag... |
2565 |
*/ |
8456a648c slab: use struct ... |
2566 |
static void slab_map_pages(struct kmem_cache *cache, struct page *page, |
7e0073552 slab: replace non... |
2567 |
void *freelist) |
1da177e4c Linux-2.6.12-rc2 |
2568 |
{ |
a57a49887 slab: use __GFP_C... |
2569 |
page->slab_cache = cache; |
8456a648c slab: use struct ... |
2570 |
page->freelist = freelist; |
1da177e4c Linux-2.6.12-rc2 |
2571 2572 2573 2574 2575 2576 |
} /* * Grow (by 1) the number of slabs within a cache. This is called by * kmem_cache_alloc() when there are no active objs left in a cache. */ |
3c517a613 [PATCH] slab: bet... |
2577 |
static int cache_grow(struct kmem_cache *cachep, |
0c3aa83e0 slab: change retu... |
2578 |
gfp_t flags, int nodeid, struct page *page) |
1da177e4c Linux-2.6.12-rc2 |
2579 |
{ |
7e0073552 slab: replace non... |
2580 |
void *freelist; |
b28a02de8 [PATCH] slab: fix... |
2581 2582 |
size_t offset; gfp_t local_flags; |
ce8eb6c42 slab: Rename list... |
2583 |
struct kmem_cache_node *n; |
1da177e4c Linux-2.6.12-rc2 |
2584 |
|
a737b3e2f [PATCH] slab cleanup |
2585 2586 2587 |
/* * Be lazy and only check for valid flags here, keeping it out of the * critical path in kmem_cache_alloc(). |
1da177e4c Linux-2.6.12-rc2 |
2588 |
*/ |
6cb062296 Categorize GFP flags |
2589 2590 |
BUG_ON(flags & GFP_SLAB_BUG_MASK); local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK); |
1da177e4c Linux-2.6.12-rc2 |
2591 |
|
ce8eb6c42 slab: Rename list... |
2592 |
/* Take the node list lock to change the colour_next on this node */ |
1da177e4c Linux-2.6.12-rc2 |
2593 |
check_irq_off(); |
ce8eb6c42 slab: Rename list... |
2594 2595 |
n = cachep->node[nodeid]; spin_lock(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
2596 2597 |
/* Get colour for the slab, and cal the next value. */ |
ce8eb6c42 slab: Rename list... |
2598 2599 2600 2601 2602 |
offset = n->colour_next; n->colour_next++; if (n->colour_next >= cachep->colour) n->colour_next = 0; spin_unlock(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
2603 |
|
2e1217cf9 [PATCH] NUMA slab... |
2604 |
offset *= cachep->colour_off; |
1da177e4c Linux-2.6.12-rc2 |
2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 |
if (local_flags & __GFP_WAIT) local_irq_enable(); /* * The test for missing atomic flag is performed here, rather than * the more obvious place, simply to reduce the critical path length * in kmem_cache_alloc(). If a caller is seriously mis-behaving they * will eventually be caught here (where it matters). */ kmem_flagcheck(cachep, flags); |
a737b3e2f [PATCH] slab cleanup |
2616 2617 2618 |
/* * Get mem for the objs. Attempt to allocate a physical page from * 'nodeid'. |
e498be7da [PATCH] Numa-awar... |
2619 |
*/ |
0c3aa83e0 slab: change retu... |
2620 2621 2622 |
if (!page) page = kmem_getpages(cachep, local_flags, nodeid); if (!page) |
1da177e4c Linux-2.6.12-rc2 |
2623 2624 2625 |
goto failed; /* Get slab management. */ |
8456a648c slab: use struct ... |
2626 |
freelist = alloc_slabmgmt(cachep, page, offset, |
6cb062296 Categorize GFP flags |
2627 |
local_flags & ~GFP_CONSTRAINT_MASK, nodeid); |
8456a648c slab: use struct ... |
2628 |
if (!freelist) |
1da177e4c Linux-2.6.12-rc2 |
2629 |
goto opps1; |
8456a648c slab: use struct ... |
2630 |
slab_map_pages(cachep, page, freelist); |
1da177e4c Linux-2.6.12-rc2 |
2631 |
|
8456a648c slab: use struct ... |
2632 |
cache_init_objs(cachep, page); |
1da177e4c Linux-2.6.12-rc2 |
2633 2634 2635 2636 |
if (local_flags & __GFP_WAIT) local_irq_disable(); check_irq_off(); |
ce8eb6c42 slab: Rename list... |
2637 |
spin_lock(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
2638 2639 |
/* Make slab active. */ |
8456a648c slab: use struct ... |
2640 |
list_add_tail(&page->lru, &(n->slabs_free)); |
1da177e4c Linux-2.6.12-rc2 |
2641 |
STATS_INC_GROWN(cachep); |
ce8eb6c42 slab: Rename list... |
2642 2643 |
n->free_objects += cachep->num; spin_unlock(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
2644 |
return 1; |
a737b3e2f [PATCH] slab cleanup |
2645 |
opps1: |
0c3aa83e0 slab: change retu... |
2646 |
kmem_freepages(cachep, page); |
a737b3e2f [PATCH] slab cleanup |
2647 |
failed: |
1da177e4c Linux-2.6.12-rc2 |
2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 |
if (local_flags & __GFP_WAIT) local_irq_disable(); return 0; } #if DEBUG /* * Perform extra freeing checks: * - detect bad pointers. * - POISON/RED_ZONE checking |
1da177e4c Linux-2.6.12-rc2 |
2659 2660 2661 |
*/ static void kfree_debugcheck(const void *objp) { |
1da177e4c Linux-2.6.12-rc2 |
2662 2663 2664 |
if (!virt_addr_valid(objp)) { printk(KERN_ERR "kfree_debugcheck: out of range ptr %lxh. ", |
b28a02de8 [PATCH] slab: fix... |
2665 2666 |
(unsigned long)objp); BUG(); |
1da177e4c Linux-2.6.12-rc2 |
2667 |
} |
1da177e4c Linux-2.6.12-rc2 |
2668 |
} |
58ce1fd58 [PATCH] slab: red... |
2669 2670 |
static inline void verify_redzone_free(struct kmem_cache *cache, void *obj) { |
b46b8f19c Increase slab red... |
2671 |
unsigned long long redzone1, redzone2; |
58ce1fd58 [PATCH] slab: red... |
2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 |
redzone1 = *dbg_redzone1(cache, obj); redzone2 = *dbg_redzone2(cache, obj); /* * Redzone is ok. */ if (redzone1 == RED_ACTIVE && redzone2 == RED_ACTIVE) return; if (redzone1 == RED_INACTIVE && redzone2 == RED_INACTIVE) slab_error(cache, "double free detected"); else slab_error(cache, "memory outside object was overwritten"); |
b46b8f19c Increase slab red... |
2686 2687 |
printk(KERN_ERR "%p: redzone 1:0x%llx, redzone 2:0x%llx. ", |
58ce1fd58 [PATCH] slab: red... |
2688 2689 |
obj, redzone1, redzone2); } |
343e0d7a9 [PATCH] slab: rep... |
2690 |
static void *cache_free_debugcheck(struct kmem_cache *cachep, void *objp, |
7c0cb9c64 mm, slab: Replace... |
2691 |
unsigned long caller) |
1da177e4c Linux-2.6.12-rc2 |
2692 |
{ |
1da177e4c Linux-2.6.12-rc2 |
2693 |
unsigned int objnr; |
8456a648c slab: use struct ... |
2694 |
struct page *page; |
1da177e4c Linux-2.6.12-rc2 |
2695 |
|
80cbd911c Fix kmem_cache_fr... |
2696 |
BUG_ON(virt_to_cache(objp) != cachep); |
3dafccf22 [PATCH] slab: dis... |
2697 |
objp -= obj_offset(cachep); |
1da177e4c Linux-2.6.12-rc2 |
2698 |
kfree_debugcheck(objp); |
b49af68ff Add virt_to_head_... |
2699 |
page = virt_to_head_page(objp); |
1da177e4c Linux-2.6.12-rc2 |
2700 |
|
1da177e4c Linux-2.6.12-rc2 |
2701 |
if (cachep->flags & SLAB_RED_ZONE) { |
58ce1fd58 [PATCH] slab: red... |
2702 |
verify_redzone_free(cachep, objp); |
1da177e4c Linux-2.6.12-rc2 |
2703 2704 2705 2706 |
*dbg_redzone1(cachep, objp) = RED_INACTIVE; *dbg_redzone2(cachep, objp) = RED_INACTIVE; } if (cachep->flags & SLAB_STORE_USER) |
7c0cb9c64 mm, slab: Replace... |
2707 |
*dbg_userword(cachep, objp) = (void *)caller; |
1da177e4c Linux-2.6.12-rc2 |
2708 |
|
8456a648c slab: use struct ... |
2709 |
objnr = obj_to_index(cachep, page, objp); |
1da177e4c Linux-2.6.12-rc2 |
2710 2711 |
BUG_ON(objnr >= cachep->num); |
8456a648c slab: use struct ... |
2712 |
BUG_ON(objp != index_to_obj(cachep, page, objnr)); |
1da177e4c Linux-2.6.12-rc2 |
2713 |
|
1da177e4c Linux-2.6.12-rc2 |
2714 2715 |
if (cachep->flags & SLAB_POISON) { #ifdef CONFIG_DEBUG_PAGEALLOC |
3b0efdfa1 mm, sl[aou]b: Ext... |
2716 |
if ((cachep->size % PAGE_SIZE)==0 && OFF_SLAB(cachep)) { |
7c0cb9c64 mm, slab: Replace... |
2717 |
store_stackinfo(cachep, objp, caller); |
b28a02de8 [PATCH] slab: fix... |
2718 |
kernel_map_pages(virt_to_page(objp), |
3b0efdfa1 mm, sl[aou]b: Ext... |
2719 |
cachep->size / PAGE_SIZE, 0); |
1da177e4c Linux-2.6.12-rc2 |
2720 2721 2722 2723 2724 2725 2726 2727 2728 |
} else { poison_obj(cachep, objp, POISON_FREE); } #else poison_obj(cachep, objp, POISON_FREE); #endif } return objp; } |
1da177e4c Linux-2.6.12-rc2 |
2729 2730 2731 |
#else #define kfree_debugcheck(x) do { } while(0) #define cache_free_debugcheck(x,objp,z) (objp) |
1da177e4c Linux-2.6.12-rc2 |
2732 |
#endif |
072bb0aa5 mm: sl[au]b: add ... |
2733 2734 |
static void *cache_alloc_refill(struct kmem_cache *cachep, gfp_t flags, bool force_refill) |
1da177e4c Linux-2.6.12-rc2 |
2735 2736 |
{ int batchcount; |
ce8eb6c42 slab: Rename list... |
2737 |
struct kmem_cache_node *n; |
1da177e4c Linux-2.6.12-rc2 |
2738 |
struct array_cache *ac; |
1ca4cb241 [PATCH] slab: red... |
2739 |
int node; |
1da177e4c Linux-2.6.12-rc2 |
2740 |
check_irq_off(); |
7d6e6d09d numa: slab: use n... |
2741 |
node = numa_mem_id(); |
072bb0aa5 mm: sl[au]b: add ... |
2742 2743 2744 |
if (unlikely(force_refill)) goto force_grow; retry: |
9a2dba4b4 [PATCH] slab: ren... |
2745 |
ac = cpu_cache_get(cachep); |
1da177e4c Linux-2.6.12-rc2 |
2746 2747 |
batchcount = ac->batchcount; if (!ac->touched && batchcount > BATCHREFILL_LIMIT) { |
a737b3e2f [PATCH] slab cleanup |
2748 2749 2750 2751 |
/* * If there was little recent activity on this cache, then * perform only a partial refill. Otherwise we could generate * refill bouncing. |
1da177e4c Linux-2.6.12-rc2 |
2752 2753 2754 |
*/ batchcount = BATCHREFILL_LIMIT; } |
ce8eb6c42 slab: Rename list... |
2755 |
n = cachep->node[node]; |
e498be7da [PATCH] Numa-awar... |
2756 |
|
ce8eb6c42 slab: Rename list... |
2757 2758 |
BUG_ON(ac->avail > 0 || !n); spin_lock(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
2759 |
|
3ded175a4 [PATCH] slab: add... |
2760 |
/* See if we can refill from the shared array */ |
ce8eb6c42 slab: Rename list... |
2761 2762 |
if (n->shared && transfer_objects(ac, n->shared, batchcount)) { n->shared->touched = 1; |
3ded175a4 [PATCH] slab: add... |
2763 |
goto alloc_done; |
44b57f1cc slab: fix regress... |
2764 |
} |
3ded175a4 [PATCH] slab: add... |
2765 |
|
1da177e4c Linux-2.6.12-rc2 |
2766 2767 |
while (batchcount > 0) { struct list_head *entry; |
8456a648c slab: use struct ... |
2768 |
struct page *page; |
1da177e4c Linux-2.6.12-rc2 |
2769 |
/* Get slab alloc is to come from. */ |
ce8eb6c42 slab: Rename list... |
2770 2771 2772 2773 2774 |
entry = n->slabs_partial.next; if (entry == &n->slabs_partial) { n->free_touched = 1; entry = n->slabs_free.next; if (entry == &n->slabs_free) |
1da177e4c Linux-2.6.12-rc2 |
2775 2776 |
goto must_grow; } |
8456a648c slab: use struct ... |
2777 |
page = list_entry(entry, struct page, lru); |
1da177e4c Linux-2.6.12-rc2 |
2778 |
check_spinlock_acquired(cachep); |
714b8171a slab: ensure cach... |
2779 2780 2781 2782 2783 2784 |
/* * The slab was either on partial or free list so * there must be at least one object available for * allocation. */ |
8456a648c slab: use struct ... |
2785 |
BUG_ON(page->active >= cachep->num); |
714b8171a slab: ensure cach... |
2786 |
|
8456a648c slab: use struct ... |
2787 |
while (page->active < cachep->num && batchcount--) { |
1da177e4c Linux-2.6.12-rc2 |
2788 2789 2790 |
STATS_INC_ALLOCED(cachep); STATS_INC_ACTIVE(cachep); STATS_SET_HIGH(cachep); |
8456a648c slab: use struct ... |
2791 |
ac_put_obj(cachep, ac, slab_get_obj(cachep, page, |
072bb0aa5 mm: sl[au]b: add ... |
2792 |
node)); |
1da177e4c Linux-2.6.12-rc2 |
2793 |
} |
1da177e4c Linux-2.6.12-rc2 |
2794 2795 |
/* move slabp to correct slabp list: */ |
8456a648c slab: use struct ... |
2796 2797 |
list_del(&page->lru); if (page->active == cachep->num) |
34bf6ef94 mm: slab/slub: us... |
2798 |
list_add(&page->lru, &n->slabs_full); |
1da177e4c Linux-2.6.12-rc2 |
2799 |
else |
34bf6ef94 mm: slab/slub: us... |
2800 |
list_add(&page->lru, &n->slabs_partial); |
1da177e4c Linux-2.6.12-rc2 |
2801 |
} |
a737b3e2f [PATCH] slab cleanup |
2802 |
must_grow: |
ce8eb6c42 slab: Rename list... |
2803 |
n->free_objects -= ac->avail; |
a737b3e2f [PATCH] slab cleanup |
2804 |
alloc_done: |
ce8eb6c42 slab: Rename list... |
2805 |
spin_unlock(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
2806 2807 2808 |
if (unlikely(!ac->avail)) { int x; |
072bb0aa5 mm: sl[au]b: add ... |
2809 |
force_grow: |
3c517a613 [PATCH] slab: bet... |
2810 |
x = cache_grow(cachep, flags | GFP_THISNODE, node, NULL); |
e498be7da [PATCH] Numa-awar... |
2811 |
|
a737b3e2f [PATCH] slab cleanup |
2812 |
/* cache_grow can reenable interrupts, then ac could change. */ |
9a2dba4b4 [PATCH] slab: ren... |
2813 |
ac = cpu_cache_get(cachep); |
51cd8e6ff mm, slab: lock th... |
2814 |
node = numa_mem_id(); |
072bb0aa5 mm: sl[au]b: add ... |
2815 2816 2817 |
/* no objects in sight? abort */ if (!x && (ac->avail == 0 || force_refill)) |
1da177e4c Linux-2.6.12-rc2 |
2818 |
return NULL; |
a737b3e2f [PATCH] slab cleanup |
2819 |
if (!ac->avail) /* objects refilled by interrupt? */ |
1da177e4c Linux-2.6.12-rc2 |
2820 2821 2822 |
goto retry; } ac->touched = 1; |
072bb0aa5 mm: sl[au]b: add ... |
2823 2824 |
return ac_get_obj(cachep, ac, flags, force_refill); |
1da177e4c Linux-2.6.12-rc2 |
2825 |
} |
a737b3e2f [PATCH] slab cleanup |
2826 2827 |
static inline void cache_alloc_debugcheck_before(struct kmem_cache *cachep, gfp_t flags) |
1da177e4c Linux-2.6.12-rc2 |
2828 2829 2830 2831 2832 2833 2834 2835 |
{ might_sleep_if(flags & __GFP_WAIT); #if DEBUG kmem_flagcheck(cachep, flags); #endif } #if DEBUG |
a737b3e2f [PATCH] slab cleanup |
2836 |
static void *cache_alloc_debugcheck_after(struct kmem_cache *cachep, |
7c0cb9c64 mm, slab: Replace... |
2837 |
gfp_t flags, void *objp, unsigned long caller) |
1da177e4c Linux-2.6.12-rc2 |
2838 |
{ |
b28a02de8 [PATCH] slab: fix... |
2839 |
if (!objp) |
1da177e4c Linux-2.6.12-rc2 |
2840 |
return objp; |
b28a02de8 [PATCH] slab: fix... |
2841 |
if (cachep->flags & SLAB_POISON) { |
1da177e4c Linux-2.6.12-rc2 |
2842 |
#ifdef CONFIG_DEBUG_PAGEALLOC |
3b0efdfa1 mm, sl[aou]b: Ext... |
2843 |
if ((cachep->size % PAGE_SIZE) == 0 && OFF_SLAB(cachep)) |
b28a02de8 [PATCH] slab: fix... |
2844 |
kernel_map_pages(virt_to_page(objp), |
3b0efdfa1 mm, sl[aou]b: Ext... |
2845 |
cachep->size / PAGE_SIZE, 1); |
1da177e4c Linux-2.6.12-rc2 |
2846 2847 2848 2849 2850 2851 2852 2853 |
else check_poison_obj(cachep, objp); #else check_poison_obj(cachep, objp); #endif poison_obj(cachep, objp, POISON_INUSE); } if (cachep->flags & SLAB_STORE_USER) |
7c0cb9c64 mm, slab: Replace... |
2854 |
*dbg_userword(cachep, objp) = (void *)caller; |
1da177e4c Linux-2.6.12-rc2 |
2855 2856 |
if (cachep->flags & SLAB_RED_ZONE) { |
a737b3e2f [PATCH] slab cleanup |
2857 2858 2859 2860 |
if (*dbg_redzone1(cachep, objp) != RED_INACTIVE || *dbg_redzone2(cachep, objp) != RED_INACTIVE) { slab_error(cachep, "double free, or memory outside" " object was overwritten"); |
b28a02de8 [PATCH] slab: fix... |
2861 |
printk(KERN_ERR |
b46b8f19c Increase slab red... |
2862 2863 |
"%p: redzone 1:0x%llx, redzone 2:0x%llx ", |
a737b3e2f [PATCH] slab cleanup |
2864 2865 |
objp, *dbg_redzone1(cachep, objp), *dbg_redzone2(cachep, objp)); |
1da177e4c Linux-2.6.12-rc2 |
2866 2867 2868 2869 |
} *dbg_redzone1(cachep, objp) = RED_ACTIVE; *dbg_redzone2(cachep, objp) = RED_ACTIVE; } |
3dafccf22 [PATCH] slab: dis... |
2870 |
objp += obj_offset(cachep); |
4f1049345 slab allocators: ... |
2871 |
if (cachep->ctor && cachep->flags & SLAB_POISON) |
51cc50685 SL*B: drop kmem c... |
2872 |
cachep->ctor(objp); |
7ea466f22 slab: fix DEBUG_S... |
2873 2874 |
if (ARCH_SLAB_MINALIGN && ((unsigned long)objp & (ARCH_SLAB_MINALIGN-1))) { |
a44b56d35 [PATCH] slab debu... |
2875 2876 |
printk(KERN_ERR "0x%p: not aligned to ARCH_SLAB_MINALIGN=%d ", |
c225150b8 slab: fix DEBUG_S... |
2877 |
objp, (int)ARCH_SLAB_MINALIGN); |
a44b56d35 [PATCH] slab debu... |
2878 |
} |
1da177e4c Linux-2.6.12-rc2 |
2879 2880 2881 2882 2883 |
return objp; } #else #define cache_alloc_debugcheck_after(a,b,objp,d) (objp) #endif |
773ff60e8 SLUB: failslab su... |
2884 |
static bool slab_should_failslab(struct kmem_cache *cachep, gfp_t flags) |
8a8b6502f [PATCH] fault-inj... |
2885 |
{ |
9b030cb86 mm/sl[aou]b: Use ... |
2886 |
if (cachep == kmem_cache) |
773ff60e8 SLUB: failslab su... |
2887 |
return false; |
8a8b6502f [PATCH] fault-inj... |
2888 |
|
8c138bc00 slab: Get rid of ... |
2889 |
return should_failslab(cachep->object_size, flags, cachep->flags); |
8a8b6502f [PATCH] fault-inj... |
2890 |
} |
343e0d7a9 [PATCH] slab: rep... |
2891 |
static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags) |
1da177e4c Linux-2.6.12-rc2 |
2892 |
{ |
b28a02de8 [PATCH] slab: fix... |
2893 |
void *objp; |
1da177e4c Linux-2.6.12-rc2 |
2894 |
struct array_cache *ac; |
072bb0aa5 mm: sl[au]b: add ... |
2895 |
bool force_refill = false; |
1da177e4c Linux-2.6.12-rc2 |
2896 |
|
5c3823008 [PATCH] kmalloc_n... |
2897 |
check_irq_off(); |
8a8b6502f [PATCH] fault-inj... |
2898 |
|
9a2dba4b4 [PATCH] slab: ren... |
2899 |
ac = cpu_cache_get(cachep); |
1da177e4c Linux-2.6.12-rc2 |
2900 |
if (likely(ac->avail)) { |
1da177e4c Linux-2.6.12-rc2 |
2901 |
ac->touched = 1; |
072bb0aa5 mm: sl[au]b: add ... |
2902 |
objp = ac_get_obj(cachep, ac, flags, false); |
ddbf2e836 slab, kmemleak: p... |
2903 |
/* |
072bb0aa5 mm: sl[au]b: add ... |
2904 2905 |
* Allow for the possibility all avail objects are not allowed * by the current flags |
ddbf2e836 slab, kmemleak: p... |
2906 |
*/ |
072bb0aa5 mm: sl[au]b: add ... |
2907 2908 2909 2910 2911 |
if (objp) { STATS_INC_ALLOCHIT(cachep); goto out; } force_refill = true; |
1da177e4c Linux-2.6.12-rc2 |
2912 |
} |
072bb0aa5 mm: sl[au]b: add ... |
2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 |
STATS_INC_ALLOCMISS(cachep); objp = cache_alloc_refill(cachep, flags, force_refill); /* * the 'ac' may be updated by cache_alloc_refill(), * and kmemleak_erase() requires its correct value. */ ac = cpu_cache_get(cachep); out: |
d5cff6352 kmemleak: Add the... |
2923 2924 2925 2926 2927 |
/* * To avoid a false negative, if an object that is in one of the * per-CPU caches is leaked, we need to make sure kmemleak doesn't * treat the array pointers as a reference to the object. */ |
f3d8b53a3 slab, kmemleak: s... |
2928 2929 |
if (objp) kmemleak_erase(&ac->entry[ac->avail]); |
5c3823008 [PATCH] kmalloc_n... |
2930 2931 |
return objp; } |
e498be7da [PATCH] Numa-awar... |
2932 2933 |
#ifdef CONFIG_NUMA /* |
f0432d159 mm, mempolicy: re... |
2934 |
* Try allocating on another node if PF_SPREAD_SLAB is a mempolicy is set. |
c61afb181 [PATCH] cpuset me... |
2935 2936 2937 2938 2939 2940 2941 |
* * If we are in_interrupt, then process context, including cpusets and * mempolicy, may not apply and should not be used for allocation policy. */ static void *alternate_node_alloc(struct kmem_cache *cachep, gfp_t flags) { int nid_alloc, nid_here; |
765c4507a [PATCH] GFP_THISN... |
2942 |
if (in_interrupt() || (flags & __GFP_THISNODE)) |
c61afb181 [PATCH] cpuset me... |
2943 |
return NULL; |
7d6e6d09d numa: slab: use n... |
2944 |
nid_alloc = nid_here = numa_mem_id(); |
c61afb181 [PATCH] cpuset me... |
2945 |
if (cpuset_do_slab_mem_spread() && (cachep->flags & SLAB_MEM_SPREAD)) |
6adef3ebe cpusets: new roun... |
2946 |
nid_alloc = cpuset_slab_spread_node(); |
c61afb181 [PATCH] cpuset me... |
2947 |
else if (current->mempolicy) |
2a389610a mm, mempolicy: re... |
2948 |
nid_alloc = mempolicy_slab_node(); |
c61afb181 [PATCH] cpuset me... |
2949 |
if (nid_alloc != nid_here) |
8b98c1699 [PATCH] leak trac... |
2950 |
return ____cache_alloc_node(cachep, flags, nid_alloc); |
c61afb181 [PATCH] cpuset me... |
2951 2952 2953 2954 |
return NULL; } /* |
765c4507a [PATCH] GFP_THISN... |
2955 |
* Fallback function if there was no memory available and no objects on a |
3c517a613 [PATCH] slab: bet... |
2956 |
* certain node and fall back is permitted. First we scan all the |
6a67368c3 slab: Rename node... |
2957 |
* available node for available objects. If that fails then we |
3c517a613 [PATCH] slab: bet... |
2958 2959 2960 |
* perform an allocation without specifying a node. This allows the page * allocator to do its reclaim / fallback magic. We then insert the * slab into the proper nodelist and then allocate from it. |
765c4507a [PATCH] GFP_THISN... |
2961 |
*/ |
8c8cc2c10 [PATCH] slab: cac... |
2962 |
static void *fallback_alloc(struct kmem_cache *cache, gfp_t flags) |
765c4507a [PATCH] GFP_THISN... |
2963 |
{ |
8c8cc2c10 [PATCH] slab: cac... |
2964 2965 |
struct zonelist *zonelist; gfp_t local_flags; |
dd1a239f6 mm: have zonelist... |
2966 |
struct zoneref *z; |
54a6eb5c4 mm: use two zonel... |
2967 2968 |
struct zone *zone; enum zone_type high_zoneidx = gfp_zone(flags); |
765c4507a [PATCH] GFP_THISN... |
2969 |
void *obj = NULL; |
3c517a613 [PATCH] slab: bet... |
2970 |
int nid; |
cc9a6c877 cpuset: mm: reduc... |
2971 |
unsigned int cpuset_mems_cookie; |
8c8cc2c10 [PATCH] slab: cac... |
2972 2973 2974 |
if (flags & __GFP_THISNODE) return NULL; |
6cb062296 Categorize GFP flags |
2975 |
local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK); |
765c4507a [PATCH] GFP_THISN... |
2976 |
|
cc9a6c877 cpuset: mm: reduc... |
2977 |
retry_cpuset: |
d26914d11 mm: optimize put_... |
2978 |
cpuset_mems_cookie = read_mems_allowed_begin(); |
2a389610a mm, mempolicy: re... |
2979 |
zonelist = node_zonelist(mempolicy_slab_node(), flags); |
cc9a6c877 cpuset: mm: reduc... |
2980 |
|
3c517a613 [PATCH] slab: bet... |
2981 2982 2983 2984 2985 |
retry: /* * Look through allowed nodes for objects available * from existing per node queues. */ |
54a6eb5c4 mm: use two zonel... |
2986 2987 |
for_each_zone_zonelist(zone, z, zonelist, high_zoneidx) { nid = zone_to_nid(zone); |
aedb0eb10 [PATCH] Slab: Do ... |
2988 |
|
54a6eb5c4 mm: use two zonel... |
2989 |
if (cpuset_zone_allowed_hardwall(zone, flags) && |
6a67368c3 slab: Rename node... |
2990 2991 |
cache->node[nid] && cache->node[nid]->free_objects) { |
3c517a613 [PATCH] slab: bet... |
2992 2993 |
obj = ____cache_alloc_node(cache, flags | GFP_THISNODE, nid); |
481c5346d Slab: Fix memory ... |
2994 2995 2996 |
if (obj) break; } |
3c517a613 [PATCH] slab: bet... |
2997 |
} |
cfce66047 Slab allocators: ... |
2998 |
if (!obj) { |
3c517a613 [PATCH] slab: bet... |
2999 3000 3001 3002 3003 3004 |
/* * This allocation will be performed within the constraints * of the current cpuset / memory policy requirements. * We may trigger various forms of reclaim on the allowed * set and go into memory reserves if necessary. */ |
0c3aa83e0 slab: change retu... |
3005 |
struct page *page; |
dd47ea755 [PATCH] slab: fix... |
3006 3007 3008 |
if (local_flags & __GFP_WAIT) local_irq_enable(); kmem_flagcheck(cache, flags); |
0c3aa83e0 slab: change retu... |
3009 |
page = kmem_getpages(cache, local_flags, numa_mem_id()); |
dd47ea755 [PATCH] slab: fix... |
3010 3011 |
if (local_flags & __GFP_WAIT) local_irq_disable(); |
0c3aa83e0 slab: change retu... |
3012 |
if (page) { |
3c517a613 [PATCH] slab: bet... |
3013 3014 3015 |
/* * Insert into the appropriate per node queues */ |
0c3aa83e0 slab: change retu... |
3016 3017 |
nid = page_to_nid(page); if (cache_grow(cache, flags, nid, page)) { |
3c517a613 [PATCH] slab: bet... |
3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 |
obj = ____cache_alloc_node(cache, flags | GFP_THISNODE, nid); if (!obj) /* * Another processor may allocate the * objects in the slab since we are * not holding any locks. */ goto retry; } else { |
b6a604518 [PATCH] fix BUG_O... |
3028 |
/* cache_grow already freed obj */ |
3c517a613 [PATCH] slab: bet... |
3029 3030 3031 |
obj = NULL; } } |
aedb0eb10 [PATCH] Slab: Do ... |
3032 |
} |
cc9a6c877 cpuset: mm: reduc... |
3033 |
|
d26914d11 mm: optimize put_... |
3034 |
if (unlikely(!obj && read_mems_allowed_retry(cpuset_mems_cookie))) |
cc9a6c877 cpuset: mm: reduc... |
3035 |
goto retry_cpuset; |
765c4507a [PATCH] GFP_THISN... |
3036 3037 3038 3039 |
return obj; } /* |
e498be7da [PATCH] Numa-awar... |
3040 |
* A interface to enable slab creation on nodeid |
1da177e4c Linux-2.6.12-rc2 |
3041 |
*/ |
8b98c1699 [PATCH] leak trac... |
3042 |
static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, |
a737b3e2f [PATCH] slab cleanup |
3043 |
int nodeid) |
e498be7da [PATCH] Numa-awar... |
3044 3045 |
{ struct list_head *entry; |
8456a648c slab: use struct ... |
3046 |
struct page *page; |
ce8eb6c42 slab: Rename list... |
3047 |
struct kmem_cache_node *n; |
b28a02de8 [PATCH] slab: fix... |
3048 |
void *obj; |
b28a02de8 [PATCH] slab: fix... |
3049 |
int x; |
14e50c6a9 mm: slab: Verify ... |
3050 |
VM_BUG_ON(nodeid > num_online_nodes()); |
ce8eb6c42 slab: Rename list... |
3051 3052 |
n = cachep->node[nodeid]; BUG_ON(!n); |
b28a02de8 [PATCH] slab: fix... |
3053 |
|
a737b3e2f [PATCH] slab cleanup |
3054 |
retry: |
ca3b9b917 [PATCH] NUMA slab... |
3055 |
check_irq_off(); |
ce8eb6c42 slab: Rename list... |
3056 3057 3058 3059 3060 3061 |
spin_lock(&n->list_lock); entry = n->slabs_partial.next; if (entry == &n->slabs_partial) { n->free_touched = 1; entry = n->slabs_free.next; if (entry == &n->slabs_free) |
b28a02de8 [PATCH] slab: fix... |
3062 3063 |
goto must_grow; } |
8456a648c slab: use struct ... |
3064 |
page = list_entry(entry, struct page, lru); |
b28a02de8 [PATCH] slab: fix... |
3065 |
check_spinlock_acquired_node(cachep, nodeid); |
b28a02de8 [PATCH] slab: fix... |
3066 3067 3068 3069 |
STATS_INC_NODEALLOCS(cachep); STATS_INC_ACTIVE(cachep); STATS_SET_HIGH(cachep); |
8456a648c slab: use struct ... |
3070 |
BUG_ON(page->active == cachep->num); |
b28a02de8 [PATCH] slab: fix... |
3071 |
|
8456a648c slab: use struct ... |
3072 |
obj = slab_get_obj(cachep, page, nodeid); |
ce8eb6c42 slab: Rename list... |
3073 |
n->free_objects--; |
b28a02de8 [PATCH] slab: fix... |
3074 |
/* move slabp to correct slabp list: */ |
8456a648c slab: use struct ... |
3075 |
list_del(&page->lru); |
b28a02de8 [PATCH] slab: fix... |
3076 |
|
8456a648c slab: use struct ... |
3077 3078 |
if (page->active == cachep->num) list_add(&page->lru, &n->slabs_full); |
a737b3e2f [PATCH] slab cleanup |
3079 |
else |
8456a648c slab: use struct ... |
3080 |
list_add(&page->lru, &n->slabs_partial); |
e498be7da [PATCH] Numa-awar... |
3081 |
|
ce8eb6c42 slab: Rename list... |
3082 |
spin_unlock(&n->list_lock); |
b28a02de8 [PATCH] slab: fix... |
3083 |
goto done; |
e498be7da [PATCH] Numa-awar... |
3084 |
|
a737b3e2f [PATCH] slab cleanup |
3085 |
must_grow: |
ce8eb6c42 slab: Rename list... |
3086 |
spin_unlock(&n->list_lock); |
3c517a613 [PATCH] slab: bet... |
3087 |
x = cache_grow(cachep, flags | GFP_THISNODE, nodeid, NULL); |
765c4507a [PATCH] GFP_THISN... |
3088 3089 |
if (x) goto retry; |
1da177e4c Linux-2.6.12-rc2 |
3090 |
|
8c8cc2c10 [PATCH] slab: cac... |
3091 |
return fallback_alloc(cachep, flags); |
e498be7da [PATCH] Numa-awar... |
3092 |
|
a737b3e2f [PATCH] slab cleanup |
3093 |
done: |
b28a02de8 [PATCH] slab: fix... |
3094 |
return obj; |
e498be7da [PATCH] Numa-awar... |
3095 |
} |
8c8cc2c10 [PATCH] slab: cac... |
3096 |
|
8c8cc2c10 [PATCH] slab: cac... |
3097 |
static __always_inline void * |
48356303f mm, slab: Rename ... |
3098 |
slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, |
7c0cb9c64 mm, slab: Replace... |
3099 |
unsigned long caller) |
8c8cc2c10 [PATCH] slab: cac... |
3100 3101 3102 |
{ unsigned long save_flags; void *ptr; |
7d6e6d09d numa: slab: use n... |
3103 |
int slab_node = numa_mem_id(); |
8c8cc2c10 [PATCH] slab: cac... |
3104 |
|
dcce284a2 mm: Extend gfp ma... |
3105 |
flags &= gfp_allowed_mask; |
7e85ee0c1 slab,slub: don't ... |
3106 |
|
cf40bd16f lockdep: annotate... |
3107 |
lockdep_trace_alloc(flags); |
773ff60e8 SLUB: failslab su... |
3108 |
if (slab_should_failslab(cachep, flags)) |
824ebef12 fault injection: ... |
3109 |
return NULL; |
d79923fad sl[au]b: allocate... |
3110 |
cachep = memcg_kmem_get_cache(cachep, flags); |
8c8cc2c10 [PATCH] slab: cac... |
3111 3112 |
cache_alloc_debugcheck_before(cachep, flags); local_irq_save(save_flags); |
eacbbae38 slab: use NUMA_NO... |
3113 |
if (nodeid == NUMA_NO_NODE) |
7d6e6d09d numa: slab: use n... |
3114 |
nodeid = slab_node; |
8c8cc2c10 [PATCH] slab: cac... |
3115 |
|
6a67368c3 slab: Rename node... |
3116 |
if (unlikely(!cachep->node[nodeid])) { |
8c8cc2c10 [PATCH] slab: cac... |
3117 3118 3119 3120 |
/* Node not bootstrapped yet */ ptr = fallback_alloc(cachep, flags); goto out; } |
7d6e6d09d numa: slab: use n... |
3121 |
if (nodeid == slab_node) { |
8c8cc2c10 [PATCH] slab: cac... |
3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 |
/* * Use the locally cached objects if possible. * However ____cache_alloc does not allow fallback * to other nodes. It may fail while we still have * objects on other nodes available. */ ptr = ____cache_alloc(cachep, flags); if (ptr) goto out; } /* ___cache_alloc_node can fall back to other nodes */ ptr = ____cache_alloc_node(cachep, flags, nodeid); out: local_irq_restore(save_flags); ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); |
8c138bc00 slab: Get rid of ... |
3137 |
kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags, |
d5cff6352 kmemleak: Add the... |
3138 |
flags); |
8c8cc2c10 [PATCH] slab: cac... |
3139 |
|
5087c8229 slab: Make alloca... |
3140 |
if (likely(ptr)) { |
8c138bc00 slab: Get rid of ... |
3141 |
kmemcheck_slab_alloc(cachep, flags, ptr, cachep->object_size); |
5087c8229 slab: Make alloca... |
3142 3143 3144 |
if (unlikely(flags & __GFP_ZERO)) memset(ptr, 0, cachep->object_size); } |
d07dbea46 Slab allocators: ... |
3145 |
|
8c8cc2c10 [PATCH] slab: cac... |
3146 3147 3148 3149 3150 3151 3152 |
return ptr; } static __always_inline void * __do_cache_alloc(struct kmem_cache *cache, gfp_t flags) { void *objp; |
f0432d159 mm, mempolicy: re... |
3153 |
if (current->mempolicy || unlikely(current->flags & PF_SPREAD_SLAB)) { |
8c8cc2c10 [PATCH] slab: cac... |
3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 |
objp = alternate_node_alloc(cache, flags); if (objp) goto out; } objp = ____cache_alloc(cache, flags); /* * We may just have run out of memory on the local node. * ____cache_alloc_node() knows how to locate memory on other nodes */ |
7d6e6d09d numa: slab: use n... |
3164 3165 |
if (!objp) objp = ____cache_alloc_node(cache, flags, numa_mem_id()); |
8c8cc2c10 [PATCH] slab: cac... |
3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 |
out: return objp; } #else static __always_inline void * __do_cache_alloc(struct kmem_cache *cachep, gfp_t flags) { return ____cache_alloc(cachep, flags); } #endif /* CONFIG_NUMA */ static __always_inline void * |
48356303f mm, slab: Rename ... |
3181 |
slab_alloc(struct kmem_cache *cachep, gfp_t flags, unsigned long caller) |
8c8cc2c10 [PATCH] slab: cac... |
3182 3183 3184 |
{ unsigned long save_flags; void *objp; |
dcce284a2 mm: Extend gfp ma... |
3185 |
flags &= gfp_allowed_mask; |
7e85ee0c1 slab,slub: don't ... |
3186 |
|
cf40bd16f lockdep: annotate... |
3187 |
lockdep_trace_alloc(flags); |
773ff60e8 SLUB: failslab su... |
3188 |
if (slab_should_failslab(cachep, flags)) |
824ebef12 fault injection: ... |
3189 |
return NULL; |
d79923fad sl[au]b: allocate... |
3190 |
cachep = memcg_kmem_get_cache(cachep, flags); |
8c8cc2c10 [PATCH] slab: cac... |
3191 3192 3193 3194 3195 |
cache_alloc_debugcheck_before(cachep, flags); local_irq_save(save_flags); objp = __do_cache_alloc(cachep, flags); local_irq_restore(save_flags); objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller); |
8c138bc00 slab: Get rid of ... |
3196 |
kmemleak_alloc_recursive(objp, cachep->object_size, 1, cachep->flags, |
d5cff6352 kmemleak: Add the... |
3197 |
flags); |
8c8cc2c10 [PATCH] slab: cac... |
3198 |
prefetchw(objp); |
5087c8229 slab: Make alloca... |
3199 |
if (likely(objp)) { |
8c138bc00 slab: Get rid of ... |
3200 |
kmemcheck_slab_alloc(cachep, flags, objp, cachep->object_size); |
5087c8229 slab: Make alloca... |
3201 3202 3203 |
if (unlikely(flags & __GFP_ZERO)) memset(objp, 0, cachep->object_size); } |
d07dbea46 Slab allocators: ... |
3204 |
|
8c8cc2c10 [PATCH] slab: cac... |
3205 3206 |
return objp; } |
e498be7da [PATCH] Numa-awar... |
3207 3208 |
/* |
5f0985bb1 mm/slab.c: cleanu... |
3209 |
* Caller needs to acquire correct kmem_cache_node's list_lock |
e498be7da [PATCH] Numa-awar... |
3210 |
*/ |
343e0d7a9 [PATCH] slab: rep... |
3211 |
static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects, |
b28a02de8 [PATCH] slab: fix... |
3212 |
int node) |
1da177e4c Linux-2.6.12-rc2 |
3213 3214 |
{ int i; |
ce8eb6c42 slab: Rename list... |
3215 |
struct kmem_cache_node *n; |
1da177e4c Linux-2.6.12-rc2 |
3216 3217 |
for (i = 0; i < nr_objects; i++) { |
072bb0aa5 mm: sl[au]b: add ... |
3218 |
void *objp; |
8456a648c slab: use struct ... |
3219 |
struct page *page; |
1da177e4c Linux-2.6.12-rc2 |
3220 |
|
072bb0aa5 mm: sl[au]b: add ... |
3221 3222 |
clear_obj_pfmemalloc(&objpp[i]); objp = objpp[i]; |
8456a648c slab: use struct ... |
3223 |
page = virt_to_head_page(objp); |
ce8eb6c42 slab: Rename list... |
3224 |
n = cachep->node[node]; |
8456a648c slab: use struct ... |
3225 |
list_del(&page->lru); |
ff69416e6 [PATCH] slab: fix... |
3226 |
check_spinlock_acquired_node(cachep, node); |
8456a648c slab: use struct ... |
3227 |
slab_put_obj(cachep, page, objp, node); |
1da177e4c Linux-2.6.12-rc2 |
3228 |
STATS_DEC_ACTIVE(cachep); |
ce8eb6c42 slab: Rename list... |
3229 |
n->free_objects++; |
1da177e4c Linux-2.6.12-rc2 |
3230 3231 |
/* fixup slab chains */ |
8456a648c slab: use struct ... |
3232 |
if (page->active == 0) { |
ce8eb6c42 slab: Rename list... |
3233 3234 |
if (n->free_objects > n->free_limit) { n->free_objects -= cachep->num; |
e5ac9c5ae [PATCH] Add some ... |
3235 3236 3237 3238 3239 3240 |
/* No need to drop any previously held * lock here, even if we have a off-slab slab * descriptor it is guaranteed to come from * a different cache, refer to comments before * alloc_slabmgmt. */ |
8456a648c slab: use struct ... |
3241 |
slab_destroy(cachep, page); |
1da177e4c Linux-2.6.12-rc2 |
3242 |
} else { |
8456a648c slab: use struct ... |
3243 |
list_add(&page->lru, &n->slabs_free); |
1da177e4c Linux-2.6.12-rc2 |
3244 3245 3246 3247 3248 3249 |
} } else { /* Unconditionally move a slab to the end of the * partial list on free - maximum time for the * other objects to be freed, too. */ |
8456a648c slab: use struct ... |
3250 |
list_add_tail(&page->lru, &n->slabs_partial); |
1da177e4c Linux-2.6.12-rc2 |
3251 3252 3253 |
} } } |
343e0d7a9 [PATCH] slab: rep... |
3254 |
static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac) |
1da177e4c Linux-2.6.12-rc2 |
3255 3256 |
{ int batchcount; |
ce8eb6c42 slab: Rename list... |
3257 |
struct kmem_cache_node *n; |
7d6e6d09d numa: slab: use n... |
3258 |
int node = numa_mem_id(); |
1da177e4c Linux-2.6.12-rc2 |
3259 3260 3261 3262 3263 3264 |
batchcount = ac->batchcount; #if DEBUG BUG_ON(!batchcount || batchcount > ac->avail); #endif check_irq_off(); |
ce8eb6c42 slab: Rename list... |
3265 3266 3267 3268 |
n = cachep->node[node]; spin_lock(&n->list_lock); if (n->shared) { struct array_cache *shared_array = n->shared; |
b28a02de8 [PATCH] slab: fix... |
3269 |
int max = shared_array->limit - shared_array->avail; |
1da177e4c Linux-2.6.12-rc2 |
3270 3271 3272 |
if (max) { if (batchcount > max) batchcount = max; |
e498be7da [PATCH] Numa-awar... |
3273 |
memcpy(&(shared_array->entry[shared_array->avail]), |
b28a02de8 [PATCH] slab: fix... |
3274 |
ac->entry, sizeof(void *) * batchcount); |
1da177e4c Linux-2.6.12-rc2 |
3275 3276 3277 3278 |
shared_array->avail += batchcount; goto free_done; } } |
ff69416e6 [PATCH] slab: fix... |
3279 |
free_block(cachep, ac->entry, batchcount, node); |
a737b3e2f [PATCH] slab cleanup |
3280 |
free_done: |
1da177e4c Linux-2.6.12-rc2 |
3281 3282 3283 3284 |
#if STATS { int i = 0; struct list_head *p; |
ce8eb6c42 slab: Rename list... |
3285 3286 |
p = n->slabs_free.next; while (p != &(n->slabs_free)) { |
8456a648c slab: use struct ... |
3287 |
struct page *page; |
1da177e4c Linux-2.6.12-rc2 |
3288 |
|
8456a648c slab: use struct ... |
3289 3290 |
page = list_entry(p, struct page, lru); BUG_ON(page->active); |
1da177e4c Linux-2.6.12-rc2 |
3291 3292 3293 3294 3295 3296 3297 |
i++; p = p->next; } STATS_SET_FREEABLE(cachep, i); } #endif |
ce8eb6c42 slab: Rename list... |
3298 |
spin_unlock(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
3299 |
ac->avail -= batchcount; |
a737b3e2f [PATCH] slab cleanup |
3300 |
memmove(ac->entry, &(ac->entry[batchcount]), sizeof(void *)*ac->avail); |
1da177e4c Linux-2.6.12-rc2 |
3301 3302 3303 |
} /* |
a737b3e2f [PATCH] slab cleanup |
3304 3305 |
* Release an obj back to its cache. If the obj has a constructed state, it must * be in this state _before_ it is released. Called with disabled ints. |
1da177e4c Linux-2.6.12-rc2 |
3306 |
*/ |
a947eb95e SLAB: Record actu... |
3307 |
static inline void __cache_free(struct kmem_cache *cachep, void *objp, |
7c0cb9c64 mm, slab: Replace... |
3308 |
unsigned long caller) |
1da177e4c Linux-2.6.12-rc2 |
3309 |
{ |
9a2dba4b4 [PATCH] slab: ren... |
3310 |
struct array_cache *ac = cpu_cache_get(cachep); |
1da177e4c Linux-2.6.12-rc2 |
3311 3312 |
check_irq_off(); |
d5cff6352 kmemleak: Add the... |
3313 |
kmemleak_free_recursive(objp, cachep->flags); |
a947eb95e SLAB: Record actu... |
3314 |
objp = cache_free_debugcheck(cachep, objp, caller); |
1da177e4c Linux-2.6.12-rc2 |
3315 |
|
8c138bc00 slab: Get rid of ... |
3316 |
kmemcheck_slab_free(cachep, objp, cachep->object_size); |
c175eea46 slab: add hooks f... |
3317 |
|
1807a1aaf slab: skip callin... |
3318 3319 3320 3321 3322 3323 3324 |
/* * Skip calling cache_free_alien() when the platform is not numa. * This will avoid cache misses that happen while accessing slabp (which * is per page memory reference) to get nodeid. Instead use a global * variable to skip the call, which is mostly likely to be present in * the cache. */ |
b6e68bc1b page allocator: s... |
3325 |
if (nr_online_nodes > 1 && cache_free_alien(cachep, objp)) |
729bd0b74 [PATCH] slab: ext... |
3326 |
return; |
1da177e4c Linux-2.6.12-rc2 |
3327 3328 |
if (likely(ac->avail < ac->limit)) { STATS_INC_FREEHIT(cachep); |
1da177e4c Linux-2.6.12-rc2 |
3329 3330 3331 |
} else { STATS_INC_FREEMISS(cachep); cache_flusharray(cachep, ac); |
1da177e4c Linux-2.6.12-rc2 |
3332 |
} |
42c8c99cd slab, cleanup: re... |
3333 |
|
072bb0aa5 mm: sl[au]b: add ... |
3334 |
ac_put_obj(cachep, ac, objp); |
1da177e4c Linux-2.6.12-rc2 |
3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 |
} /** * kmem_cache_alloc - Allocate an object * @cachep: The cache to allocate from. * @flags: See kmalloc(). * * Allocate an object from this cache. The flags are only relevant * if the cache has no available objects. */ |
343e0d7a9 [PATCH] slab: rep... |
3345 |
void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) |
1da177e4c Linux-2.6.12-rc2 |
3346 |
{ |
48356303f mm, slab: Rename ... |
3347 |
void *ret = slab_alloc(cachep, flags, _RET_IP_); |
36555751c kmemtrace: SLAB h... |
3348 |
|
ca2b84cb3 kmemtrace: use tr... |
3349 |
trace_kmem_cache_alloc(_RET_IP_, ret, |
8c138bc00 slab: Get rid of ... |
3350 |
cachep->object_size, cachep->size, flags); |
36555751c kmemtrace: SLAB h... |
3351 3352 |
return ret; |
1da177e4c Linux-2.6.12-rc2 |
3353 3354 |
} EXPORT_SYMBOL(kmem_cache_alloc); |
0f24f1287 tracing, slab: De... |
3355 |
#ifdef CONFIG_TRACING |
85beb5869 tracing/slab: Mov... |
3356 |
void * |
4052147c0 mm, slab: Match S... |
3357 |
kmem_cache_alloc_trace(struct kmem_cache *cachep, gfp_t flags, size_t size) |
36555751c kmemtrace: SLAB h... |
3358 |
{ |
85beb5869 tracing/slab: Mov... |
3359 |
void *ret; |
48356303f mm, slab: Rename ... |
3360 |
ret = slab_alloc(cachep, flags, _RET_IP_); |
85beb5869 tracing/slab: Mov... |
3361 3362 |
trace_kmalloc(_RET_IP_, ret, |
ff4fcd01e mm, slab: Remove ... |
3363 |
size, cachep->size, flags); |
85beb5869 tracing/slab: Mov... |
3364 |
return ret; |
36555751c kmemtrace: SLAB h... |
3365 |
} |
85beb5869 tracing/slab: Mov... |
3366 |
EXPORT_SYMBOL(kmem_cache_alloc_trace); |
36555751c kmemtrace: SLAB h... |
3367 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
3368 |
#ifdef CONFIG_NUMA |
d0d04b78f mm, slab: moved k... |
3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 |
/** * kmem_cache_alloc_node - Allocate an object on the specified node * @cachep: The cache to allocate from. * @flags: See kmalloc(). * @nodeid: node number of the target node. * * Identical to kmem_cache_alloc but it will allocate memory on the given * node, which can improve the performance for cpu bound structures. * * Fallback to other node is possible if __GFP_THISNODE is not set. */ |
8b98c1699 [PATCH] leak trac... |
3380 3381 |
void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) { |
48356303f mm, slab: Rename ... |
3382 |
void *ret = slab_alloc_node(cachep, flags, nodeid, _RET_IP_); |
36555751c kmemtrace: SLAB h... |
3383 |
|
ca2b84cb3 kmemtrace: use tr... |
3384 |
trace_kmem_cache_alloc_node(_RET_IP_, ret, |
8c138bc00 slab: Get rid of ... |
3385 |
cachep->object_size, cachep->size, |
ca2b84cb3 kmemtrace: use tr... |
3386 |
flags, nodeid); |
36555751c kmemtrace: SLAB h... |
3387 3388 |
return ret; |
8b98c1699 [PATCH] leak trac... |
3389 |
} |
1da177e4c Linux-2.6.12-rc2 |
3390 |
EXPORT_SYMBOL(kmem_cache_alloc_node); |
0f24f1287 tracing, slab: De... |
3391 |
#ifdef CONFIG_TRACING |
4052147c0 mm, slab: Match S... |
3392 |
void *kmem_cache_alloc_node_trace(struct kmem_cache *cachep, |
85beb5869 tracing/slab: Mov... |
3393 |
gfp_t flags, |
4052147c0 mm, slab: Match S... |
3394 3395 |
int nodeid, size_t size) |
36555751c kmemtrace: SLAB h... |
3396 |
{ |
85beb5869 tracing/slab: Mov... |
3397 |
void *ret; |
592f41450 mm/slab: Fix typo... |
3398 |
ret = slab_alloc_node(cachep, flags, nodeid, _RET_IP_); |
7c0cb9c64 mm, slab: Replace... |
3399 |
|
85beb5869 tracing/slab: Mov... |
3400 |
trace_kmalloc_node(_RET_IP_, ret, |
ff4fcd01e mm, slab: Remove ... |
3401 |
size, cachep->size, |
85beb5869 tracing/slab: Mov... |
3402 3403 |
flags, nodeid); return ret; |
36555751c kmemtrace: SLAB h... |
3404 |
} |
85beb5869 tracing/slab: Mov... |
3405 |
EXPORT_SYMBOL(kmem_cache_alloc_node_trace); |
36555751c kmemtrace: SLAB h... |
3406 |
#endif |
8b98c1699 [PATCH] leak trac... |
3407 |
static __always_inline void * |
7c0cb9c64 mm, slab: Replace... |
3408 |
__do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) |
97e2bde47 [PATCH] add kmall... |
3409 |
{ |
343e0d7a9 [PATCH] slab: rep... |
3410 |
struct kmem_cache *cachep; |
97e2bde47 [PATCH] add kmall... |
3411 |
|
2c59dd654 slab: Common Kmal... |
3412 |
cachep = kmalloc_slab(size, flags); |
6cb8f9132 Slab allocators: ... |
3413 3414 |
if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; |
4052147c0 mm, slab: Match S... |
3415 |
return kmem_cache_alloc_node_trace(cachep, flags, node, size); |
97e2bde47 [PATCH] add kmall... |
3416 |
} |
8b98c1699 [PATCH] leak trac... |
3417 |
|
0bb38a5cd tracing, slab: Fi... |
3418 |
#if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_TRACING) |
8b98c1699 [PATCH] leak trac... |
3419 3420 |
void *__kmalloc_node(size_t size, gfp_t flags, int node) { |
7c0cb9c64 mm, slab: Replace... |
3421 |
return __do_kmalloc_node(size, flags, node, _RET_IP_); |
8b98c1699 [PATCH] leak trac... |
3422 |
} |
dbe5e69d2 [PATCH] slab: opt... |
3423 |
EXPORT_SYMBOL(__kmalloc_node); |
8b98c1699 [PATCH] leak trac... |
3424 3425 |
void *__kmalloc_node_track_caller(size_t size, gfp_t flags, |
ce71e27c6 SLUB: Replace __b... |
3426 |
int node, unsigned long caller) |
8b98c1699 [PATCH] leak trac... |
3427 |
{ |
7c0cb9c64 mm, slab: Replace... |
3428 |
return __do_kmalloc_node(size, flags, node, caller); |
8b98c1699 [PATCH] leak trac... |
3429 3430 3431 3432 3433 |
} EXPORT_SYMBOL(__kmalloc_node_track_caller); #else void *__kmalloc_node(size_t size, gfp_t flags, int node) { |
7c0cb9c64 mm, slab: Replace... |
3434 |
return __do_kmalloc_node(size, flags, node, 0); |
8b98c1699 [PATCH] leak trac... |
3435 3436 |
} EXPORT_SYMBOL(__kmalloc_node); |
0bb38a5cd tracing, slab: Fi... |
3437 |
#endif /* CONFIG_DEBUG_SLAB || CONFIG_TRACING */ |
8b98c1699 [PATCH] leak trac... |
3438 |
#endif /* CONFIG_NUMA */ |
1da177e4c Linux-2.6.12-rc2 |
3439 3440 |
/** |
800590f52 [PATCH] slab: kma... |
3441 |
* __do_kmalloc - allocate memory |
1da177e4c Linux-2.6.12-rc2 |
3442 |
* @size: how many bytes of memory are required. |
800590f52 [PATCH] slab: kma... |
3443 |
* @flags: the type of memory to allocate (see kmalloc). |
911851e6e [PATCH] slab: fix... |
3444 |
* @caller: function caller for debug tracking of the caller |
1da177e4c Linux-2.6.12-rc2 |
3445 |
*/ |
7fd6b1413 [PATCH] slab: fix... |
3446 |
static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, |
7c0cb9c64 mm, slab: Replace... |
3447 |
unsigned long caller) |
1da177e4c Linux-2.6.12-rc2 |
3448 |
{ |
343e0d7a9 [PATCH] slab: rep... |
3449 |
struct kmem_cache *cachep; |
36555751c kmemtrace: SLAB h... |
3450 |
void *ret; |
1da177e4c Linux-2.6.12-rc2 |
3451 |
|
2c59dd654 slab: Common Kmal... |
3452 |
cachep = kmalloc_slab(size, flags); |
a5c96d8a1 Fix up non-NUMA S... |
3453 3454 |
if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; |
48356303f mm, slab: Rename ... |
3455 |
ret = slab_alloc(cachep, flags, caller); |
36555751c kmemtrace: SLAB h... |
3456 |
|
7c0cb9c64 mm, slab: Replace... |
3457 |
trace_kmalloc(caller, ret, |
3b0efdfa1 mm, sl[aou]b: Ext... |
3458 |
size, cachep->size, flags); |
36555751c kmemtrace: SLAB h... |
3459 3460 |
return ret; |
7fd6b1413 [PATCH] slab: fix... |
3461 |
} |
7fd6b1413 [PATCH] slab: fix... |
3462 |
|
0bb38a5cd tracing, slab: Fi... |
3463 |
#if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_TRACING) |
7fd6b1413 [PATCH] slab: fix... |
3464 3465 |
void *__kmalloc(size_t size, gfp_t flags) { |
7c0cb9c64 mm, slab: Replace... |
3466 |
return __do_kmalloc(size, flags, _RET_IP_); |
1da177e4c Linux-2.6.12-rc2 |
3467 3468 |
} EXPORT_SYMBOL(__kmalloc); |
ce71e27c6 SLUB: Replace __b... |
3469 |
void *__kmalloc_track_caller(size_t size, gfp_t flags, unsigned long caller) |
7fd6b1413 [PATCH] slab: fix... |
3470 |
{ |
7c0cb9c64 mm, slab: Replace... |
3471 |
return __do_kmalloc(size, flags, caller); |
7fd6b1413 [PATCH] slab: fix... |
3472 3473 |
} EXPORT_SYMBOL(__kmalloc_track_caller); |
1d2c8eea6 [PATCH] slab: cle... |
3474 3475 3476 3477 |
#else void *__kmalloc(size_t size, gfp_t flags) { |
7c0cb9c64 mm, slab: Replace... |
3478 |
return __do_kmalloc(size, flags, 0); |
1d2c8eea6 [PATCH] slab: cle... |
3479 3480 |
} EXPORT_SYMBOL(__kmalloc); |
7fd6b1413 [PATCH] slab: fix... |
3481 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
3482 3483 3484 3485 3486 3487 3488 3489 |
/** * kmem_cache_free - Deallocate an object * @cachep: The cache the allocation was from. * @objp: The previously allocated object. * * Free an object which was previously allocated from this * cache. */ |
343e0d7a9 [PATCH] slab: rep... |
3490 |
void kmem_cache_free(struct kmem_cache *cachep, void *objp) |
1da177e4c Linux-2.6.12-rc2 |
3491 3492 |
{ unsigned long flags; |
b9ce5ef49 sl[au]b: always g... |
3493 3494 3495 |
cachep = cache_from_obj(cachep, objp); if (!cachep) return; |
1da177e4c Linux-2.6.12-rc2 |
3496 3497 |
local_irq_save(flags); |
d97d476b1 slab: Fix a typo ... |
3498 |
debug_check_no_locks_freed(objp, cachep->object_size); |
3ac7fe5a4 infrastructure to... |
3499 |
if (!(cachep->flags & SLAB_DEBUG_OBJECTS)) |
8c138bc00 slab: Get rid of ... |
3500 |
debug_check_no_obj_freed(objp, cachep->object_size); |
7c0cb9c64 mm, slab: Replace... |
3501 |
__cache_free(cachep, objp, _RET_IP_); |
1da177e4c Linux-2.6.12-rc2 |
3502 |
local_irq_restore(flags); |
36555751c kmemtrace: SLAB h... |
3503 |
|
ca2b84cb3 kmemtrace: use tr... |
3504 |
trace_kmem_cache_free(_RET_IP_, objp); |
1da177e4c Linux-2.6.12-rc2 |
3505 3506 3507 3508 |
} EXPORT_SYMBOL(kmem_cache_free); /** |
1da177e4c Linux-2.6.12-rc2 |
3509 3510 3511 |
* kfree - free previously allocated memory * @objp: pointer returned by kmalloc. * |
80e93effc [PATCH] update kf... |
3512 3513 |
* If @objp is NULL, no operation is performed. * |
1da177e4c Linux-2.6.12-rc2 |
3514 3515 3516 3517 3518 |
* Don't free memory not originally allocated by kmalloc() * or you will run into trouble. */ void kfree(const void *objp) { |
343e0d7a9 [PATCH] slab: rep... |
3519 |
struct kmem_cache *c; |
1da177e4c Linux-2.6.12-rc2 |
3520 |
unsigned long flags; |
2121db74b kmemtrace: trace ... |
3521 |
trace_kfree(_RET_IP_, objp); |
6cb8f9132 Slab allocators: ... |
3522 |
if (unlikely(ZERO_OR_NULL_PTR(objp))) |
1da177e4c Linux-2.6.12-rc2 |
3523 3524 3525 |
return; local_irq_save(flags); kfree_debugcheck(objp); |
6ed5eb221 [PATCH] slab: ext... |
3526 |
c = virt_to_cache(objp); |
8c138bc00 slab: Get rid of ... |
3527 3528 3529 |
debug_check_no_locks_freed(objp, c->object_size); debug_check_no_obj_freed(objp, c->object_size); |
7c0cb9c64 mm, slab: Replace... |
3530 |
__cache_free(c, (void *)objp, _RET_IP_); |
1da177e4c Linux-2.6.12-rc2 |
3531 3532 3533 |
local_irq_restore(flags); } EXPORT_SYMBOL(kfree); |
e498be7da [PATCH] Numa-awar... |
3534 |
/* |
ce8eb6c42 slab: Rename list... |
3535 |
* This initializes kmem_cache_node or resizes various caches for all nodes. |
e498be7da [PATCH] Numa-awar... |
3536 |
*/ |
5f0985bb1 mm/slab.c: cleanu... |
3537 |
static int alloc_kmem_cache_node(struct kmem_cache *cachep, gfp_t gfp) |
e498be7da [PATCH] Numa-awar... |
3538 3539 |
{ int node; |
ce8eb6c42 slab: Rename list... |
3540 |
struct kmem_cache_node *n; |
cafeb02e0 [PATCH] alloc_kme... |
3541 |
struct array_cache *new_shared; |
3395ee058 [PATCH] mm: add n... |
3542 |
struct array_cache **new_alien = NULL; |
e498be7da [PATCH] Numa-awar... |
3543 |
|
9c09a95cf slab: partially r... |
3544 |
for_each_online_node(node) { |
cafeb02e0 [PATCH] alloc_kme... |
3545 |
|
3395ee058 [PATCH] mm: add n... |
3546 |
if (use_alien_caches) { |
83b519e8b slab: setup alloc... |
3547 |
new_alien = alloc_alien_cache(node, cachep->limit, gfp); |
3395ee058 [PATCH] mm: add n... |
3548 3549 3550 |
if (!new_alien) goto fail; } |
cafeb02e0 [PATCH] alloc_kme... |
3551 |
|
631098469 SLAB: don't alloc... |
3552 3553 3554 |
new_shared = NULL; if (cachep->shared) { new_shared = alloc_arraycache(node, |
0718dc2a8 [PATCH] slab: fix... |
3555 |
cachep->shared*cachep->batchcount, |
83b519e8b slab: setup alloc... |
3556 |
0xbaadf00d, gfp); |
631098469 SLAB: don't alloc... |
3557 3558 3559 3560 |
if (!new_shared) { free_alien_cache(new_alien); goto fail; } |
0718dc2a8 [PATCH] slab: fix... |
3561 |
} |
cafeb02e0 [PATCH] alloc_kme... |
3562 |
|
ce8eb6c42 slab: Rename list... |
3563 3564 3565 |
n = cachep->node[node]; if (n) { struct array_cache *shared = n->shared; |
cafeb02e0 [PATCH] alloc_kme... |
3566 |
|
ce8eb6c42 slab: Rename list... |
3567 |
spin_lock_irq(&n->list_lock); |
e498be7da [PATCH] Numa-awar... |
3568 |
|
cafeb02e0 [PATCH] alloc_kme... |
3569 |
if (shared) |
0718dc2a8 [PATCH] slab: fix... |
3570 3571 |
free_block(cachep, shared->entry, shared->avail, node); |
e498be7da [PATCH] Numa-awar... |
3572 |
|
ce8eb6c42 slab: Rename list... |
3573 3574 3575 |
n->shared = new_shared; if (!n->alien) { n->alien = new_alien; |
e498be7da [PATCH] Numa-awar... |
3576 3577 |
new_alien = NULL; } |
ce8eb6c42 slab: Rename list... |
3578 |
n->free_limit = (1 + nr_cpus_node(node)) * |
a737b3e2f [PATCH] slab cleanup |
3579 |
cachep->batchcount + cachep->num; |
ce8eb6c42 slab: Rename list... |
3580 |
spin_unlock_irq(&n->list_lock); |
cafeb02e0 [PATCH] alloc_kme... |
3581 |
kfree(shared); |
e498be7da [PATCH] Numa-awar... |
3582 3583 3584 |
free_alien_cache(new_alien); continue; } |
ce8eb6c42 slab: Rename list... |
3585 3586 |
n = kmalloc_node(sizeof(struct kmem_cache_node), gfp, node); if (!n) { |
0718dc2a8 [PATCH] slab: fix... |
3587 3588 |
free_alien_cache(new_alien); kfree(new_shared); |
e498be7da [PATCH] Numa-awar... |
3589 |
goto fail; |
0718dc2a8 [PATCH] slab: fix... |
3590 |
} |
e498be7da [PATCH] Numa-awar... |
3591 |
|
ce8eb6c42 slab: Rename list... |
3592 |
kmem_cache_node_init(n); |
5f0985bb1 mm/slab.c: cleanu... |
3593 3594 |
n->next_reap = jiffies + REAPTIMEOUT_NODE + ((unsigned long)cachep) % REAPTIMEOUT_NODE; |
ce8eb6c42 slab: Rename list... |
3595 3596 3597 |
n->shared = new_shared; n->alien = new_alien; n->free_limit = (1 + nr_cpus_node(node)) * |
a737b3e2f [PATCH] slab cleanup |
3598 |
cachep->batchcount + cachep->num; |
ce8eb6c42 slab: Rename list... |
3599 |
cachep->node[node] = n; |
e498be7da [PATCH] Numa-awar... |
3600 |
} |
cafeb02e0 [PATCH] alloc_kme... |
3601 |
return 0; |
0718dc2a8 [PATCH] slab: fix... |
3602 |
|
a737b3e2f [PATCH] slab cleanup |
3603 |
fail: |
3b0efdfa1 mm, sl[aou]b: Ext... |
3604 |
if (!cachep->list.next) { |
0718dc2a8 [PATCH] slab: fix... |
3605 3606 3607 |
/* Cache is not active yet. Roll back what we did */ node--; while (node >= 0) { |
6a67368c3 slab: Rename node... |
3608 |
if (cachep->node[node]) { |
ce8eb6c42 slab: Rename list... |
3609 |
n = cachep->node[node]; |
0718dc2a8 [PATCH] slab: fix... |
3610 |
|
ce8eb6c42 slab: Rename list... |
3611 3612 3613 |
kfree(n->shared); free_alien_cache(n->alien); kfree(n); |
6a67368c3 slab: Rename node... |
3614 |
cachep->node[node] = NULL; |
0718dc2a8 [PATCH] slab: fix... |
3615 3616 3617 3618 |
} node--; } } |
cafeb02e0 [PATCH] alloc_kme... |
3619 |
return -ENOMEM; |
e498be7da [PATCH] Numa-awar... |
3620 |
} |
1da177e4c Linux-2.6.12-rc2 |
3621 |
struct ccupdate_struct { |
343e0d7a9 [PATCH] slab: rep... |
3622 |
struct kmem_cache *cachep; |
acfe7d744 slab: remove one ... |
3623 |
struct array_cache *new[0]; |
1da177e4c Linux-2.6.12-rc2 |
3624 3625 3626 3627 |
}; static void do_ccupdate_local(void *info) { |
a737b3e2f [PATCH] slab cleanup |
3628 |
struct ccupdate_struct *new = info; |
1da177e4c Linux-2.6.12-rc2 |
3629 3630 3631 |
struct array_cache *old; check_irq_off(); |
9a2dba4b4 [PATCH] slab: ren... |
3632 |
old = cpu_cache_get(new->cachep); |
e498be7da [PATCH] Numa-awar... |
3633 |
|
1da177e4c Linux-2.6.12-rc2 |
3634 3635 3636 |
new->cachep->array[smp_processor_id()] = new->new[smp_processor_id()]; new->new[smp_processor_id()] = old; } |
18004c5d4 mm, sl[aou]b: Use... |
3637 |
/* Always called with the slab_mutex held */ |
943a451a8 slab: propagate t... |
3638 |
static int __do_tune_cpucache(struct kmem_cache *cachep, int limit, |
83b519e8b slab: setup alloc... |
3639 |
int batchcount, int shared, gfp_t gfp) |
1da177e4c Linux-2.6.12-rc2 |
3640 |
{ |
d2e7b7d0a [PATCH] fix poten... |
3641 |
struct ccupdate_struct *new; |
2ed3a4ef9 [PATCH] slab: do ... |
3642 |
int i; |
1da177e4c Linux-2.6.12-rc2 |
3643 |
|
acfe7d744 slab: remove one ... |
3644 3645 |
new = kzalloc(sizeof(*new) + nr_cpu_ids * sizeof(struct array_cache *), gfp); |
d2e7b7d0a [PATCH] fix poten... |
3646 3647 |
if (!new) return -ENOMEM; |
e498be7da [PATCH] Numa-awar... |
3648 |
for_each_online_cpu(i) { |
7d6e6d09d numa: slab: use n... |
3649 |
new->new[i] = alloc_arraycache(cpu_to_mem(i), limit, |
83b519e8b slab: setup alloc... |
3650 |
batchcount, gfp); |
d2e7b7d0a [PATCH] fix poten... |
3651 |
if (!new->new[i]) { |
b28a02de8 [PATCH] slab: fix... |
3652 |
for (i--; i >= 0; i--) |
d2e7b7d0a [PATCH] fix poten... |
3653 3654 |
kfree(new->new[i]); kfree(new); |
e498be7da [PATCH] Numa-awar... |
3655 |
return -ENOMEM; |
1da177e4c Linux-2.6.12-rc2 |
3656 3657 |
} } |
d2e7b7d0a [PATCH] fix poten... |
3658 |
new->cachep = cachep; |
1da177e4c Linux-2.6.12-rc2 |
3659 |
|
15c8b6c1a on_each_cpu(): ki... |
3660 |
on_each_cpu(do_ccupdate_local, (void *)new, 1); |
e498be7da [PATCH] Numa-awar... |
3661 |
|
1da177e4c Linux-2.6.12-rc2 |
3662 |
check_irq_on(); |
1da177e4c Linux-2.6.12-rc2 |
3663 3664 |
cachep->batchcount = batchcount; cachep->limit = limit; |
e498be7da [PATCH] Numa-awar... |
3665 |
cachep->shared = shared; |
1da177e4c Linux-2.6.12-rc2 |
3666 |
|
e498be7da [PATCH] Numa-awar... |
3667 |
for_each_online_cpu(i) { |
d2e7b7d0a [PATCH] fix poten... |
3668 |
struct array_cache *ccold = new->new[i]; |
1da177e4c Linux-2.6.12-rc2 |
3669 3670 |
if (!ccold) continue; |
6a67368c3 slab: Rename node... |
3671 |
spin_lock_irq(&cachep->node[cpu_to_mem(i)]->list_lock); |
7d6e6d09d numa: slab: use n... |
3672 |
free_block(cachep, ccold->entry, ccold->avail, cpu_to_mem(i)); |
6a67368c3 slab: Rename node... |
3673 |
spin_unlock_irq(&cachep->node[cpu_to_mem(i)]->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
3674 3675 |
kfree(ccold); } |
d2e7b7d0a [PATCH] fix poten... |
3676 |
kfree(new); |
5f0985bb1 mm/slab.c: cleanu... |
3677 |
return alloc_kmem_cache_node(cachep, gfp); |
1da177e4c Linux-2.6.12-rc2 |
3678 |
} |
943a451a8 slab: propagate t... |
3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 |
static int do_tune_cpucache(struct kmem_cache *cachep, int limit, int batchcount, int shared, gfp_t gfp) { int ret; struct kmem_cache *c = NULL; int i = 0; ret = __do_tune_cpucache(cachep, limit, batchcount, shared, gfp); if (slab_state < FULL) return ret; if ((ret < 0) || !is_root_cache(cachep)) return ret; |
ebe945c27 memcg: add commen... |
3693 |
VM_BUG_ON(!mutex_is_locked(&slab_mutex)); |
943a451a8 slab: propagate t... |
3694 |
for_each_memcg_cache_index(i) { |
2ade4de87 memcg, kmem: rena... |
3695 |
c = cache_from_memcg_idx(cachep, i); |
943a451a8 slab: propagate t... |
3696 3697 3698 3699 3700 3701 3702 |
if (c) /* return value determined by the parent cache only */ __do_tune_cpucache(c, limit, batchcount, shared, gfp); } return ret; } |
18004c5d4 mm, sl[aou]b: Use... |
3703 |
/* Called with slab_mutex held always */ |
83b519e8b slab: setup alloc... |
3704 |
static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp) |
1da177e4c Linux-2.6.12-rc2 |
3705 3706 |
{ int err; |
943a451a8 slab: propagate t... |
3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 |
int limit = 0; int shared = 0; int batchcount = 0; if (!is_root_cache(cachep)) { struct kmem_cache *root = memcg_root_cache(cachep); limit = root->limit; shared = root->shared; batchcount = root->batchcount; } |
1da177e4c Linux-2.6.12-rc2 |
3717 |
|
943a451a8 slab: propagate t... |
3718 3719 |
if (limit && shared && batchcount) goto skip_setup; |
a737b3e2f [PATCH] slab cleanup |
3720 3721 |
/* * The head array serves three purposes: |
1da177e4c Linux-2.6.12-rc2 |
3722 3723 |
* - create a LIFO ordering, i.e. return objects that are cache-warm * - reduce the number of spinlock operations. |
a737b3e2f [PATCH] slab cleanup |
3724 |
* - reduce the number of linked list operations on the slab and |
1da177e4c Linux-2.6.12-rc2 |
3725 3726 3727 3728 |
* bufctl chains: array operations are cheaper. * The numbers are guessed, we should auto-tune as described by * Bonwick. */ |
3b0efdfa1 mm, sl[aou]b: Ext... |
3729 |
if (cachep->size > 131072) |
1da177e4c Linux-2.6.12-rc2 |
3730 |
limit = 1; |
3b0efdfa1 mm, sl[aou]b: Ext... |
3731 |
else if (cachep->size > PAGE_SIZE) |
1da177e4c Linux-2.6.12-rc2 |
3732 |
limit = 8; |
3b0efdfa1 mm, sl[aou]b: Ext... |
3733 |
else if (cachep->size > 1024) |
1da177e4c Linux-2.6.12-rc2 |
3734 |
limit = 24; |
3b0efdfa1 mm, sl[aou]b: Ext... |
3735 |
else if (cachep->size > 256) |
1da177e4c Linux-2.6.12-rc2 |
3736 3737 3738 |
limit = 54; else limit = 120; |
a737b3e2f [PATCH] slab cleanup |
3739 3740 |
/* * CPU bound tasks (e.g. network routing) can exhibit cpu bound |
1da177e4c Linux-2.6.12-rc2 |
3741 3742 3743 3744 3745 3746 3747 3748 |
* allocation behaviour: Most allocs on one cpu, most free operations * on another cpu. For these cases, an efficient object passing between * cpus is necessary. This is provided by a shared array. The array * replaces Bonwick's magazine layer. * On uniprocessor, it's functionally equivalent (but less efficient) * to a larger limit. Thus disabled by default. */ shared = 0; |
3b0efdfa1 mm, sl[aou]b: Ext... |
3749 |
if (cachep->size <= PAGE_SIZE && num_possible_cpus() > 1) |
1da177e4c Linux-2.6.12-rc2 |
3750 |
shared = 8; |
1da177e4c Linux-2.6.12-rc2 |
3751 3752 |
#if DEBUG |
a737b3e2f [PATCH] slab cleanup |
3753 3754 3755 |
/* * With debugging enabled, large batchcount lead to excessively long * periods with disabled local interrupts. Limit the batchcount |
1da177e4c Linux-2.6.12-rc2 |
3756 3757 3758 3759 |
*/ if (limit > 32) limit = 32; #endif |
943a451a8 slab: propagate t... |
3760 3761 3762 |
batchcount = (limit + 1) / 2; skip_setup: err = do_tune_cpucache(cachep, limit, batchcount, shared, gfp); |
1da177e4c Linux-2.6.12-rc2 |
3763 3764 3765 |
if (err) printk(KERN_ERR "enable_cpucache failed for %s, error %d. ", |
b28a02de8 [PATCH] slab: fix... |
3766 |
cachep->name, -err); |
2ed3a4ef9 [PATCH] slab: do ... |
3767 |
return err; |
1da177e4c Linux-2.6.12-rc2 |
3768 |
} |
1b55253a7 [PATCH] slab: rem... |
3769 |
/* |
ce8eb6c42 slab: Rename list... |
3770 3771 |
* Drain an array if it contains any elements taking the node lock only if * necessary. Note that the node listlock also protects the array_cache |
b18e7e654 [PATCH] slab: fix... |
3772 |
* if drain_array() is used on the shared array. |
1b55253a7 [PATCH] slab: rem... |
3773 |
*/ |
ce8eb6c42 slab: Rename list... |
3774 |
static void drain_array(struct kmem_cache *cachep, struct kmem_cache_node *n, |
1b55253a7 [PATCH] slab: rem... |
3775 |
struct array_cache *ac, int force, int node) |
1da177e4c Linux-2.6.12-rc2 |
3776 3777 |
{ int tofree; |
1b55253a7 [PATCH] slab: rem... |
3778 3779 |
if (!ac || !ac->avail) return; |
1da177e4c Linux-2.6.12-rc2 |
3780 3781 |
if (ac->touched && !force) { ac->touched = 0; |
b18e7e654 [PATCH] slab: fix... |
3782 |
} else { |
ce8eb6c42 slab: Rename list... |
3783 |
spin_lock_irq(&n->list_lock); |
b18e7e654 [PATCH] slab: fix... |
3784 3785 3786 3787 3788 3789 3790 3791 3792 |
if (ac->avail) { tofree = force ? ac->avail : (ac->limit + 4) / 5; if (tofree > ac->avail) tofree = (ac->avail + 1) / 2; free_block(cachep, ac->entry, tofree, node); ac->avail -= tofree; memmove(ac->entry, &(ac->entry[tofree]), sizeof(void *) * ac->avail); } |
ce8eb6c42 slab: Rename list... |
3793 |
spin_unlock_irq(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
3794 3795 3796 3797 3798 |
} } /** * cache_reap - Reclaim memory from caches. |
05fb6bf0b [PATCH] kernel-do... |
3799 |
* @w: work descriptor |
1da177e4c Linux-2.6.12-rc2 |
3800 3801 3802 3803 3804 3805 |
* * Called from workqueue/eventd every few seconds. * Purpose: * - clear the per-cpu caches for this CPU. * - return freeable pages to the main free memory pool. * |
a737b3e2f [PATCH] slab cleanup |
3806 3807 |
* If we cannot acquire the cache chain mutex then just give up - we'll try * again on the next iteration. |
1da177e4c Linux-2.6.12-rc2 |
3808 |
*/ |
7c5cae368 [PATCH] slab: use... |
3809 |
static void cache_reap(struct work_struct *w) |
1da177e4c Linux-2.6.12-rc2 |
3810 |
{ |
7a7c381d2 [PATCH] slab: sto... |
3811 |
struct kmem_cache *searchp; |
ce8eb6c42 slab: Rename list... |
3812 |
struct kmem_cache_node *n; |
7d6e6d09d numa: slab: use n... |
3813 |
int node = numa_mem_id(); |
bf6aede71 workqueue: add to... |
3814 |
struct delayed_work *work = to_delayed_work(w); |
1da177e4c Linux-2.6.12-rc2 |
3815 |
|
18004c5d4 mm, sl[aou]b: Use... |
3816 |
if (!mutex_trylock(&slab_mutex)) |
1da177e4c Linux-2.6.12-rc2 |
3817 |
/* Give up. Setup the next iteration. */ |
7c5cae368 [PATCH] slab: use... |
3818 |
goto out; |
1da177e4c Linux-2.6.12-rc2 |
3819 |
|
18004c5d4 mm, sl[aou]b: Use... |
3820 |
list_for_each_entry(searchp, &slab_caches, list) { |
1da177e4c Linux-2.6.12-rc2 |
3821 |
check_irq_on(); |
35386e3b0 [PATCH] slab: cac... |
3822 |
/* |
ce8eb6c42 slab: Rename list... |
3823 |
* We only take the node lock if absolutely necessary and we |
35386e3b0 [PATCH] slab: cac... |
3824 3825 3826 |
* have established with reasonable certainty that * we can do some work if the lock was obtained. */ |
ce8eb6c42 slab: Rename list... |
3827 |
n = searchp->node[node]; |
35386e3b0 [PATCH] slab: cac... |
3828 |
|
ce8eb6c42 slab: Rename list... |
3829 |
reap_alien(searchp, n); |
1da177e4c Linux-2.6.12-rc2 |
3830 |
|
ce8eb6c42 slab: Rename list... |
3831 |
drain_array(searchp, n, cpu_cache_get(searchp), 0, node); |
1da177e4c Linux-2.6.12-rc2 |
3832 |
|
35386e3b0 [PATCH] slab: cac... |
3833 3834 3835 3836 |
/* * These are racy checks but it does not matter * if we skip one check or scan twice. */ |
ce8eb6c42 slab: Rename list... |
3837 |
if (time_after(n->next_reap, jiffies)) |
35386e3b0 [PATCH] slab: cac... |
3838 |
goto next; |
1da177e4c Linux-2.6.12-rc2 |
3839 |
|
5f0985bb1 mm/slab.c: cleanu... |
3840 |
n->next_reap = jiffies + REAPTIMEOUT_NODE; |
1da177e4c Linux-2.6.12-rc2 |
3841 |
|
ce8eb6c42 slab: Rename list... |
3842 |
drain_array(searchp, n, n->shared, 0, node); |
1da177e4c Linux-2.6.12-rc2 |
3843 |
|
ce8eb6c42 slab: Rename list... |
3844 3845 |
if (n->free_touched) n->free_touched = 0; |
ed11d9eb2 [PATCH] slab: con... |
3846 3847 |
else { int freed; |
1da177e4c Linux-2.6.12-rc2 |
3848 |
|
ce8eb6c42 slab: Rename list... |
3849 |
freed = drain_freelist(searchp, n, (n->free_limit + |
ed11d9eb2 [PATCH] slab: con... |
3850 3851 3852 |
5 * searchp->num - 1) / (5 * searchp->num)); STATS_ADD_REAPED(searchp, freed); } |
35386e3b0 [PATCH] slab: cac... |
3853 |
next: |
1da177e4c Linux-2.6.12-rc2 |
3854 3855 3856 |
cond_resched(); } check_irq_on(); |
18004c5d4 mm, sl[aou]b: Use... |
3857 |
mutex_unlock(&slab_mutex); |
8fce4d8e3 [PATCH] slab: Nod... |
3858 |
next_reap_node(); |
7c5cae368 [PATCH] slab: use... |
3859 |
out: |
a737b3e2f [PATCH] slab cleanup |
3860 |
/* Set up the next iteration */ |
5f0985bb1 mm/slab.c: cleanu... |
3861 |
schedule_delayed_work(work, round_jiffies_relative(REAPTIMEOUT_AC)); |
1da177e4c Linux-2.6.12-rc2 |
3862 |
} |
158a96242 Unify /proc/slabi... |
3863 |
#ifdef CONFIG_SLABINFO |
0d7561c61 sl[au]b: Process ... |
3864 |
void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo) |
1da177e4c Linux-2.6.12-rc2 |
3865 |
{ |
8456a648c slab: use struct ... |
3866 |
struct page *page; |
b28a02de8 [PATCH] slab: fix... |
3867 3868 3869 3870 |
unsigned long active_objs; unsigned long num_objs; unsigned long active_slabs = 0; unsigned long num_slabs, free_objects = 0, shared_avail = 0; |
e498be7da [PATCH] Numa-awar... |
3871 |
const char *name; |
1da177e4c Linux-2.6.12-rc2 |
3872 |
char *error = NULL; |
e498be7da [PATCH] Numa-awar... |
3873 |
int node; |
ce8eb6c42 slab: Rename list... |
3874 |
struct kmem_cache_node *n; |
1da177e4c Linux-2.6.12-rc2 |
3875 |
|
1da177e4c Linux-2.6.12-rc2 |
3876 3877 |
active_objs = 0; num_slabs = 0; |
e498be7da [PATCH] Numa-awar... |
3878 |
for_each_online_node(node) { |
ce8eb6c42 slab: Rename list... |
3879 3880 |
n = cachep->node[node]; if (!n) |
e498be7da [PATCH] Numa-awar... |
3881 |
continue; |
ca3b9b917 [PATCH] NUMA slab... |
3882 |
check_irq_on(); |
ce8eb6c42 slab: Rename list... |
3883 |
spin_lock_irq(&n->list_lock); |
e498be7da [PATCH] Numa-awar... |
3884 |
|
8456a648c slab: use struct ... |
3885 3886 |
list_for_each_entry(page, &n->slabs_full, lru) { if (page->active != cachep->num && !error) |
e498be7da [PATCH] Numa-awar... |
3887 3888 3889 3890 |
error = "slabs_full accounting error"; active_objs += cachep->num; active_slabs++; } |
8456a648c slab: use struct ... |
3891 3892 |
list_for_each_entry(page, &n->slabs_partial, lru) { if (page->active == cachep->num && !error) |
106a74e13 slab: replace fre... |
3893 |
error = "slabs_partial accounting error"; |
8456a648c slab: use struct ... |
3894 |
if (!page->active && !error) |
106a74e13 slab: replace fre... |
3895 |
error = "slabs_partial accounting error"; |
8456a648c slab: use struct ... |
3896 |
active_objs += page->active; |
e498be7da [PATCH] Numa-awar... |
3897 3898 |
active_slabs++; } |
8456a648c slab: use struct ... |
3899 3900 |
list_for_each_entry(page, &n->slabs_free, lru) { if (page->active && !error) |
106a74e13 slab: replace fre... |
3901 |
error = "slabs_free accounting error"; |
e498be7da [PATCH] Numa-awar... |
3902 3903 |
num_slabs++; } |
ce8eb6c42 slab: Rename list... |
3904 3905 3906 |
free_objects += n->free_objects; if (n->shared) shared_avail += n->shared->avail; |
e498be7da [PATCH] Numa-awar... |
3907 |
|
ce8eb6c42 slab: Rename list... |
3908 |
spin_unlock_irq(&n->list_lock); |
1da177e4c Linux-2.6.12-rc2 |
3909 |
} |
b28a02de8 [PATCH] slab: fix... |
3910 3911 |
num_slabs += active_slabs; num_objs = num_slabs * cachep->num; |
e498be7da [PATCH] Numa-awar... |
3912 |
if (num_objs - active_objs != free_objects && !error) |
1da177e4c Linux-2.6.12-rc2 |
3913 |
error = "free_objects accounting error"; |
b28a02de8 [PATCH] slab: fix... |
3914 |
name = cachep->name; |
1da177e4c Linux-2.6.12-rc2 |
3915 3916 3917 |
if (error) printk(KERN_ERR "slab: cache %s error: %s ", name, error); |
0d7561c61 sl[au]b: Process ... |
3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 |
sinfo->active_objs = active_objs; sinfo->num_objs = num_objs; sinfo->active_slabs = active_slabs; sinfo->num_slabs = num_slabs; sinfo->shared_avail = shared_avail; sinfo->limit = cachep->limit; sinfo->batchcount = cachep->batchcount; sinfo->shared = cachep->shared; sinfo->objects_per_slab = cachep->num; sinfo->cache_order = cachep->gfporder; } void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep) { |
1da177e4c Linux-2.6.12-rc2 |
3932 |
#if STATS |
ce8eb6c42 slab: Rename list... |
3933 |
{ /* node stats */ |
1da177e4c Linux-2.6.12-rc2 |
3934 3935 3936 3937 3938 3939 |
unsigned long high = cachep->high_mark; unsigned long allocs = cachep->num_allocations; unsigned long grown = cachep->grown; unsigned long reaped = cachep->reaped; unsigned long errors = cachep->errors; unsigned long max_freeable = cachep->max_freeable; |
1da177e4c Linux-2.6.12-rc2 |
3940 |
unsigned long node_allocs = cachep->node_allocs; |
e498be7da [PATCH] Numa-awar... |
3941 |
unsigned long node_frees = cachep->node_frees; |
fb7faf331 [PATCH] slab: add... |
3942 |
unsigned long overflows = cachep->node_overflow; |
1da177e4c Linux-2.6.12-rc2 |
3943 |
|
e92dd4fd1 slab: Fix continu... |
3944 3945 3946 3947 3948 |
seq_printf(m, " : globalstat %7lu %6lu %5lu %4lu " "%4lu %4lu %4lu %4lu %4lu", allocs, high, grown, reaped, errors, max_freeable, node_allocs, node_frees, overflows); |
1da177e4c Linux-2.6.12-rc2 |
3949 3950 3951 3952 3953 3954 3955 3956 3957 |
} /* cpu stats */ { unsigned long allochit = atomic_read(&cachep->allochit); unsigned long allocmiss = atomic_read(&cachep->allocmiss); unsigned long freehit = atomic_read(&cachep->freehit); unsigned long freemiss = atomic_read(&cachep->freemiss); seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu", |
b28a02de8 [PATCH] slab: fix... |
3958 |
allochit, allocmiss, freehit, freemiss); |
1da177e4c Linux-2.6.12-rc2 |
3959 3960 |
} #endif |
1da177e4c Linux-2.6.12-rc2 |
3961 |
} |
1da177e4c Linux-2.6.12-rc2 |
3962 3963 3964 3965 3966 3967 3968 3969 |
#define MAX_SLABINFO_WRITE 128 /** * slabinfo_write - Tuning for the slab allocator * @file: unused * @buffer: user buffer * @count: data length * @ppos: unused */ |
b7454ad3c mm/sl[au]b: Move ... |
3970 |
ssize_t slabinfo_write(struct file *file, const char __user *buffer, |
b28a02de8 [PATCH] slab: fix... |
3971 |
size_t count, loff_t *ppos) |
1da177e4c Linux-2.6.12-rc2 |
3972 |
{ |
b28a02de8 [PATCH] slab: fix... |
3973 |
char kbuf[MAX_SLABINFO_WRITE + 1], *tmp; |
1da177e4c Linux-2.6.12-rc2 |
3974 |
int limit, batchcount, shared, res; |
7a7c381d2 [PATCH] slab: sto... |
3975 |
struct kmem_cache *cachep; |
b28a02de8 [PATCH] slab: fix... |
3976 |
|
1da177e4c Linux-2.6.12-rc2 |
3977 3978 3979 3980 |
if (count > MAX_SLABINFO_WRITE) return -EINVAL; if (copy_from_user(&kbuf, buffer, count)) return -EFAULT; |
b28a02de8 [PATCH] slab: fix... |
3981 |
kbuf[MAX_SLABINFO_WRITE] = '\0'; |
1da177e4c Linux-2.6.12-rc2 |
3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 |
tmp = strchr(kbuf, ' '); if (!tmp) return -EINVAL; *tmp = '\0'; tmp++; if (sscanf(tmp, " %d %d %d", &limit, &batchcount, &shared) != 3) return -EINVAL; /* Find the cache in the chain of caches. */ |
18004c5d4 mm, sl[aou]b: Use... |
3992 |
mutex_lock(&slab_mutex); |
1da177e4c Linux-2.6.12-rc2 |
3993 |
res = -EINVAL; |
18004c5d4 mm, sl[aou]b: Use... |
3994 |
list_for_each_entry(cachep, &slab_caches, list) { |
1da177e4c Linux-2.6.12-rc2 |
3995 |
if (!strcmp(cachep->name, kbuf)) { |
a737b3e2f [PATCH] slab cleanup |
3996 3997 |
if (limit < 1 || batchcount < 1 || batchcount > limit || shared < 0) { |
e498be7da [PATCH] Numa-awar... |
3998 |
res = 0; |
1da177e4c Linux-2.6.12-rc2 |
3999 |
} else { |
e498be7da [PATCH] Numa-awar... |
4000 |
res = do_tune_cpucache(cachep, limit, |
83b519e8b slab: setup alloc... |
4001 4002 |
batchcount, shared, GFP_KERNEL); |
1da177e4c Linux-2.6.12-rc2 |
4003 4004 4005 4006 |
} break; } } |
18004c5d4 mm, sl[aou]b: Use... |
4007 |
mutex_unlock(&slab_mutex); |
1da177e4c Linux-2.6.12-rc2 |
4008 4009 4010 4011 |
if (res >= 0) res = count; return res; } |
871751e25 [PATCH] slab: imp... |
4012 4013 4014 4015 4016 |
#ifdef CONFIG_DEBUG_SLAB_LEAK static void *leaks_start(struct seq_file *m, loff_t *pos) { |
18004c5d4 mm, sl[aou]b: Use... |
4017 4018 |
mutex_lock(&slab_mutex); return seq_list_start(&slab_caches, *pos); |
871751e25 [PATCH] slab: imp... |
4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 |
} static inline int add_caller(unsigned long *n, unsigned long v) { unsigned long *p; int l; if (!v) return 1; l = n[1]; p = n + 2; while (l) { int i = l/2; unsigned long *q = p + 2 * i; if (*q == v) { q[1]++; return 1; } if (*q > v) { l = i; } else { p = q + 2; l -= i + 1; } } if (++n[1] == n[0]) return 0; memmove(p + 2, p, n[1] * 2 * sizeof(unsigned long) - ((void *)p - (void *)n)); p[0] = v; p[1] = 1; return 1; } |
8456a648c slab: use struct ... |
4050 4051 |
static void handle_slab(unsigned long *n, struct kmem_cache *c, struct page *page) |
871751e25 [PATCH] slab: imp... |
4052 4053 |
{ void *p; |
b1cb0982b slab: change the ... |
4054 |
int i, j; |
871751e25 [PATCH] slab: imp... |
4055 4056 |
if (n[0] == n[1]) return; |
8456a648c slab: use struct ... |
4057 |
for (i = 0, p = page->s_mem; i < c->num; i++, p += c->size) { |
b1cb0982b slab: change the ... |
4058 |
bool active = true; |
8456a648c slab: use struct ... |
4059 |
for (j = page->active; j < c->num; j++) { |
b1cb0982b slab: change the ... |
4060 |
/* Skip freed item */ |
e5c58dfdc slab: introduce h... |
4061 |
if (get_free_obj(page, j) == i) { |
b1cb0982b slab: change the ... |
4062 4063 4064 4065 4066 |
active = false; break; } } if (!active) |
871751e25 [PATCH] slab: imp... |
4067 |
continue; |
b1cb0982b slab: change the ... |
4068 |
|
871751e25 [PATCH] slab: imp... |
4069 4070 4071 4072 4073 4074 4075 4076 |
if (!add_caller(n, (unsigned long)*dbg_userword(c, p))) return; } } static void show_symbol(struct seq_file *m, unsigned long address) { #ifdef CONFIG_KALLSYMS |
871751e25 [PATCH] slab: imp... |
4077 |
unsigned long offset, size; |
9281acea6 kallsyms: make KS... |
4078 |
char modname[MODULE_NAME_LEN], name[KSYM_NAME_LEN]; |
871751e25 [PATCH] slab: imp... |
4079 |
|
a5c43dae7 Fix race between ... |
4080 |
if (lookup_symbol_attrs(address, &size, &offset, modname, name) == 0) { |
871751e25 [PATCH] slab: imp... |
4081 |
seq_printf(m, "%s+%#lx/%#lx", name, offset, size); |
a5c43dae7 Fix race between ... |
4082 |
if (modname[0]) |
871751e25 [PATCH] slab: imp... |
4083 4084 4085 4086 4087 4088 4089 4090 4091 |
seq_printf(m, " [%s]", modname); return; } #endif seq_printf(m, "%p", (void *)address); } static int leaks_show(struct seq_file *m, void *p) { |
0672aa7c2 mm, slab: Build f... |
4092 |
struct kmem_cache *cachep = list_entry(p, struct kmem_cache, list); |
8456a648c slab: use struct ... |
4093 |
struct page *page; |
ce8eb6c42 slab: Rename list... |
4094 |
struct kmem_cache_node *n; |
871751e25 [PATCH] slab: imp... |
4095 |
const char *name; |
db8450673 slab: Fixup CONFI... |
4096 |
unsigned long *x = m->private; |
871751e25 [PATCH] slab: imp... |
4097 4098 4099 4100 4101 4102 4103 4104 4105 |
int node; int i; if (!(cachep->flags & SLAB_STORE_USER)) return 0; if (!(cachep->flags & SLAB_RED_ZONE)) return 0; /* OK, we can do it */ |
db8450673 slab: Fixup CONFI... |
4106 |
x[1] = 0; |
871751e25 [PATCH] slab: imp... |
4107 4108 |
for_each_online_node(node) { |
ce8eb6c42 slab: Rename list... |
4109 4110 |
n = cachep->node[node]; if (!n) |
871751e25 [PATCH] slab: imp... |
4111 4112 4113 |
continue; check_irq_on(); |
ce8eb6c42 slab: Rename list... |
4114 |
spin_lock_irq(&n->list_lock); |
871751e25 [PATCH] slab: imp... |
4115 |
|
8456a648c slab: use struct ... |
4116 4117 4118 4119 |
list_for_each_entry(page, &n->slabs_full, lru) handle_slab(x, cachep, page); list_for_each_entry(page, &n->slabs_partial, lru) handle_slab(x, cachep, page); |
ce8eb6c42 slab: Rename list... |
4120 |
spin_unlock_irq(&n->list_lock); |
871751e25 [PATCH] slab: imp... |
4121 4122 |
} name = cachep->name; |
db8450673 slab: Fixup CONFI... |
4123 |
if (x[0] == x[1]) { |
871751e25 [PATCH] slab: imp... |
4124 |
/* Increase the buffer size */ |
18004c5d4 mm, sl[aou]b: Use... |
4125 |
mutex_unlock(&slab_mutex); |
db8450673 slab: Fixup CONFI... |
4126 |
m->private = kzalloc(x[0] * 4 * sizeof(unsigned long), GFP_KERNEL); |
871751e25 [PATCH] slab: imp... |
4127 4128 |
if (!m->private) { /* Too bad, we are really out */ |
db8450673 slab: Fixup CONFI... |
4129 |
m->private = x; |
18004c5d4 mm, sl[aou]b: Use... |
4130 |
mutex_lock(&slab_mutex); |
871751e25 [PATCH] slab: imp... |
4131 4132 |
return -ENOMEM; } |
db8450673 slab: Fixup CONFI... |
4133 4134 |
*(unsigned long *)m->private = x[0] * 2; kfree(x); |
18004c5d4 mm, sl[aou]b: Use... |
4135 |
mutex_lock(&slab_mutex); |
871751e25 [PATCH] slab: imp... |
4136 4137 4138 4139 |
/* Now make sure this entry will be retried */ m->count = m->size; return 0; } |
db8450673 slab: Fixup CONFI... |
4140 4141 4142 |
for (i = 0; i < x[1]; i++) { seq_printf(m, "%s: %lu ", name, x[2*i+3]); show_symbol(m, x[2*i+2]); |
871751e25 [PATCH] slab: imp... |
4143 4144 4145 |
seq_putc(m, ' '); } |
d2e7b7d0a [PATCH] fix poten... |
4146 |
|
871751e25 [PATCH] slab: imp... |
4147 4148 |
return 0; } |
a0ec95a8e proc: move /proc/... |
4149 |
static const struct seq_operations slabstats_op = { |
871751e25 [PATCH] slab: imp... |
4150 |
.start = leaks_start, |
276a2439c mm/slab: Give s_n... |
4151 4152 |
.next = slab_next, .stop = slab_stop, |
871751e25 [PATCH] slab: imp... |
4153 4154 |
.show = leaks_show, }; |
a0ec95a8e proc: move /proc/... |
4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 |
static int slabstats_open(struct inode *inode, struct file *file) { unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL); int ret = -ENOMEM; if (n) { ret = seq_open(file, &slabstats_op); if (!ret) { struct seq_file *m = file->private_data; *n = PAGE_SIZE / (2 * sizeof(unsigned long)); m->private = n; n = NULL; } kfree(n); } return ret; } static const struct file_operations proc_slabstats_operations = { .open = slabstats_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_private, }; #endif static int __init slab_proc_init(void) { #ifdef CONFIG_DEBUG_SLAB_LEAK proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations); |
871751e25 [PATCH] slab: imp... |
4185 |
#endif |
a0ec95a8e proc: move /proc/... |
4186 4187 4188 |
return 0; } module_init(slab_proc_init); |
1da177e4c Linux-2.6.12-rc2 |
4189 |
#endif |
00e145b6d [PATCH] slab: rem... |
4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 |
/** * ksize - get the actual amount of memory allocated for a given object * @objp: Pointer to the object * * kmalloc may internally round up allocations and return more memory * than requested. ksize() can be used to determine the actual amount of * memory allocated. The caller may use this additional memory, even though * a smaller amount of memory was initially specified with the kmalloc call. * The caller must guarantee that objp points to a valid object previously * allocated with either kmalloc() or kmem_cache_alloc(). The object * must not be freed during the duration of the call. */ |
fd76bab2f slab: introduce k... |
4202 |
size_t ksize(const void *objp) |
1da177e4c Linux-2.6.12-rc2 |
4203 |
{ |
ef8b4520b Slab allocators: ... |
4204 4205 |
BUG_ON(!objp); if (unlikely(objp == ZERO_SIZE_PTR)) |
00e145b6d [PATCH] slab: rem... |
4206 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
4207 |
|
8c138bc00 slab: Get rid of ... |
4208 |
return virt_to_cache(objp)->object_size; |
1da177e4c Linux-2.6.12-rc2 |
4209 |
} |
b1aabecd5 mm: Export symbol... |
4210 |
EXPORT_SYMBOL(ksize); |