slab.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * Written by Mark Hemment, 1996 (markhe@nextd.demon.co.uk).
  3. *
  4. * (C) SGI 2006, Christoph Lameter
  5. * Cleaned up and restructured to ease the addition of alternative
  6. * implementations of SLAB allocators.
  7. * (C) Linux Foundation 2008-2013
  8. * Unified interface for all slab allocators
  9. */
  10. #ifndef _LINUX_SLAB_H
  11. #define _LINUX_SLAB_H
  12. #include <linux/gfp.h>
  13. #include <linux/types.h>
  14. #include <linux/workqueue.h>
  15. /*
  16. * Flags to pass to kmem_cache_create().
  17. * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
  18. */
  19. #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
  20. #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
  21. #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
  22. #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
  23. #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
  24. #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
  25. #define SLAB_PANIC 0x00040000UL /* Panic if kmem_cache_create() fails */
  26. /*
  27. * SLAB_DESTROY_BY_RCU - **WARNING** READ THIS!
  28. *
  29. * This delays freeing the SLAB page by a grace period, it does _NOT_
  30. * delay object freeing. This means that if you do kmem_cache_free()
  31. * that memory location is free to be reused at any time. Thus it may
  32. * be possible to see another object there in the same RCU grace period.
  33. *
  34. * This feature only ensures the memory location backing the object
  35. * stays valid, the trick to using this is relying on an independent
  36. * object validation pass. Something like:
  37. *
  38. * rcu_read_lock()
  39. * again:
  40. * obj = lockless_lookup(key);
  41. * if (obj) {
  42. * if (!try_get_ref(obj)) // might fail for free objects
  43. * goto again;
  44. *
  45. * if (obj->key != key) { // not the object we expected
  46. * put_ref(obj);
  47. * goto again;
  48. * }
  49. * }
  50. * rcu_read_unlock();
  51. *
  52. * This is useful if we need to approach a kernel structure obliquely,
  53. * from its address obtained without the usual locking. We can lock
  54. * the structure to stabilize it and check it's still at the given address,
  55. * only if we can be sure that the memory has not been meanwhile reused
  56. * for some other kind of object (which our subsystem's lock might corrupt).
  57. *
  58. * rcu_read_lock before reading the address, then rcu_read_unlock after
  59. * taking the spinlock within the structure expected at that address.
  60. */
  61. #define SLAB_DESTROY_BY_RCU 0x00080000UL /* Defer freeing slabs to RCU */
  62. #define SLAB_MEM_SPREAD 0x00100000UL /* Spread some memory over cpuset */
  63. #define SLAB_TRACE 0x00200000UL /* Trace allocations and frees */
  64. /* Flag to prevent checks on free */
  65. #ifdef CONFIG_DEBUG_OBJECTS
  66. # define SLAB_DEBUG_OBJECTS 0x00400000UL
  67. #else
  68. # define SLAB_DEBUG_OBJECTS 0x00000000UL
  69. #endif
  70. #define SLAB_NOLEAKTRACE 0x00800000UL /* Avoid kmemleak tracing */
  71. /* Don't track use of uninitialized memory */
  72. #ifdef CONFIG_KMEMCHECK
  73. # define SLAB_NOTRACK 0x01000000UL
  74. #else
  75. # define SLAB_NOTRACK 0x00000000UL
  76. #endif
  77. #ifdef CONFIG_FAILSLAB
  78. # define SLAB_FAILSLAB 0x02000000UL /* Fault injection mark */
  79. #else
  80. # define SLAB_FAILSLAB 0x00000000UL
  81. #endif
  82. /* The following flags affect the page allocator grouping pages by mobility */
  83. #define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */
  84. #define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
  85. /*
  86. * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.
  87. *
  88. * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault.
  89. *
  90. * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
  91. * Both make kfree a no-op.
  92. */
  93. #define ZERO_SIZE_PTR ((void *)16)
  94. #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
  95. (unsigned long)ZERO_SIZE_PTR)
  96. #include <linux/kmemleak.h>
  97. struct mem_cgroup;
  98. /*
  99. * struct kmem_cache related prototypes
  100. */
  101. void __init kmem_cache_init(void);
  102. int slab_is_available(void);
  103. struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
  104. unsigned long,
  105. void (*)(void *));
  106. #ifdef CONFIG_MEMCG_KMEM
  107. struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *,
  108. struct kmem_cache *,
  109. const char *);
  110. #endif
  111. void kmem_cache_destroy(struct kmem_cache *);
  112. int kmem_cache_shrink(struct kmem_cache *);
  113. void kmem_cache_free(struct kmem_cache *, void *);
  114. /*
  115. * Please use this macro to create slab caches. Simply specify the
  116. * name of the structure and maybe some flags that are listed above.
  117. *
  118. * The alignment of the struct determines object alignment. If you
  119. * f.e. add ____cacheline_aligned_in_smp to the struct declaration
  120. * then the objects will be properly aligned in SMP configurations.
  121. */
  122. #define KMEM_CACHE(__struct, __flags) kmem_cache_create(#__struct,\
  123. sizeof(struct __struct), __alignof__(struct __struct),\
  124. (__flags), NULL)
  125. /*
  126. * Common kmalloc functions provided by all allocators
  127. */
  128. void * __must_check __krealloc(const void *, size_t, gfp_t);
  129. void * __must_check krealloc(const void *, size_t, gfp_t);
  130. void kfree(const void *);
  131. void kzfree(const void *);
  132. size_t ksize(const void *);
  133. /*
  134. * Some archs want to perform DMA into kmalloc caches and need a guaranteed
  135. * alignment larger than the alignment of a 64-bit integer.
  136. * Setting ARCH_KMALLOC_MINALIGN in arch headers allows that.
  137. */
  138. #if defined(ARCH_DMA_MINALIGN) && ARCH_DMA_MINALIGN > 8
  139. #define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN
  140. #define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN
  141. #define KMALLOC_SHIFT_LOW ilog2(ARCH_DMA_MINALIGN)
  142. #else
  143. #define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long)
  144. #endif
  145. /*
  146. * Kmalloc array related definitions
  147. */
  148. #ifdef CONFIG_SLAB
  149. /*
  150. * The largest kmalloc size supported by the SLAB allocators is
  151. * 32 megabyte (2^25) or the maximum allocatable page order if that is
  152. * less than 32 MB.
  153. *
  154. * WARNING: Its not easy to increase this value since the allocators have
  155. * to do various tricks to work around compiler limitations in order to
  156. * ensure proper constant folding.
  157. */
  158. #define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT - 1) <= 25 ? \
  159. (MAX_ORDER + PAGE_SHIFT - 1) : 25)
  160. #define KMALLOC_SHIFT_MAX KMALLOC_SHIFT_HIGH
  161. #ifndef KMALLOC_SHIFT_LOW
  162. #define KMALLOC_SHIFT_LOW 5
  163. #endif
  164. #endif
  165. #ifdef CONFIG_SLUB
  166. /*
  167. * SLUB directly allocates requests fitting in to an order-1 page
  168. * (PAGE_SIZE*2). Larger requests are passed to the page allocator.
  169. */
  170. #define KMALLOC_SHIFT_HIGH (PAGE_SHIFT + 1)
  171. #define KMALLOC_SHIFT_MAX (MAX_ORDER + PAGE_SHIFT)
  172. #ifndef KMALLOC_SHIFT_LOW
  173. #define KMALLOC_SHIFT_LOW 3
  174. #endif
  175. #endif
  176. #ifdef CONFIG_SLOB
  177. /*
  178. * SLOB passes all requests larger than one page to the page allocator.
  179. * No kmalloc array is necessary since objects of different sizes can
  180. * be allocated from the same page.
  181. */
  182. #define KMALLOC_SHIFT_HIGH PAGE_SHIFT
  183. #define KMALLOC_SHIFT_MAX 30
  184. #ifndef KMALLOC_SHIFT_LOW
  185. #define KMALLOC_SHIFT_LOW 3
  186. #endif
  187. #endif
  188. /* Maximum allocatable size */
  189. #define KMALLOC_MAX_SIZE (1UL << KMALLOC_SHIFT_MAX)
  190. /* Maximum size for which we actually use a slab cache */
  191. #define KMALLOC_MAX_CACHE_SIZE (1UL << KMALLOC_SHIFT_HIGH)
  192. /* Maximum order allocatable via the slab allocagtor */
  193. #define KMALLOC_MAX_ORDER (KMALLOC_SHIFT_MAX - PAGE_SHIFT)
  194. /*
  195. * Kmalloc subsystem.
  196. */
  197. #ifndef KMALLOC_MIN_SIZE
  198. #define KMALLOC_MIN_SIZE (1 << KMALLOC_SHIFT_LOW)
  199. #endif
  200. /*
  201. * This restriction comes from byte sized index implementation.
  202. * Page size is normally 2^12 bytes and, in this case, if we want to use
  203. * byte sized index which can represent 2^8 entries, the size of the object
  204. * should be equal or greater to 2^12 / 2^8 = 2^4 = 16.
  205. * If minimum size of kmalloc is less than 16, we use it as minimum object
  206. * size and give up to use byte sized index.
  207. */
  208. #define SLAB_OBJ_MIN_SIZE (KMALLOC_MIN_SIZE < 16 ? \
  209. (KMALLOC_MIN_SIZE) : 16)
  210. #ifndef CONFIG_SLOB
  211. extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
  212. #ifdef CONFIG_ZONE_DMA
  213. extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
  214. #endif
  215. /*
  216. * Figure out which kmalloc slab an allocation of a certain size
  217. * belongs to.
  218. * 0 = zero alloc
  219. * 1 = 65 .. 96 bytes
  220. * 2 = 120 .. 192 bytes
  221. * n = 2^(n-1) .. 2^n -1
  222. */
  223. static __always_inline int kmalloc_index(size_t size)
  224. {
  225. if (!size)
  226. return 0;
  227. if (size <= KMALLOC_MIN_SIZE)
  228. return KMALLOC_SHIFT_LOW;
  229. if (KMALLOC_MIN_SIZE <= 32 && size > 64 && size <= 96)
  230. return 1;
  231. if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
  232. return 2;
  233. if (size <= 8) return 3;
  234. if (size <= 16) return 4;
  235. if (size <= 32) return 5;
  236. if (size <= 64) return 6;
  237. if (size <= 128) return 7;
  238. if (size <= 256) return 8;
  239. if (size <= 512) return 9;
  240. if (size <= 1024) return 10;
  241. if (size <= 2 * 1024) return 11;
  242. if (size <= 4 * 1024) return 12;
  243. if (size <= 8 * 1024) return 13;
  244. if (size <= 16 * 1024) return 14;
  245. if (size <= 32 * 1024) return 15;
  246. if (size <= 64 * 1024) return 16;
  247. if (size <= 128 * 1024) return 17;
  248. if (size <= 256 * 1024) return 18;
  249. if (size <= 512 * 1024) return 19;
  250. if (size <= 1024 * 1024) return 20;
  251. if (size <= 2 * 1024 * 1024) return 21;
  252. if (size <= 4 * 1024 * 1024) return 22;
  253. if (size <= 8 * 1024 * 1024) return 23;
  254. if (size <= 16 * 1024 * 1024) return 24;
  255. if (size <= 32 * 1024 * 1024) return 25;
  256. if (size <= 64 * 1024 * 1024) return 26;
  257. BUG();
  258. /* Will never be reached. Needed because the compiler may complain */
  259. return -1;
  260. }
  261. #endif /* !CONFIG_SLOB */
  262. void *__kmalloc(size_t size, gfp_t flags);
  263. void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
  264. #ifdef CONFIG_NUMA
  265. void *__kmalloc_node(size_t size, gfp_t flags, int node);
  266. void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
  267. #else
  268. static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
  269. {
  270. return __kmalloc(size, flags);
  271. }
  272. static __always_inline void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t flags, int node)
  273. {
  274. return kmem_cache_alloc(s, flags);
  275. }
  276. #endif
  277. #ifdef CONFIG_TRACING
  278. extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
  279. #ifdef CONFIG_NUMA
  280. extern void *kmem_cache_alloc_node_trace(struct kmem_cache *s,
  281. gfp_t gfpflags,
  282. int node, size_t size);
  283. #else
  284. static __always_inline void *
  285. kmem_cache_alloc_node_trace(struct kmem_cache *s,
  286. gfp_t gfpflags,
  287. int node, size_t size)
  288. {
  289. return kmem_cache_alloc_trace(s, gfpflags, size);
  290. }
  291. #endif /* CONFIG_NUMA */
  292. #else /* CONFIG_TRACING */
  293. static __always_inline void *kmem_cache_alloc_trace(struct kmem_cache *s,
  294. gfp_t flags, size_t size)
  295. {
  296. return kmem_cache_alloc(s, flags);
  297. }
  298. static __always_inline void *
  299. kmem_cache_alloc_node_trace(struct kmem_cache *s,
  300. gfp_t gfpflags,
  301. int node, size_t size)
  302. {
  303. return kmem_cache_alloc_node(s, gfpflags, node);
  304. }
  305. #endif /* CONFIG_TRACING */
  306. extern void *kmalloc_order(size_t size, gfp_t flags, unsigned int order);
  307. #ifdef CONFIG_TRACING
  308. extern void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order);
  309. #else
  310. static __always_inline void *
  311. kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
  312. {
  313. return kmalloc_order(size, flags, order);
  314. }
  315. #endif
  316. static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
  317. {
  318. unsigned int order = get_order(size);
  319. return kmalloc_order_trace(size, flags, order);
  320. }
  321. /**
  322. * kmalloc - allocate memory
  323. * @size: how many bytes of memory are required.
  324. * @flags: the type of memory to allocate.
  325. *
  326. * kmalloc is the normal method of allocating memory
  327. * for objects smaller than page size in the kernel.
  328. *
  329. * The @flags argument may be one of:
  330. *
  331. * %GFP_USER - Allocate memory on behalf of user. May sleep.
  332. *
  333. * %GFP_KERNEL - Allocate normal kernel ram. May sleep.
  334. *
  335. * %GFP_ATOMIC - Allocation will not sleep. May use emergency pools.
  336. * For example, use this inside interrupt handlers.
  337. *
  338. * %GFP_HIGHUSER - Allocate pages from high memory.
  339. *
  340. * %GFP_NOIO - Do not do any I/O at all while trying to get memory.
  341. *
  342. * %GFP_NOFS - Do not make any fs calls while trying to get memory.
  343. *
  344. * %GFP_NOWAIT - Allocation will not sleep.
  345. *
  346. * %__GFP_THISNODE - Allocate node-local memory only.
  347. *
  348. * %GFP_DMA - Allocation suitable for DMA.
  349. * Should only be used for kmalloc() caches. Otherwise, use a
  350. * slab created with SLAB_DMA.
  351. *
  352. * Also it is possible to set different flags by OR'ing
  353. * in one or more of the following additional @flags:
  354. *
  355. * %__GFP_COLD - Request cache-cold pages instead of
  356. * trying to return cache-warm pages.
  357. *
  358. * %__GFP_HIGH - This allocation has high priority and may use emergency pools.
  359. *
  360. * %__GFP_NOFAIL - Indicate that this allocation is in no way allowed to fail
  361. * (think twice before using).
  362. *
  363. * %__GFP_NORETRY - If memory is not immediately available,
  364. * then give up at once.
  365. *
  366. * %__GFP_NOWARN - If allocation fails, don't issue any warnings.
  367. *
  368. * %__GFP_REPEAT - If allocation fails initially, try once more before failing.
  369. *
  370. * There are other flags available as well, but these are not intended
  371. * for general use, and so are not documented here. For a full list of
  372. * potential flags, always refer to linux/gfp.h.
  373. */
  374. static __always_inline void *kmalloc(size_t size, gfp_t flags)
  375. {
  376. if (__builtin_constant_p(size)) {
  377. if (size > KMALLOC_MAX_CACHE_SIZE)
  378. return kmalloc_large(size, flags);
  379. #ifndef CONFIG_SLOB
  380. if (!(flags & GFP_DMA)) {
  381. int index = kmalloc_index(size);
  382. if (!index)
  383. return ZERO_SIZE_PTR;
  384. return kmem_cache_alloc_trace(kmalloc_caches[index],
  385. flags, size);
  386. }
  387. #endif
  388. }
  389. return __kmalloc(size, flags);
  390. }
  391. /*
  392. * Determine size used for the nth kmalloc cache.
  393. * return size or 0 if a kmalloc cache for that
  394. * size does not exist
  395. */
  396. static __always_inline int kmalloc_size(int n)
  397. {
  398. #ifndef CONFIG_SLOB
  399. if (n > 2)
  400. return 1 << n;
  401. if (n == 1 && KMALLOC_MIN_SIZE <= 32)
  402. return 96;
  403. if (n == 2 && KMALLOC_MIN_SIZE <= 64)
  404. return 192;
  405. #endif
  406. return 0;
  407. }
  408. static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
  409. {
  410. #ifndef CONFIG_SLOB
  411. if (__builtin_constant_p(size) &&
  412. size <= KMALLOC_MAX_CACHE_SIZE && !(flags & GFP_DMA)) {
  413. int i = kmalloc_index(size);
  414. if (!i)
  415. return ZERO_SIZE_PTR;
  416. return kmem_cache_alloc_node_trace(kmalloc_caches[i],
  417. flags, node, size);
  418. }
  419. #endif
  420. return __kmalloc_node(size, flags, node);
  421. }
  422. /*
  423. * Setting ARCH_SLAB_MINALIGN in arch headers allows a different alignment.
  424. * Intended for arches that get misalignment faults even for 64 bit integer
  425. * aligned buffers.
  426. */
  427. #ifndef ARCH_SLAB_MINALIGN
  428. #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
  429. #endif
  430. /*
  431. * This is the main placeholder for memcg-related information in kmem caches.
  432. * struct kmem_cache will hold a pointer to it, so the memory cost while
  433. * disabled is 1 pointer. The runtime cost while enabled, gets bigger than it
  434. * would otherwise be if that would be bundled in kmem_cache: we'll need an
  435. * extra pointer chase. But the trade off clearly lays in favor of not
  436. * penalizing non-users.
  437. *
  438. * Both the root cache and the child caches will have it. For the root cache,
  439. * this will hold a dynamically allocated array large enough to hold
  440. * information about the currently limited memcgs in the system. To allow the
  441. * array to be accessed without taking any locks, on relocation we free the old
  442. * version only after a grace period.
  443. *
  444. * Child caches will hold extra metadata needed for its operation. Fields are:
  445. *
  446. * @memcg: pointer to the memcg this cache belongs to
  447. * @list: list_head for the list of all caches in this memcg
  448. * @root_cache: pointer to the global, root cache, this cache was derived from
  449. * @nr_pages: number of pages that belongs to this cache.
  450. */
  451. struct memcg_cache_params {
  452. bool is_root_cache;
  453. union {
  454. struct {
  455. struct rcu_head rcu_head;
  456. struct kmem_cache *memcg_caches[0];
  457. };
  458. struct {
  459. struct mem_cgroup *memcg;
  460. struct list_head list;
  461. struct kmem_cache *root_cache;
  462. atomic_t nr_pages;
  463. };
  464. };
  465. };
  466. int memcg_update_all_caches(int num_memcgs);
  467. struct seq_file;
  468. int cache_show(struct kmem_cache *s, struct seq_file *m);
  469. void print_slabinfo_header(struct seq_file *m);
  470. /**
  471. * kmalloc_array - allocate memory for an array.
  472. * @n: number of elements.
  473. * @size: element size.
  474. * @flags: the type of memory to allocate (see kmalloc).
  475. */
  476. static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
  477. {
  478. if (size != 0 && n > SIZE_MAX / size)
  479. return NULL;
  480. return __kmalloc(n * size, flags);
  481. }
  482. /**
  483. * kcalloc - allocate memory for an array. The memory is set to zero.
  484. * @n: number of elements.
  485. * @size: element size.
  486. * @flags: the type of memory to allocate (see kmalloc).
  487. */
  488. static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
  489. {
  490. return kmalloc_array(n, size, flags | __GFP_ZERO);
  491. }
  492. /*
  493. * kmalloc_track_caller is a special version of kmalloc that records the
  494. * calling function of the routine calling it for slab leak tracking instead
  495. * of just the calling function (confusing, eh?).
  496. * It's useful when the call to kmalloc comes from a widely-used standard
  497. * allocator where we care about the real place the memory allocation
  498. * request comes from.
  499. */
  500. extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
  501. #define kmalloc_track_caller(size, flags) \
  502. __kmalloc_track_caller(size, flags, _RET_IP_)
  503. #ifdef CONFIG_NUMA
  504. extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
  505. #define kmalloc_node_track_caller(size, flags, node) \
  506. __kmalloc_node_track_caller(size, flags, node, \
  507. _RET_IP_)
  508. #else /* CONFIG_NUMA */
  509. #define kmalloc_node_track_caller(size, flags, node) \
  510. kmalloc_track_caller(size, flags)
  511. #endif /* CONFIG_NUMA */
  512. /*
  513. * Shortcuts
  514. */
  515. static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
  516. {
  517. return kmem_cache_alloc(k, flags | __GFP_ZERO);
  518. }
  519. /**
  520. * kzalloc - allocate memory. The memory is set to zero.
  521. * @size: how many bytes of memory are required.
  522. * @flags: the type of memory to allocate (see kmalloc).
  523. */
  524. static inline void *kzalloc(size_t size, gfp_t flags)
  525. {
  526. return kmalloc(size, flags | __GFP_ZERO);
  527. }
  528. /**
  529. * kzalloc_node - allocate zeroed memory from a particular memory node.
  530. * @size: how many bytes of memory are required.
  531. * @flags: the type of memory to allocate (see kmalloc).
  532. * @node: memory node from which to allocate
  533. */
  534. static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
  535. {
  536. return kmalloc_node(size, flags | __GFP_ZERO, node);
  537. }
  538. unsigned int kmem_cache_size(struct kmem_cache *s);
  539. void __init kmem_cache_init_late(void);
  540. #endif /* _LINUX_SLAB_H */