1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Written by Mark Hemment, 1996 (markhe@nextd.demon.co.uk).
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * (C) SGI 2006, Christoph Lameter
6*4882a593Smuzhiyun * Cleaned up and restructured to ease the addition of alternative
7*4882a593Smuzhiyun * implementations of SLAB allocators.
8*4882a593Smuzhiyun * (C) Linux Foundation 2008-2013
9*4882a593Smuzhiyun * Unified interface for all slab allocators
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #ifndef _LINUX_SLAB_H
13*4882a593Smuzhiyun #define _LINUX_SLAB_H
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <linux/gfp.h>
16*4882a593Smuzhiyun #include <linux/overflow.h>
17*4882a593Smuzhiyun #include <linux/types.h>
18*4882a593Smuzhiyun #include <linux/workqueue.h>
19*4882a593Smuzhiyun #include <linux/percpu-refcount.h>
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun * Flags to pass to kmem_cache_create().
24*4882a593Smuzhiyun * The ones marked DEBUG are only valid if CONFIG_DEBUG_SLAB is set.
25*4882a593Smuzhiyun */
26*4882a593Smuzhiyun /* DEBUG: Perform (expensive) checks on alloc/free */
27*4882a593Smuzhiyun #define SLAB_CONSISTENCY_CHECKS ((slab_flags_t __force)0x00000100U)
28*4882a593Smuzhiyun /* DEBUG: Red zone objs in a cache */
29*4882a593Smuzhiyun #define SLAB_RED_ZONE ((slab_flags_t __force)0x00000400U)
30*4882a593Smuzhiyun /* DEBUG: Poison objects */
31*4882a593Smuzhiyun #define SLAB_POISON ((slab_flags_t __force)0x00000800U)
32*4882a593Smuzhiyun /* Align objs on cache lines */
33*4882a593Smuzhiyun #define SLAB_HWCACHE_ALIGN ((slab_flags_t __force)0x00002000U)
34*4882a593Smuzhiyun /* Use GFP_DMA memory */
35*4882a593Smuzhiyun #define SLAB_CACHE_DMA ((slab_flags_t __force)0x00004000U)
36*4882a593Smuzhiyun /* Use GFP_DMA32 memory */
37*4882a593Smuzhiyun #define SLAB_CACHE_DMA32 ((slab_flags_t __force)0x00008000U)
38*4882a593Smuzhiyun /* DEBUG: Store the last owner for bug hunting */
39*4882a593Smuzhiyun #define SLAB_STORE_USER ((slab_flags_t __force)0x00010000U)
40*4882a593Smuzhiyun /* Panic if kmem_cache_create() fails */
41*4882a593Smuzhiyun #define SLAB_PANIC ((slab_flags_t __force)0x00040000U)
42*4882a593Smuzhiyun /*
43*4882a593Smuzhiyun * SLAB_TYPESAFE_BY_RCU - **WARNING** READ THIS!
44*4882a593Smuzhiyun *
45*4882a593Smuzhiyun * This delays freeing the SLAB page by a grace period, it does _NOT_
46*4882a593Smuzhiyun * delay object freeing. This means that if you do kmem_cache_free()
47*4882a593Smuzhiyun * that memory location is free to be reused at any time. Thus it may
48*4882a593Smuzhiyun * be possible to see another object there in the same RCU grace period.
49*4882a593Smuzhiyun *
50*4882a593Smuzhiyun * This feature only ensures the memory location backing the object
51*4882a593Smuzhiyun * stays valid, the trick to using this is relying on an independent
52*4882a593Smuzhiyun * object validation pass. Something like:
53*4882a593Smuzhiyun *
54*4882a593Smuzhiyun * rcu_read_lock()
55*4882a593Smuzhiyun * again:
56*4882a593Smuzhiyun * obj = lockless_lookup(key);
57*4882a593Smuzhiyun * if (obj) {
58*4882a593Smuzhiyun * if (!try_get_ref(obj)) // might fail for free objects
59*4882a593Smuzhiyun * goto again;
60*4882a593Smuzhiyun *
61*4882a593Smuzhiyun * if (obj->key != key) { // not the object we expected
62*4882a593Smuzhiyun * put_ref(obj);
63*4882a593Smuzhiyun * goto again;
64*4882a593Smuzhiyun * }
65*4882a593Smuzhiyun * }
66*4882a593Smuzhiyun * rcu_read_unlock();
67*4882a593Smuzhiyun *
68*4882a593Smuzhiyun * This is useful if we need to approach a kernel structure obliquely,
69*4882a593Smuzhiyun * from its address obtained without the usual locking. We can lock
70*4882a593Smuzhiyun * the structure to stabilize it and check it's still at the given address,
71*4882a593Smuzhiyun * only if we can be sure that the memory has not been meanwhile reused
72*4882a593Smuzhiyun * for some other kind of object (which our subsystem's lock might corrupt).
73*4882a593Smuzhiyun *
74*4882a593Smuzhiyun * rcu_read_lock before reading the address, then rcu_read_unlock after
75*4882a593Smuzhiyun * taking the spinlock within the structure expected at that address.
76*4882a593Smuzhiyun *
77*4882a593Smuzhiyun * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
78*4882a593Smuzhiyun */
79*4882a593Smuzhiyun /* Defer freeing slabs to RCU */
80*4882a593Smuzhiyun #define SLAB_TYPESAFE_BY_RCU ((slab_flags_t __force)0x00080000U)
81*4882a593Smuzhiyun /* Spread some memory over cpuset */
82*4882a593Smuzhiyun #define SLAB_MEM_SPREAD ((slab_flags_t __force)0x00100000U)
83*4882a593Smuzhiyun /* Trace allocations and frees */
84*4882a593Smuzhiyun #define SLAB_TRACE ((slab_flags_t __force)0x00200000U)
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /* Flag to prevent checks on free */
87*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_OBJECTS
88*4882a593Smuzhiyun # define SLAB_DEBUG_OBJECTS ((slab_flags_t __force)0x00400000U)
89*4882a593Smuzhiyun #else
90*4882a593Smuzhiyun # define SLAB_DEBUG_OBJECTS 0
91*4882a593Smuzhiyun #endif
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun /* Avoid kmemleak tracing */
94*4882a593Smuzhiyun #define SLAB_NOLEAKTRACE ((slab_flags_t __force)0x00800000U)
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun /* Fault injection mark */
97*4882a593Smuzhiyun #ifdef CONFIG_FAILSLAB
98*4882a593Smuzhiyun # define SLAB_FAILSLAB ((slab_flags_t __force)0x02000000U)
99*4882a593Smuzhiyun #else
100*4882a593Smuzhiyun # define SLAB_FAILSLAB 0
101*4882a593Smuzhiyun #endif
102*4882a593Smuzhiyun /* Account to memcg */
103*4882a593Smuzhiyun #ifdef CONFIG_MEMCG_KMEM
104*4882a593Smuzhiyun # define SLAB_ACCOUNT ((slab_flags_t __force)0x04000000U)
105*4882a593Smuzhiyun #else
106*4882a593Smuzhiyun # define SLAB_ACCOUNT 0
107*4882a593Smuzhiyun #endif
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun #ifdef CONFIG_KASAN
110*4882a593Smuzhiyun #define SLAB_KASAN ((slab_flags_t __force)0x08000000U)
111*4882a593Smuzhiyun #else
112*4882a593Smuzhiyun #define SLAB_KASAN 0
113*4882a593Smuzhiyun #endif
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /* The following flags affect the page allocator grouping pages by mobility */
116*4882a593Smuzhiyun /* Objects are reclaimable */
117*4882a593Smuzhiyun #define SLAB_RECLAIM_ACCOUNT ((slab_flags_t __force)0x00020000U)
118*4882a593Smuzhiyun #define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun /* Slab deactivation flag */
121*4882a593Smuzhiyun #define SLAB_DEACTIVATED ((slab_flags_t __force)0x10000000U)
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun /*
124*4882a593Smuzhiyun * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.
125*4882a593Smuzhiyun *
126*4882a593Smuzhiyun * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault.
127*4882a593Smuzhiyun *
128*4882a593Smuzhiyun * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
129*4882a593Smuzhiyun * Both make kfree a no-op.
130*4882a593Smuzhiyun */
131*4882a593Smuzhiyun #define ZERO_SIZE_PTR ((void *)16)
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
134*4882a593Smuzhiyun (unsigned long)ZERO_SIZE_PTR)
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun #include <linux/kasan.h>
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun struct mem_cgroup;
139*4882a593Smuzhiyun /*
140*4882a593Smuzhiyun * struct kmem_cache related prototypes
141*4882a593Smuzhiyun */
142*4882a593Smuzhiyun void __init kmem_cache_init(void);
143*4882a593Smuzhiyun bool slab_is_available(void);
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun extern bool usercopy_fallback;
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun struct kmem_cache *kmem_cache_create(const char *name, unsigned int size,
148*4882a593Smuzhiyun unsigned int align, slab_flags_t flags,
149*4882a593Smuzhiyun void (*ctor)(void *));
150*4882a593Smuzhiyun struct kmem_cache *kmem_cache_create_usercopy(const char *name,
151*4882a593Smuzhiyun unsigned int size, unsigned int align,
152*4882a593Smuzhiyun slab_flags_t flags,
153*4882a593Smuzhiyun unsigned int useroffset, unsigned int usersize,
154*4882a593Smuzhiyun void (*ctor)(void *));
155*4882a593Smuzhiyun void kmem_cache_destroy(struct kmem_cache *);
156*4882a593Smuzhiyun int kmem_cache_shrink(struct kmem_cache *);
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /*
159*4882a593Smuzhiyun * Please use this macro to create slab caches. Simply specify the
160*4882a593Smuzhiyun * name of the structure and maybe some flags that are listed above.
161*4882a593Smuzhiyun *
162*4882a593Smuzhiyun * The alignment of the struct determines object alignment. If you
163*4882a593Smuzhiyun * f.e. add ____cacheline_aligned_in_smp to the struct declaration
164*4882a593Smuzhiyun * then the objects will be properly aligned in SMP configurations.
165*4882a593Smuzhiyun */
166*4882a593Smuzhiyun #define KMEM_CACHE(__struct, __flags) \
167*4882a593Smuzhiyun kmem_cache_create(#__struct, sizeof(struct __struct), \
168*4882a593Smuzhiyun __alignof__(struct __struct), (__flags), NULL)
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /*
171*4882a593Smuzhiyun * To whitelist a single field for copying to/from usercopy, use this
172*4882a593Smuzhiyun * macro instead for KMEM_CACHE() above.
173*4882a593Smuzhiyun */
174*4882a593Smuzhiyun #define KMEM_CACHE_USERCOPY(__struct, __flags, __field) \
175*4882a593Smuzhiyun kmem_cache_create_usercopy(#__struct, \
176*4882a593Smuzhiyun sizeof(struct __struct), \
177*4882a593Smuzhiyun __alignof__(struct __struct), (__flags), \
178*4882a593Smuzhiyun offsetof(struct __struct, __field), \
179*4882a593Smuzhiyun sizeof_field(struct __struct, __field), NULL)
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun /*
182*4882a593Smuzhiyun * Common kmalloc functions provided by all allocators
183*4882a593Smuzhiyun */
184*4882a593Smuzhiyun void * __must_check krealloc(const void *, size_t, gfp_t);
185*4882a593Smuzhiyun void kfree(const void *);
186*4882a593Smuzhiyun void kfree_sensitive(const void *);
187*4882a593Smuzhiyun size_t __ksize(const void *);
188*4882a593Smuzhiyun size_t ksize(const void *);
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun #ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
191*4882a593Smuzhiyun void __check_heap_object(const void *ptr, unsigned long n, struct page *page,
192*4882a593Smuzhiyun bool to_user);
193*4882a593Smuzhiyun #else
__check_heap_object(const void * ptr,unsigned long n,struct page * page,bool to_user)194*4882a593Smuzhiyun static inline void __check_heap_object(const void *ptr, unsigned long n,
195*4882a593Smuzhiyun struct page *page, bool to_user) { }
196*4882a593Smuzhiyun #endif
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun /*
199*4882a593Smuzhiyun * Some archs want to perform DMA into kmalloc caches and need a guaranteed
200*4882a593Smuzhiyun * alignment larger than the alignment of a 64-bit integer.
201*4882a593Smuzhiyun * Setting ARCH_KMALLOC_MINALIGN in arch headers allows that.
202*4882a593Smuzhiyun */
203*4882a593Smuzhiyun #if defined(ARCH_DMA_MINALIGN) && ARCH_DMA_MINALIGN > 8 && !IS_ENABLED(CONFIG_ROCKCHIP_MINI_KERNEL)
204*4882a593Smuzhiyun #define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN
205*4882a593Smuzhiyun #define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN
206*4882a593Smuzhiyun #define KMALLOC_SHIFT_LOW ilog2(ARCH_DMA_MINALIGN)
207*4882a593Smuzhiyun #else
208*4882a593Smuzhiyun #define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long)
209*4882a593Smuzhiyun #endif
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun /*
212*4882a593Smuzhiyun * Setting ARCH_SLAB_MINALIGN in arch headers allows a different alignment.
213*4882a593Smuzhiyun * Intended for arches that get misalignment faults even for 64 bit integer
214*4882a593Smuzhiyun * aligned buffers.
215*4882a593Smuzhiyun */
216*4882a593Smuzhiyun #ifndef ARCH_SLAB_MINALIGN
217*4882a593Smuzhiyun #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
218*4882a593Smuzhiyun #endif
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun /*
221*4882a593Smuzhiyun * Arches can define this function if they want to decide the minimum slab
222*4882a593Smuzhiyun * alignment at runtime. The value returned by the function must be a power
223*4882a593Smuzhiyun * of two and >= ARCH_SLAB_MINALIGN.
224*4882a593Smuzhiyun */
225*4882a593Smuzhiyun #ifndef arch_slab_minalign
arch_slab_minalign(void)226*4882a593Smuzhiyun static inline unsigned int arch_slab_minalign(void)
227*4882a593Smuzhiyun {
228*4882a593Smuzhiyun return ARCH_SLAB_MINALIGN;
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun #endif
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun /*
233*4882a593Smuzhiyun * kmalloc and friends return ARCH_KMALLOC_MINALIGN aligned
234*4882a593Smuzhiyun * pointers. kmem_cache_alloc and friends return ARCH_SLAB_MINALIGN
235*4882a593Smuzhiyun * aligned pointers.
236*4882a593Smuzhiyun */
237*4882a593Smuzhiyun #define __assume_kmalloc_alignment __assume_aligned(ARCH_KMALLOC_MINALIGN)
238*4882a593Smuzhiyun #define __assume_slab_alignment __assume_aligned(ARCH_SLAB_MINALIGN)
239*4882a593Smuzhiyun #define __assume_page_alignment __assume_aligned(PAGE_SIZE)
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun /*
242*4882a593Smuzhiyun * Kmalloc array related definitions
243*4882a593Smuzhiyun */
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun #ifdef CONFIG_SLAB
246*4882a593Smuzhiyun /*
247*4882a593Smuzhiyun * The largest kmalloc size supported by the SLAB allocators is
248*4882a593Smuzhiyun * 32 megabyte (2^25) or the maximum allocatable page order if that is
249*4882a593Smuzhiyun * less than 32 MB.
250*4882a593Smuzhiyun *
251*4882a593Smuzhiyun * WARNING: Its not easy to increase this value since the allocators have
252*4882a593Smuzhiyun * to do various tricks to work around compiler limitations in order to
253*4882a593Smuzhiyun * ensure proper constant folding.
254*4882a593Smuzhiyun */
255*4882a593Smuzhiyun #define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT - 1) <= 25 ? \
256*4882a593Smuzhiyun (MAX_ORDER + PAGE_SHIFT - 1) : 25)
257*4882a593Smuzhiyun #define KMALLOC_SHIFT_MAX KMALLOC_SHIFT_HIGH
258*4882a593Smuzhiyun #ifndef KMALLOC_SHIFT_LOW
259*4882a593Smuzhiyun #define KMALLOC_SHIFT_LOW 5
260*4882a593Smuzhiyun #endif
261*4882a593Smuzhiyun #endif
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun #ifdef CONFIG_SLUB
264*4882a593Smuzhiyun /*
265*4882a593Smuzhiyun * SLUB directly allocates requests fitting in to an order-1 page
266*4882a593Smuzhiyun * (PAGE_SIZE*2). Larger requests are passed to the page allocator.
267*4882a593Smuzhiyun */
268*4882a593Smuzhiyun #define KMALLOC_SHIFT_HIGH (PAGE_SHIFT + 1)
269*4882a593Smuzhiyun #define KMALLOC_SHIFT_MAX (MAX_ORDER + PAGE_SHIFT - 1)
270*4882a593Smuzhiyun #ifndef KMALLOC_SHIFT_LOW
271*4882a593Smuzhiyun #define KMALLOC_SHIFT_LOW 3
272*4882a593Smuzhiyun #endif
273*4882a593Smuzhiyun #endif
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun #ifdef CONFIG_SLOB
276*4882a593Smuzhiyun /*
277*4882a593Smuzhiyun * SLOB passes all requests larger than one page to the page allocator.
278*4882a593Smuzhiyun * No kmalloc array is necessary since objects of different sizes can
279*4882a593Smuzhiyun * be allocated from the same page.
280*4882a593Smuzhiyun */
281*4882a593Smuzhiyun #define KMALLOC_SHIFT_HIGH PAGE_SHIFT
282*4882a593Smuzhiyun #define KMALLOC_SHIFT_MAX (MAX_ORDER + PAGE_SHIFT - 1)
283*4882a593Smuzhiyun #ifndef KMALLOC_SHIFT_LOW
284*4882a593Smuzhiyun #define KMALLOC_SHIFT_LOW 3
285*4882a593Smuzhiyun #endif
286*4882a593Smuzhiyun #endif
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun /* Maximum allocatable size */
289*4882a593Smuzhiyun #define KMALLOC_MAX_SIZE (1UL << KMALLOC_SHIFT_MAX)
290*4882a593Smuzhiyun /* Maximum size for which we actually use a slab cache */
291*4882a593Smuzhiyun #define KMALLOC_MAX_CACHE_SIZE (1UL << KMALLOC_SHIFT_HIGH)
292*4882a593Smuzhiyun /* Maximum order allocatable via the slab allocator */
293*4882a593Smuzhiyun #define KMALLOC_MAX_ORDER (KMALLOC_SHIFT_MAX - PAGE_SHIFT)
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun /*
296*4882a593Smuzhiyun * Kmalloc subsystem.
297*4882a593Smuzhiyun */
298*4882a593Smuzhiyun #ifndef KMALLOC_MIN_SIZE
299*4882a593Smuzhiyun #define KMALLOC_MIN_SIZE (1 << KMALLOC_SHIFT_LOW)
300*4882a593Smuzhiyun #endif
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun /*
303*4882a593Smuzhiyun * This restriction comes from byte sized index implementation.
304*4882a593Smuzhiyun * Page size is normally 2^12 bytes and, in this case, if we want to use
305*4882a593Smuzhiyun * byte sized index which can represent 2^8 entries, the size of the object
306*4882a593Smuzhiyun * should be equal or greater to 2^12 / 2^8 = 2^4 = 16.
307*4882a593Smuzhiyun * If minimum size of kmalloc is less than 16, we use it as minimum object
308*4882a593Smuzhiyun * size and give up to use byte sized index.
309*4882a593Smuzhiyun */
310*4882a593Smuzhiyun #define SLAB_OBJ_MIN_SIZE (KMALLOC_MIN_SIZE < 16 ? \
311*4882a593Smuzhiyun (KMALLOC_MIN_SIZE) : 16)
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun /*
314*4882a593Smuzhiyun * Whenever changing this, take care of that kmalloc_type() and
315*4882a593Smuzhiyun * create_kmalloc_caches() still work as intended.
316*4882a593Smuzhiyun */
317*4882a593Smuzhiyun enum kmalloc_cache_type {
318*4882a593Smuzhiyun KMALLOC_NORMAL = 0,
319*4882a593Smuzhiyun KMALLOC_RECLAIM,
320*4882a593Smuzhiyun #ifdef CONFIG_ZONE_DMA
321*4882a593Smuzhiyun KMALLOC_DMA,
322*4882a593Smuzhiyun #endif
323*4882a593Smuzhiyun NR_KMALLOC_TYPES
324*4882a593Smuzhiyun };
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun #ifndef CONFIG_SLOB
327*4882a593Smuzhiyun extern struct kmem_cache *
328*4882a593Smuzhiyun kmalloc_caches[NR_KMALLOC_TYPES][KMALLOC_SHIFT_HIGH + 1];
329*4882a593Smuzhiyun
kmalloc_type(gfp_t flags)330*4882a593Smuzhiyun static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun #ifdef CONFIG_ZONE_DMA
333*4882a593Smuzhiyun /*
334*4882a593Smuzhiyun * The most common case is KMALLOC_NORMAL, so test for it
335*4882a593Smuzhiyun * with a single branch for both flags.
336*4882a593Smuzhiyun */
337*4882a593Smuzhiyun if (likely((flags & (__GFP_DMA | __GFP_RECLAIMABLE)) == 0))
338*4882a593Smuzhiyun return KMALLOC_NORMAL;
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun /*
341*4882a593Smuzhiyun * At least one of the flags has to be set. If both are, __GFP_DMA
342*4882a593Smuzhiyun * is more important.
343*4882a593Smuzhiyun */
344*4882a593Smuzhiyun return flags & __GFP_DMA ? KMALLOC_DMA : KMALLOC_RECLAIM;
345*4882a593Smuzhiyun #else
346*4882a593Smuzhiyun return flags & __GFP_RECLAIMABLE ? KMALLOC_RECLAIM : KMALLOC_NORMAL;
347*4882a593Smuzhiyun #endif
348*4882a593Smuzhiyun }
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun /*
351*4882a593Smuzhiyun * Figure out which kmalloc slab an allocation of a certain size
352*4882a593Smuzhiyun * belongs to.
353*4882a593Smuzhiyun * 0 = zero alloc
354*4882a593Smuzhiyun * 1 = 65 .. 96 bytes
355*4882a593Smuzhiyun * 2 = 129 .. 192 bytes
356*4882a593Smuzhiyun * n = 2^(n-1)+1 .. 2^n
357*4882a593Smuzhiyun */
kmalloc_index(size_t size)358*4882a593Smuzhiyun static __always_inline unsigned int kmalloc_index(size_t size)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun if (!size)
361*4882a593Smuzhiyun return 0;
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun if (size <= KMALLOC_MIN_SIZE)
364*4882a593Smuzhiyun return KMALLOC_SHIFT_LOW;
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun if (KMALLOC_MIN_SIZE <= 32 && size > 64 && size <= 96)
367*4882a593Smuzhiyun return 1;
368*4882a593Smuzhiyun if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
369*4882a593Smuzhiyun return 2;
370*4882a593Smuzhiyun if (size <= 8) return 3;
371*4882a593Smuzhiyun if (size <= 16) return 4;
372*4882a593Smuzhiyun if (size <= 32) return 5;
373*4882a593Smuzhiyun if (size <= 64) return 6;
374*4882a593Smuzhiyun if (size <= 128) return 7;
375*4882a593Smuzhiyun if (size <= 256) return 8;
376*4882a593Smuzhiyun if (size <= 512) return 9;
377*4882a593Smuzhiyun if (size <= 1024) return 10;
378*4882a593Smuzhiyun if (size <= 2 * 1024) return 11;
379*4882a593Smuzhiyun if (size <= 4 * 1024) return 12;
380*4882a593Smuzhiyun if (size <= 8 * 1024) return 13;
381*4882a593Smuzhiyun if (size <= 16 * 1024) return 14;
382*4882a593Smuzhiyun if (size <= 32 * 1024) return 15;
383*4882a593Smuzhiyun if (size <= 64 * 1024) return 16;
384*4882a593Smuzhiyun if (size <= 128 * 1024) return 17;
385*4882a593Smuzhiyun if (size <= 256 * 1024) return 18;
386*4882a593Smuzhiyun if (size <= 512 * 1024) return 19;
387*4882a593Smuzhiyun if (size <= 1024 * 1024) return 20;
388*4882a593Smuzhiyun if (size <= 2 * 1024 * 1024) return 21;
389*4882a593Smuzhiyun if (size <= 4 * 1024 * 1024) return 22;
390*4882a593Smuzhiyun if (size <= 8 * 1024 * 1024) return 23;
391*4882a593Smuzhiyun if (size <= 16 * 1024 * 1024) return 24;
392*4882a593Smuzhiyun if (size <= 32 * 1024 * 1024) return 25;
393*4882a593Smuzhiyun if (size <= 64 * 1024 * 1024) return 26;
394*4882a593Smuzhiyun BUG();
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun /* Will never be reached. Needed because the compiler may complain */
397*4882a593Smuzhiyun return -1;
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun #endif /* !CONFIG_SLOB */
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun void *__kmalloc(size_t size, gfp_t flags) __assume_kmalloc_alignment __malloc;
402*4882a593Smuzhiyun void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags) __assume_slab_alignment __malloc;
403*4882a593Smuzhiyun void kmem_cache_free(struct kmem_cache *, void *);
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun /*
406*4882a593Smuzhiyun * Bulk allocation and freeing operations. These are accelerated in an
407*4882a593Smuzhiyun * allocator specific way to avoid taking locks repeatedly or building
408*4882a593Smuzhiyun * metadata structures unnecessarily.
409*4882a593Smuzhiyun *
410*4882a593Smuzhiyun * Note that interrupts must be enabled when calling these functions.
411*4882a593Smuzhiyun */
412*4882a593Smuzhiyun void kmem_cache_free_bulk(struct kmem_cache *, size_t, void **);
413*4882a593Smuzhiyun int kmem_cache_alloc_bulk(struct kmem_cache *, gfp_t, size_t, void **);
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun /*
416*4882a593Smuzhiyun * Caller must not use kfree_bulk() on memory not originally allocated
417*4882a593Smuzhiyun * by kmalloc(), because the SLOB allocator cannot handle this.
418*4882a593Smuzhiyun */
kfree_bulk(size_t size,void ** p)419*4882a593Smuzhiyun static __always_inline void kfree_bulk(size_t size, void **p)
420*4882a593Smuzhiyun {
421*4882a593Smuzhiyun kmem_cache_free_bulk(NULL, size, p);
422*4882a593Smuzhiyun }
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun #ifdef CONFIG_NUMA
425*4882a593Smuzhiyun void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_kmalloc_alignment __malloc;
426*4882a593Smuzhiyun void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node) __assume_slab_alignment __malloc;
427*4882a593Smuzhiyun #else
__kmalloc_node(size_t size,gfp_t flags,int node)428*4882a593Smuzhiyun static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
429*4882a593Smuzhiyun {
430*4882a593Smuzhiyun return __kmalloc(size, flags);
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun
kmem_cache_alloc_node(struct kmem_cache * s,gfp_t flags,int node)433*4882a593Smuzhiyun static __always_inline void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t flags, int node)
434*4882a593Smuzhiyun {
435*4882a593Smuzhiyun return kmem_cache_alloc(s, flags);
436*4882a593Smuzhiyun }
437*4882a593Smuzhiyun #endif
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun #ifdef CONFIG_TRACING
440*4882a593Smuzhiyun extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t) __assume_slab_alignment __malloc;
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun #ifdef CONFIG_NUMA
443*4882a593Smuzhiyun extern void *kmem_cache_alloc_node_trace(struct kmem_cache *s,
444*4882a593Smuzhiyun gfp_t gfpflags,
445*4882a593Smuzhiyun int node, size_t size) __assume_slab_alignment __malloc;
446*4882a593Smuzhiyun #else
447*4882a593Smuzhiyun static __always_inline void *
kmem_cache_alloc_node_trace(struct kmem_cache * s,gfp_t gfpflags,int node,size_t size)448*4882a593Smuzhiyun kmem_cache_alloc_node_trace(struct kmem_cache *s,
449*4882a593Smuzhiyun gfp_t gfpflags,
450*4882a593Smuzhiyun int node, size_t size)
451*4882a593Smuzhiyun {
452*4882a593Smuzhiyun return kmem_cache_alloc_trace(s, gfpflags, size);
453*4882a593Smuzhiyun }
454*4882a593Smuzhiyun #endif /* CONFIG_NUMA */
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun #else /* CONFIG_TRACING */
kmem_cache_alloc_trace(struct kmem_cache * s,gfp_t flags,size_t size)457*4882a593Smuzhiyun static __always_inline void *kmem_cache_alloc_trace(struct kmem_cache *s,
458*4882a593Smuzhiyun gfp_t flags, size_t size)
459*4882a593Smuzhiyun {
460*4882a593Smuzhiyun void *ret = kmem_cache_alloc(s, flags);
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun ret = kasan_kmalloc(s, ret, size, flags);
463*4882a593Smuzhiyun return ret;
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun static __always_inline void *
kmem_cache_alloc_node_trace(struct kmem_cache * s,gfp_t gfpflags,int node,size_t size)467*4882a593Smuzhiyun kmem_cache_alloc_node_trace(struct kmem_cache *s,
468*4882a593Smuzhiyun gfp_t gfpflags,
469*4882a593Smuzhiyun int node, size_t size)
470*4882a593Smuzhiyun {
471*4882a593Smuzhiyun void *ret = kmem_cache_alloc_node(s, gfpflags, node);
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun ret = kasan_kmalloc(s, ret, size, gfpflags);
474*4882a593Smuzhiyun return ret;
475*4882a593Smuzhiyun }
476*4882a593Smuzhiyun #endif /* CONFIG_TRACING */
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun extern void *kmalloc_order(size_t size, gfp_t flags, unsigned int order) __assume_page_alignment __malloc;
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun #ifdef CONFIG_TRACING
481*4882a593Smuzhiyun extern void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order) __assume_page_alignment __malloc;
482*4882a593Smuzhiyun #else
483*4882a593Smuzhiyun static __always_inline void *
kmalloc_order_trace(size_t size,gfp_t flags,unsigned int order)484*4882a593Smuzhiyun kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
485*4882a593Smuzhiyun {
486*4882a593Smuzhiyun return kmalloc_order(size, flags, order);
487*4882a593Smuzhiyun }
488*4882a593Smuzhiyun #endif
489*4882a593Smuzhiyun
kmalloc_large(size_t size,gfp_t flags)490*4882a593Smuzhiyun static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
491*4882a593Smuzhiyun {
492*4882a593Smuzhiyun unsigned int order = get_order(size);
493*4882a593Smuzhiyun return kmalloc_order_trace(size, flags, order);
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun /**
497*4882a593Smuzhiyun * kmalloc - allocate memory
498*4882a593Smuzhiyun * @size: how many bytes of memory are required.
499*4882a593Smuzhiyun * @flags: the type of memory to allocate.
500*4882a593Smuzhiyun *
501*4882a593Smuzhiyun * kmalloc is the normal method of allocating memory
502*4882a593Smuzhiyun * for objects smaller than page size in the kernel.
503*4882a593Smuzhiyun *
504*4882a593Smuzhiyun * The allocated object address is aligned to at least ARCH_KMALLOC_MINALIGN
505*4882a593Smuzhiyun * bytes. For @size of power of two bytes, the alignment is also guaranteed
506*4882a593Smuzhiyun * to be at least to the size.
507*4882a593Smuzhiyun *
508*4882a593Smuzhiyun * The @flags argument may be one of the GFP flags defined at
509*4882a593Smuzhiyun * include/linux/gfp.h and described at
510*4882a593Smuzhiyun * :ref:`Documentation/core-api/mm-api.rst <mm-api-gfp-flags>`
511*4882a593Smuzhiyun *
512*4882a593Smuzhiyun * The recommended usage of the @flags is described at
513*4882a593Smuzhiyun * :ref:`Documentation/core-api/memory-allocation.rst <memory_allocation>`
514*4882a593Smuzhiyun *
515*4882a593Smuzhiyun * Below is a brief outline of the most useful GFP flags
516*4882a593Smuzhiyun *
517*4882a593Smuzhiyun * %GFP_KERNEL
518*4882a593Smuzhiyun * Allocate normal kernel ram. May sleep.
519*4882a593Smuzhiyun *
520*4882a593Smuzhiyun * %GFP_NOWAIT
521*4882a593Smuzhiyun * Allocation will not sleep.
522*4882a593Smuzhiyun *
523*4882a593Smuzhiyun * %GFP_ATOMIC
524*4882a593Smuzhiyun * Allocation will not sleep. May use emergency pools.
525*4882a593Smuzhiyun *
526*4882a593Smuzhiyun * %GFP_HIGHUSER
527*4882a593Smuzhiyun * Allocate memory from high memory on behalf of user.
528*4882a593Smuzhiyun *
529*4882a593Smuzhiyun * Also it is possible to set different flags by OR'ing
530*4882a593Smuzhiyun * in one or more of the following additional @flags:
531*4882a593Smuzhiyun *
532*4882a593Smuzhiyun * %__GFP_HIGH
533*4882a593Smuzhiyun * This allocation has high priority and may use emergency pools.
534*4882a593Smuzhiyun *
535*4882a593Smuzhiyun * %__GFP_NOFAIL
536*4882a593Smuzhiyun * Indicate that this allocation is in no way allowed to fail
537*4882a593Smuzhiyun * (think twice before using).
538*4882a593Smuzhiyun *
539*4882a593Smuzhiyun * %__GFP_NORETRY
540*4882a593Smuzhiyun * If memory is not immediately available,
541*4882a593Smuzhiyun * then give up at once.
542*4882a593Smuzhiyun *
543*4882a593Smuzhiyun * %__GFP_NOWARN
544*4882a593Smuzhiyun * If allocation fails, don't issue any warnings.
545*4882a593Smuzhiyun *
546*4882a593Smuzhiyun * %__GFP_RETRY_MAYFAIL
547*4882a593Smuzhiyun * Try really hard to succeed the allocation but fail
548*4882a593Smuzhiyun * eventually.
549*4882a593Smuzhiyun */
kmalloc(size_t size,gfp_t flags)550*4882a593Smuzhiyun static __always_inline void *kmalloc(size_t size, gfp_t flags)
551*4882a593Smuzhiyun {
552*4882a593Smuzhiyun if (__builtin_constant_p(size)) {
553*4882a593Smuzhiyun #ifndef CONFIG_SLOB
554*4882a593Smuzhiyun unsigned int index;
555*4882a593Smuzhiyun #endif
556*4882a593Smuzhiyun if (size > KMALLOC_MAX_CACHE_SIZE)
557*4882a593Smuzhiyun return kmalloc_large(size, flags);
558*4882a593Smuzhiyun #ifndef CONFIG_SLOB
559*4882a593Smuzhiyun index = kmalloc_index(size);
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun if (!index)
562*4882a593Smuzhiyun return ZERO_SIZE_PTR;
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun return kmem_cache_alloc_trace(
565*4882a593Smuzhiyun kmalloc_caches[kmalloc_type(flags)][index],
566*4882a593Smuzhiyun flags, size);
567*4882a593Smuzhiyun #endif
568*4882a593Smuzhiyun }
569*4882a593Smuzhiyun return __kmalloc(size, flags);
570*4882a593Smuzhiyun }
571*4882a593Smuzhiyun
kmalloc_node(size_t size,gfp_t flags,int node)572*4882a593Smuzhiyun static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
573*4882a593Smuzhiyun {
574*4882a593Smuzhiyun #ifndef CONFIG_SLOB
575*4882a593Smuzhiyun if (__builtin_constant_p(size) &&
576*4882a593Smuzhiyun size <= KMALLOC_MAX_CACHE_SIZE) {
577*4882a593Smuzhiyun unsigned int i = kmalloc_index(size);
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun if (!i)
580*4882a593Smuzhiyun return ZERO_SIZE_PTR;
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun return kmem_cache_alloc_node_trace(
583*4882a593Smuzhiyun kmalloc_caches[kmalloc_type(flags)][i],
584*4882a593Smuzhiyun flags, node, size);
585*4882a593Smuzhiyun }
586*4882a593Smuzhiyun #endif
587*4882a593Smuzhiyun return __kmalloc_node(size, flags, node);
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun /**
591*4882a593Smuzhiyun * kmalloc_array - allocate memory for an array.
592*4882a593Smuzhiyun * @n: number of elements.
593*4882a593Smuzhiyun * @size: element size.
594*4882a593Smuzhiyun * @flags: the type of memory to allocate (see kmalloc).
595*4882a593Smuzhiyun */
kmalloc_array(size_t n,size_t size,gfp_t flags)596*4882a593Smuzhiyun static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
597*4882a593Smuzhiyun {
598*4882a593Smuzhiyun size_t bytes;
599*4882a593Smuzhiyun
600*4882a593Smuzhiyun if (unlikely(check_mul_overflow(n, size, &bytes)))
601*4882a593Smuzhiyun return NULL;
602*4882a593Smuzhiyun if (__builtin_constant_p(n) && __builtin_constant_p(size))
603*4882a593Smuzhiyun return kmalloc(bytes, flags);
604*4882a593Smuzhiyun return __kmalloc(bytes, flags);
605*4882a593Smuzhiyun }
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun /**
608*4882a593Smuzhiyun * kcalloc - allocate memory for an array. The memory is set to zero.
609*4882a593Smuzhiyun * @n: number of elements.
610*4882a593Smuzhiyun * @size: element size.
611*4882a593Smuzhiyun * @flags: the type of memory to allocate (see kmalloc).
612*4882a593Smuzhiyun */
kcalloc(size_t n,size_t size,gfp_t flags)613*4882a593Smuzhiyun static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
614*4882a593Smuzhiyun {
615*4882a593Smuzhiyun return kmalloc_array(n, size, flags | __GFP_ZERO);
616*4882a593Smuzhiyun }
617*4882a593Smuzhiyun
618*4882a593Smuzhiyun /*
619*4882a593Smuzhiyun * kmalloc_track_caller is a special version of kmalloc that records the
620*4882a593Smuzhiyun * calling function of the routine calling it for slab leak tracking instead
621*4882a593Smuzhiyun * of just the calling function (confusing, eh?).
622*4882a593Smuzhiyun * It's useful when the call to kmalloc comes from a widely-used standard
623*4882a593Smuzhiyun * allocator where we care about the real place the memory allocation
624*4882a593Smuzhiyun * request comes from.
625*4882a593Smuzhiyun */
626*4882a593Smuzhiyun extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
627*4882a593Smuzhiyun #define kmalloc_track_caller(size, flags) \
628*4882a593Smuzhiyun __kmalloc_track_caller(size, flags, _RET_IP_)
629*4882a593Smuzhiyun
kmalloc_array_node(size_t n,size_t size,gfp_t flags,int node)630*4882a593Smuzhiyun static inline void *kmalloc_array_node(size_t n, size_t size, gfp_t flags,
631*4882a593Smuzhiyun int node)
632*4882a593Smuzhiyun {
633*4882a593Smuzhiyun size_t bytes;
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun if (unlikely(check_mul_overflow(n, size, &bytes)))
636*4882a593Smuzhiyun return NULL;
637*4882a593Smuzhiyun if (__builtin_constant_p(n) && __builtin_constant_p(size))
638*4882a593Smuzhiyun return kmalloc_node(bytes, flags, node);
639*4882a593Smuzhiyun return __kmalloc_node(bytes, flags, node);
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun
kcalloc_node(size_t n,size_t size,gfp_t flags,int node)642*4882a593Smuzhiyun static inline void *kcalloc_node(size_t n, size_t size, gfp_t flags, int node)
643*4882a593Smuzhiyun {
644*4882a593Smuzhiyun return kmalloc_array_node(n, size, flags | __GFP_ZERO, node);
645*4882a593Smuzhiyun }
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun #ifdef CONFIG_NUMA
649*4882a593Smuzhiyun extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
650*4882a593Smuzhiyun #define kmalloc_node_track_caller(size, flags, node) \
651*4882a593Smuzhiyun __kmalloc_node_track_caller(size, flags, node, \
652*4882a593Smuzhiyun _RET_IP_)
653*4882a593Smuzhiyun
654*4882a593Smuzhiyun #else /* CONFIG_NUMA */
655*4882a593Smuzhiyun
656*4882a593Smuzhiyun #define kmalloc_node_track_caller(size, flags, node) \
657*4882a593Smuzhiyun kmalloc_track_caller(size, flags)
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun #endif /* CONFIG_NUMA */
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun /*
662*4882a593Smuzhiyun * Shortcuts
663*4882a593Smuzhiyun */
kmem_cache_zalloc(struct kmem_cache * k,gfp_t flags)664*4882a593Smuzhiyun static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
665*4882a593Smuzhiyun {
666*4882a593Smuzhiyun return kmem_cache_alloc(k, flags | __GFP_ZERO);
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun /**
670*4882a593Smuzhiyun * kzalloc - allocate memory. The memory is set to zero.
671*4882a593Smuzhiyun * @size: how many bytes of memory are required.
672*4882a593Smuzhiyun * @flags: the type of memory to allocate (see kmalloc).
673*4882a593Smuzhiyun */
kzalloc(size_t size,gfp_t flags)674*4882a593Smuzhiyun static inline void *kzalloc(size_t size, gfp_t flags)
675*4882a593Smuzhiyun {
676*4882a593Smuzhiyun return kmalloc(size, flags | __GFP_ZERO);
677*4882a593Smuzhiyun }
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun /**
680*4882a593Smuzhiyun * kzalloc_node - allocate zeroed memory from a particular memory node.
681*4882a593Smuzhiyun * @size: how many bytes of memory are required.
682*4882a593Smuzhiyun * @flags: the type of memory to allocate (see kmalloc).
683*4882a593Smuzhiyun * @node: memory node from which to allocate
684*4882a593Smuzhiyun */
kzalloc_node(size_t size,gfp_t flags,int node)685*4882a593Smuzhiyun static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
686*4882a593Smuzhiyun {
687*4882a593Smuzhiyun return kmalloc_node(size, flags | __GFP_ZERO, node);
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun
690*4882a593Smuzhiyun unsigned int kmem_cache_size(struct kmem_cache *s);
691*4882a593Smuzhiyun void __init kmem_cache_init_late(void);
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun #if defined(CONFIG_SMP) && defined(CONFIG_SLAB)
694*4882a593Smuzhiyun int slab_prepare_cpu(unsigned int cpu);
695*4882a593Smuzhiyun int slab_dead_cpu(unsigned int cpu);
696*4882a593Smuzhiyun #else
697*4882a593Smuzhiyun #define slab_prepare_cpu NULL
698*4882a593Smuzhiyun #define slab_dead_cpu NULL
699*4882a593Smuzhiyun #endif
700*4882a593Smuzhiyun
701*4882a593Smuzhiyun #endif /* _LINUX_SLAB_H */
702