slab_common.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. /*
  2. * Slab allocator functions that are independent of the allocator strategy
  3. *
  4. * (C) 2012 Christoph Lameter <cl@linux.com>
  5. */
  6. #include <linux/slab.h>
  7. #include <linux/mm.h>
  8. #include <linux/poison.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/memory.h>
  11. #include <linux/compiler.h>
  12. #include <linux/module.h>
  13. #include <linux/cpu.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/proc_fs.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/tlbflush.h>
  19. #include <asm/page.h>
  20. #include <linux/memcontrol.h>
  21. #define CREATE_TRACE_POINTS
  22. #include <trace/events/kmem.h>
  23. #include "slab.h"
  24. enum slab_state slab_state;
  25. LIST_HEAD(slab_caches);
  26. DEFINE_MUTEX(slab_mutex);
  27. struct kmem_cache *kmem_cache;
  28. /*
  29. * Set of flags that will prevent slab merging
  30. */
  31. #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
  32. SLAB_TRACE | SLAB_DESTROY_BY_RCU | SLAB_NOLEAKTRACE | \
  33. SLAB_FAILSLAB | SLAB_KASAN)
  34. #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \
  35. SLAB_NOTRACK | SLAB_ACCOUNT)
  36. /*
  37. * Merge control. If this is set then no merging of slab caches will occur.
  38. * (Could be removed. This was introduced to pacify the merge skeptics.)
  39. */
  40. static int slab_nomerge;
  41. static int __init setup_slab_nomerge(char *str)
  42. {
  43. slab_nomerge = 1;
  44. return 1;
  45. }
  46. #ifdef CONFIG_SLUB
  47. __setup_param("slub_nomerge", slub_nomerge, setup_slab_nomerge, 0);
  48. #endif
  49. __setup("slab_nomerge", setup_slab_nomerge);
  50. /*
  51. * Determine the size of a slab object
  52. */
  53. unsigned int kmem_cache_size(struct kmem_cache *s)
  54. {
  55. return s->object_size;
  56. }
  57. EXPORT_SYMBOL(kmem_cache_size);
  58. #ifdef CONFIG_DEBUG_VM
  59. static int kmem_cache_sanity_check(const char *name, size_t size)
  60. {
  61. struct kmem_cache *s = NULL;
  62. if (!name || in_interrupt() || size < sizeof(void *) ||
  63. size > KMALLOC_MAX_SIZE) {
  64. pr_err("kmem_cache_create(%s) integrity check failed\n", name);
  65. return -EINVAL;
  66. }
  67. list_for_each_entry(s, &slab_caches, list) {
  68. char tmp;
  69. int res;
  70. /*
  71. * This happens when the module gets unloaded and doesn't
  72. * destroy its slab cache and no-one else reuses the vmalloc
  73. * area of the module. Print a warning.
  74. */
  75. res = probe_kernel_address(s->name, tmp);
  76. if (res) {
  77. pr_err("Slab cache with size %d has lost its name\n",
  78. s->object_size);
  79. continue;
  80. }
  81. }
  82. WARN_ON(strchr(name, ' ')); /* It confuses parsers */
  83. return 0;
  84. }
  85. #else
  86. static inline int kmem_cache_sanity_check(const char *name, size_t size)
  87. {
  88. return 0;
  89. }
  90. #endif
  91. void __kmem_cache_free_bulk(struct kmem_cache *s, size_t nr, void **p)
  92. {
  93. size_t i;
  94. for (i = 0; i < nr; i++) {
  95. if (s)
  96. kmem_cache_free(s, p[i]);
  97. else
  98. kfree(p[i]);
  99. }
  100. }
  101. int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t nr,
  102. void **p)
  103. {
  104. size_t i;
  105. for (i = 0; i < nr; i++) {
  106. void *x = p[i] = kmem_cache_alloc(s, flags);
  107. if (!x) {
  108. __kmem_cache_free_bulk(s, i, p);
  109. return 0;
  110. }
  111. }
  112. return i;
  113. }
  114. #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
  115. void slab_init_memcg_params(struct kmem_cache *s)
  116. {
  117. s->memcg_params.is_root_cache = true;
  118. INIT_LIST_HEAD(&s->memcg_params.list);
  119. RCU_INIT_POINTER(s->memcg_params.memcg_caches, NULL);
  120. }
  121. static int init_memcg_params(struct kmem_cache *s,
  122. struct mem_cgroup *memcg, struct kmem_cache *root_cache)
  123. {
  124. struct memcg_cache_array *arr;
  125. if (memcg) {
  126. s->memcg_params.is_root_cache = false;
  127. s->memcg_params.memcg = memcg;
  128. s->memcg_params.root_cache = root_cache;
  129. return 0;
  130. }
  131. slab_init_memcg_params(s);
  132. if (!memcg_nr_cache_ids)
  133. return 0;
  134. arr = kzalloc(sizeof(struct memcg_cache_array) +
  135. memcg_nr_cache_ids * sizeof(void *),
  136. GFP_KERNEL);
  137. if (!arr)
  138. return -ENOMEM;
  139. RCU_INIT_POINTER(s->memcg_params.memcg_caches, arr);
  140. return 0;
  141. }
  142. static void destroy_memcg_params(struct kmem_cache *s)
  143. {
  144. if (is_root_cache(s))
  145. kfree(rcu_access_pointer(s->memcg_params.memcg_caches));
  146. }
  147. static int update_memcg_params(struct kmem_cache *s, int new_array_size)
  148. {
  149. struct memcg_cache_array *old, *new;
  150. if (!is_root_cache(s))
  151. return 0;
  152. new = kzalloc(sizeof(struct memcg_cache_array) +
  153. new_array_size * sizeof(void *), GFP_KERNEL);
  154. if (!new)
  155. return -ENOMEM;
  156. old = rcu_dereference_protected(s->memcg_params.memcg_caches,
  157. lockdep_is_held(&slab_mutex));
  158. if (old)
  159. memcpy(new->entries, old->entries,
  160. memcg_nr_cache_ids * sizeof(void *));
  161. rcu_assign_pointer(s->memcg_params.memcg_caches, new);
  162. if (old)
  163. kfree_rcu(old, rcu);
  164. return 0;
  165. }
  166. int memcg_update_all_caches(int num_memcgs)
  167. {
  168. struct kmem_cache *s;
  169. int ret = 0;
  170. mutex_lock(&slab_mutex);
  171. list_for_each_entry(s, &slab_caches, list) {
  172. ret = update_memcg_params(s, num_memcgs);
  173. /*
  174. * Instead of freeing the memory, we'll just leave the caches
  175. * up to this point in an updated state.
  176. */
  177. if (ret)
  178. break;
  179. }
  180. mutex_unlock(&slab_mutex);
  181. return ret;
  182. }
  183. #else
  184. static inline int init_memcg_params(struct kmem_cache *s,
  185. struct mem_cgroup *memcg, struct kmem_cache *root_cache)
  186. {
  187. return 0;
  188. }
  189. static inline void destroy_memcg_params(struct kmem_cache *s)
  190. {
  191. }
  192. #endif /* CONFIG_MEMCG && !CONFIG_SLOB */
  193. /*
  194. * Find a mergeable slab cache
  195. */
  196. int slab_unmergeable(struct kmem_cache *s)
  197. {
  198. if (slab_nomerge || (s->flags & SLAB_NEVER_MERGE))
  199. return 1;
  200. if (!is_root_cache(s))
  201. return 1;
  202. if (s->ctor)
  203. return 1;
  204. /*
  205. * We may have set a slab to be unmergeable during bootstrap.
  206. */
  207. if (s->refcount < 0)
  208. return 1;
  209. return 0;
  210. }
  211. struct kmem_cache *find_mergeable(size_t size, size_t align,
  212. unsigned long flags, const char *name, void (*ctor)(void *))
  213. {
  214. struct kmem_cache *s;
  215. if (slab_nomerge)
  216. return NULL;
  217. if (ctor)
  218. return NULL;
  219. size = ALIGN(size, sizeof(void *));
  220. align = calculate_alignment(flags, align, size);
  221. size = ALIGN(size, align);
  222. flags = kmem_cache_flags(size, flags, name, NULL);
  223. if (flags & SLAB_NEVER_MERGE)
  224. return NULL;
  225. list_for_each_entry_reverse(s, &slab_caches, list) {
  226. if (slab_unmergeable(s))
  227. continue;
  228. if (size > s->size)
  229. continue;
  230. if ((flags & SLAB_MERGE_SAME) != (s->flags & SLAB_MERGE_SAME))
  231. continue;
  232. /*
  233. * Check if alignment is compatible.
  234. * Courtesy of Adrian Drzewiecki
  235. */
  236. if ((s->size & ~(align - 1)) != s->size)
  237. continue;
  238. if (s->size - size >= sizeof(void *))
  239. continue;
  240. if (IS_ENABLED(CONFIG_SLAB) && align &&
  241. (align > s->align || s->align % align))
  242. continue;
  243. return s;
  244. }
  245. return NULL;
  246. }
  247. /*
  248. * Figure out what the alignment of the objects will be given a set of
  249. * flags, a user specified alignment and the size of the objects.
  250. */
  251. unsigned long calculate_alignment(unsigned long flags,
  252. unsigned long align, unsigned long size)
  253. {
  254. /*
  255. * If the user wants hardware cache aligned objects then follow that
  256. * suggestion if the object is sufficiently large.
  257. *
  258. * The hardware cache alignment cannot override the specified
  259. * alignment though. If that is greater then use it.
  260. */
  261. if (flags & SLAB_HWCACHE_ALIGN) {
  262. unsigned long ralign = cache_line_size();
  263. while (size <= ralign / 2)
  264. ralign /= 2;
  265. align = max(align, ralign);
  266. }
  267. if (align < ARCH_SLAB_MINALIGN)
  268. align = ARCH_SLAB_MINALIGN;
  269. return ALIGN(align, sizeof(void *));
  270. }
  271. static struct kmem_cache *create_cache(const char *name,
  272. size_t object_size, size_t size, size_t align,
  273. unsigned long flags, void (*ctor)(void *),
  274. struct mem_cgroup *memcg, struct kmem_cache *root_cache)
  275. {
  276. struct kmem_cache *s;
  277. int err;
  278. err = -ENOMEM;
  279. s = kmem_cache_zalloc(kmem_cache, GFP_KERNEL);
  280. if (!s)
  281. goto out;
  282. s->name = name;
  283. s->object_size = object_size;
  284. s->size = size;
  285. s->align = align;
  286. s->ctor = ctor;
  287. err = init_memcg_params(s, memcg, root_cache);
  288. if (err)
  289. goto out_free_cache;
  290. err = __kmem_cache_create(s, flags);
  291. if (err)
  292. goto out_free_cache;
  293. s->refcount = 1;
  294. list_add(&s->list, &slab_caches);
  295. out:
  296. if (err)
  297. return ERR_PTR(err);
  298. return s;
  299. out_free_cache:
  300. destroy_memcg_params(s);
  301. kmem_cache_free(kmem_cache, s);
  302. goto out;
  303. }
  304. /*
  305. * kmem_cache_create - Create a cache.
  306. * @name: A string which is used in /proc/slabinfo to identify this cache.
  307. * @size: The size of objects to be created in this cache.
  308. * @align: The required alignment for the objects.
  309. * @flags: SLAB flags
  310. * @ctor: A constructor for the objects.
  311. *
  312. * Returns a ptr to the cache on success, NULL on failure.
  313. * Cannot be called within a interrupt, but can be interrupted.
  314. * The @ctor is run when new pages are allocated by the cache.
  315. *
  316. * The flags are
  317. *
  318. * %SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5)
  319. * to catch references to uninitialised memory.
  320. *
  321. * %SLAB_RED_ZONE - Insert `Red' zones around the allocated memory to check
  322. * for buffer overruns.
  323. *
  324. * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware
  325. * cacheline. This can be beneficial if you're counting cycles as closely
  326. * as davem.
  327. */
  328. struct kmem_cache *
  329. kmem_cache_create(const char *name, size_t size, size_t align,
  330. unsigned long flags, void (*ctor)(void *))
  331. {
  332. struct kmem_cache *s = NULL;
  333. const char *cache_name;
  334. int err;
  335. get_online_cpus();
  336. get_online_mems();
  337. memcg_get_cache_ids();
  338. mutex_lock(&slab_mutex);
  339. err = kmem_cache_sanity_check(name, size);
  340. if (err) {
  341. goto out_unlock;
  342. }
  343. /*
  344. * Some allocators will constraint the set of valid flags to a subset
  345. * of all flags. We expect them to define CACHE_CREATE_MASK in this
  346. * case, and we'll just provide them with a sanitized version of the
  347. * passed flags.
  348. */
  349. flags &= CACHE_CREATE_MASK;
  350. s = __kmem_cache_alias(name, size, align, flags, ctor);
  351. if (s)
  352. goto out_unlock;
  353. cache_name = kstrdup_const(name, GFP_KERNEL);
  354. if (!cache_name) {
  355. err = -ENOMEM;
  356. goto out_unlock;
  357. }
  358. s = create_cache(cache_name, size, size,
  359. calculate_alignment(flags, align, size),
  360. flags, ctor, NULL, NULL);
  361. if (IS_ERR(s)) {
  362. err = PTR_ERR(s);
  363. kfree_const(cache_name);
  364. }
  365. out_unlock:
  366. mutex_unlock(&slab_mutex);
  367. memcg_put_cache_ids();
  368. put_online_mems();
  369. put_online_cpus();
  370. if (err) {
  371. if (flags & SLAB_PANIC)
  372. panic("kmem_cache_create: Failed to create slab '%s'. Error %d\n",
  373. name, err);
  374. else {
  375. pr_warn("kmem_cache_create(%s) failed with error %d\n",
  376. name, err);
  377. dump_stack();
  378. }
  379. return NULL;
  380. }
  381. return s;
  382. }
  383. EXPORT_SYMBOL(kmem_cache_create);
  384. static int shutdown_cache(struct kmem_cache *s,
  385. struct list_head *release, bool *need_rcu_barrier)
  386. {
  387. if (__kmem_cache_shutdown(s) != 0)
  388. return -EBUSY;
  389. if (s->flags & SLAB_DESTROY_BY_RCU)
  390. *need_rcu_barrier = true;
  391. list_move(&s->list, release);
  392. return 0;
  393. }
  394. static void release_caches(struct list_head *release, bool need_rcu_barrier)
  395. {
  396. struct kmem_cache *s, *s2;
  397. if (need_rcu_barrier)
  398. rcu_barrier();
  399. list_for_each_entry_safe(s, s2, release, list) {
  400. #ifdef SLAB_SUPPORTS_SYSFS
  401. sysfs_slab_remove(s);
  402. #else
  403. slab_kmem_cache_release(s);
  404. #endif
  405. }
  406. }
  407. #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
  408. /*
  409. * memcg_create_kmem_cache - Create a cache for a memory cgroup.
  410. * @memcg: The memory cgroup the new cache is for.
  411. * @root_cache: The parent of the new cache.
  412. *
  413. * This function attempts to create a kmem cache that will serve allocation
  414. * requests going from @memcg to @root_cache. The new cache inherits properties
  415. * from its parent.
  416. */
  417. void memcg_create_kmem_cache(struct mem_cgroup *memcg,
  418. struct kmem_cache *root_cache)
  419. {
  420. static char memcg_name_buf[NAME_MAX + 1]; /* protected by slab_mutex */
  421. struct cgroup_subsys_state *css = &memcg->css;
  422. struct memcg_cache_array *arr;
  423. struct kmem_cache *s = NULL;
  424. char *cache_name;
  425. int idx;
  426. get_online_cpus();
  427. get_online_mems();
  428. mutex_lock(&slab_mutex);
  429. /*
  430. * The memory cgroup could have been offlined while the cache
  431. * creation work was pending.
  432. */
  433. if (memcg->kmem_state != KMEM_ONLINE)
  434. goto out_unlock;
  435. idx = memcg_cache_id(memcg);
  436. arr = rcu_dereference_protected(root_cache->memcg_params.memcg_caches,
  437. lockdep_is_held(&slab_mutex));
  438. /*
  439. * Since per-memcg caches are created asynchronously on first
  440. * allocation (see memcg_kmem_get_cache()), several threads can try to
  441. * create the same cache, but only one of them may succeed.
  442. */
  443. if (arr->entries[idx])
  444. goto out_unlock;
  445. cgroup_name(css->cgroup, memcg_name_buf, sizeof(memcg_name_buf));
  446. cache_name = kasprintf(GFP_KERNEL, "%s(%llu:%s)", root_cache->name,
  447. css->serial_nr, memcg_name_buf);
  448. if (!cache_name)
  449. goto out_unlock;
  450. s = create_cache(cache_name, root_cache->object_size,
  451. root_cache->size, root_cache->align,
  452. root_cache->flags & CACHE_CREATE_MASK,
  453. root_cache->ctor, memcg, root_cache);
  454. /*
  455. * If we could not create a memcg cache, do not complain, because
  456. * that's not critical at all as we can always proceed with the root
  457. * cache.
  458. */
  459. if (IS_ERR(s)) {
  460. kfree(cache_name);
  461. goto out_unlock;
  462. }
  463. list_add(&s->memcg_params.list, &root_cache->memcg_params.list);
  464. /*
  465. * Since readers won't lock (see cache_from_memcg_idx()), we need a
  466. * barrier here to ensure nobody will see the kmem_cache partially
  467. * initialized.
  468. */
  469. smp_wmb();
  470. arr->entries[idx] = s;
  471. out_unlock:
  472. mutex_unlock(&slab_mutex);
  473. put_online_mems();
  474. put_online_cpus();
  475. }
  476. void memcg_deactivate_kmem_caches(struct mem_cgroup *memcg)
  477. {
  478. int idx;
  479. struct memcg_cache_array *arr;
  480. struct kmem_cache *s, *c;
  481. idx = memcg_cache_id(memcg);
  482. get_online_cpus();
  483. get_online_mems();
  484. #ifdef CONFIG_SLUB
  485. /*
  486. * In case of SLUB, we need to disable empty slab caching to
  487. * avoid pinning the offline memory cgroup by freeable kmem
  488. * pages charged to it. SLAB doesn't need this, as it
  489. * periodically purges unused slabs.
  490. */
  491. mutex_lock(&slab_mutex);
  492. list_for_each_entry(s, &slab_caches, list) {
  493. c = is_root_cache(s) ? cache_from_memcg_idx(s, idx) : NULL;
  494. if (c) {
  495. c->cpu_partial = 0;
  496. c->min_partial = 0;
  497. }
  498. }
  499. mutex_unlock(&slab_mutex);
  500. /*
  501. * kmem_cache->cpu_partial is checked locklessly (see
  502. * put_cpu_partial()). Make sure the change is visible.
  503. */
  504. synchronize_sched();
  505. #endif
  506. mutex_lock(&slab_mutex);
  507. list_for_each_entry(s, &slab_caches, list) {
  508. if (!is_root_cache(s))
  509. continue;
  510. arr = rcu_dereference_protected(s->memcg_params.memcg_caches,
  511. lockdep_is_held(&slab_mutex));
  512. c = arr->entries[idx];
  513. if (!c)
  514. continue;
  515. __kmem_cache_shrink(c);
  516. arr->entries[idx] = NULL;
  517. }
  518. mutex_unlock(&slab_mutex);
  519. put_online_mems();
  520. put_online_cpus();
  521. }
  522. static int __shutdown_memcg_cache(struct kmem_cache *s,
  523. struct list_head *release, bool *need_rcu_barrier)
  524. {
  525. BUG_ON(is_root_cache(s));
  526. if (shutdown_cache(s, release, need_rcu_barrier))
  527. return -EBUSY;
  528. list_del(&s->memcg_params.list);
  529. return 0;
  530. }
  531. void memcg_destroy_kmem_caches(struct mem_cgroup *memcg)
  532. {
  533. LIST_HEAD(release);
  534. bool need_rcu_barrier = false;
  535. struct kmem_cache *s, *s2;
  536. get_online_cpus();
  537. get_online_mems();
  538. mutex_lock(&slab_mutex);
  539. list_for_each_entry_safe(s, s2, &slab_caches, list) {
  540. if (is_root_cache(s) || s->memcg_params.memcg != memcg)
  541. continue;
  542. /*
  543. * The cgroup is about to be freed and therefore has no charges
  544. * left. Hence, all its caches must be empty by now.
  545. */
  546. BUG_ON(__shutdown_memcg_cache(s, &release, &need_rcu_barrier));
  547. }
  548. mutex_unlock(&slab_mutex);
  549. put_online_mems();
  550. put_online_cpus();
  551. release_caches(&release, need_rcu_barrier);
  552. }
  553. static int shutdown_memcg_caches(struct kmem_cache *s,
  554. struct list_head *release, bool *need_rcu_barrier)
  555. {
  556. struct memcg_cache_array *arr;
  557. struct kmem_cache *c, *c2;
  558. LIST_HEAD(busy);
  559. int i;
  560. BUG_ON(!is_root_cache(s));
  561. /*
  562. * First, shutdown active caches, i.e. caches that belong to online
  563. * memory cgroups.
  564. */
  565. arr = rcu_dereference_protected(s->memcg_params.memcg_caches,
  566. lockdep_is_held(&slab_mutex));
  567. for_each_memcg_cache_index(i) {
  568. c = arr->entries[i];
  569. if (!c)
  570. continue;
  571. if (__shutdown_memcg_cache(c, release, need_rcu_barrier))
  572. /*
  573. * The cache still has objects. Move it to a temporary
  574. * list so as not to try to destroy it for a second
  575. * time while iterating over inactive caches below.
  576. */
  577. list_move(&c->memcg_params.list, &busy);
  578. else
  579. /*
  580. * The cache is empty and will be destroyed soon. Clear
  581. * the pointer to it in the memcg_caches array so that
  582. * it will never be accessed even if the root cache
  583. * stays alive.
  584. */
  585. arr->entries[i] = NULL;
  586. }
  587. /*
  588. * Second, shutdown all caches left from memory cgroups that are now
  589. * offline.
  590. */
  591. list_for_each_entry_safe(c, c2, &s->memcg_params.list,
  592. memcg_params.list)
  593. __shutdown_memcg_cache(c, release, need_rcu_barrier);
  594. list_splice(&busy, &s->memcg_params.list);
  595. /*
  596. * A cache being destroyed must be empty. In particular, this means
  597. * that all per memcg caches attached to it must be empty too.
  598. */
  599. if (!list_empty(&s->memcg_params.list))
  600. return -EBUSY;
  601. return 0;
  602. }
  603. #else
  604. static inline int shutdown_memcg_caches(struct kmem_cache *s,
  605. struct list_head *release, bool *need_rcu_barrier)
  606. {
  607. return 0;
  608. }
  609. #endif /* CONFIG_MEMCG && !CONFIG_SLOB */
  610. void slab_kmem_cache_release(struct kmem_cache *s)
  611. {
  612. __kmem_cache_release(s);
  613. destroy_memcg_params(s);
  614. kfree_const(s->name);
  615. kmem_cache_free(kmem_cache, s);
  616. }
  617. void kmem_cache_destroy(struct kmem_cache *s)
  618. {
  619. LIST_HEAD(release);
  620. bool need_rcu_barrier = false;
  621. int err;
  622. if (unlikely(!s))
  623. return;
  624. get_online_cpus();
  625. get_online_mems();
  626. kasan_cache_destroy(s);
  627. mutex_lock(&slab_mutex);
  628. s->refcount--;
  629. if (s->refcount)
  630. goto out_unlock;
  631. err = shutdown_memcg_caches(s, &release, &need_rcu_barrier);
  632. if (!err)
  633. err = shutdown_cache(s, &release, &need_rcu_barrier);
  634. if (err) {
  635. pr_err("kmem_cache_destroy %s: Slab cache still has objects\n",
  636. s->name);
  637. dump_stack();
  638. }
  639. out_unlock:
  640. mutex_unlock(&slab_mutex);
  641. put_online_mems();
  642. put_online_cpus();
  643. release_caches(&release, need_rcu_barrier);
  644. }
  645. EXPORT_SYMBOL(kmem_cache_destroy);
  646. /**
  647. * kmem_cache_shrink - Shrink a cache.
  648. * @cachep: The cache to shrink.
  649. *
  650. * Releases as many slabs as possible for a cache.
  651. * To help debugging, a zero exit status indicates all slabs were released.
  652. */
  653. int kmem_cache_shrink(struct kmem_cache *cachep)
  654. {
  655. int ret;
  656. get_online_cpus();
  657. get_online_mems();
  658. kasan_cache_shrink(cachep);
  659. ret = __kmem_cache_shrink(cachep);
  660. put_online_mems();
  661. put_online_cpus();
  662. return ret;
  663. }
  664. EXPORT_SYMBOL(kmem_cache_shrink);
  665. bool slab_is_available(void)
  666. {
  667. return slab_state >= UP;
  668. }
  669. #ifndef CONFIG_SLOB
  670. /* Create a cache during boot when no slab services are available yet */
  671. void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t size,
  672. unsigned long flags)
  673. {
  674. int err;
  675. s->name = name;
  676. s->size = s->object_size = size;
  677. s->align = calculate_alignment(flags, ARCH_KMALLOC_MINALIGN, size);
  678. slab_init_memcg_params(s);
  679. err = __kmem_cache_create(s, flags);
  680. if (err)
  681. panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
  682. name, size, err);
  683. s->refcount = -1; /* Exempt from merging for now */
  684. }
  685. struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
  686. unsigned long flags)
  687. {
  688. struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
  689. if (!s)
  690. panic("Out of memory when creating slab %s\n", name);
  691. create_boot_cache(s, name, size, flags);
  692. list_add(&s->list, &slab_caches);
  693. s->refcount = 1;
  694. return s;
  695. }
  696. struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
  697. EXPORT_SYMBOL(kmalloc_caches);
  698. #ifdef CONFIG_ZONE_DMA
  699. struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
  700. EXPORT_SYMBOL(kmalloc_dma_caches);
  701. #endif
  702. /*
  703. * Conversion table for small slabs sizes / 8 to the index in the
  704. * kmalloc array. This is necessary for slabs < 192 since we have non power
  705. * of two cache sizes there. The size of larger slabs can be determined using
  706. * fls.
  707. */
  708. static s8 size_index[24] = {
  709. 3, /* 8 */
  710. 4, /* 16 */
  711. 5, /* 24 */
  712. 5, /* 32 */
  713. 6, /* 40 */
  714. 6, /* 48 */
  715. 6, /* 56 */
  716. 6, /* 64 */
  717. 1, /* 72 */
  718. 1, /* 80 */
  719. 1, /* 88 */
  720. 1, /* 96 */
  721. 7, /* 104 */
  722. 7, /* 112 */
  723. 7, /* 120 */
  724. 7, /* 128 */
  725. 2, /* 136 */
  726. 2, /* 144 */
  727. 2, /* 152 */
  728. 2, /* 160 */
  729. 2, /* 168 */
  730. 2, /* 176 */
  731. 2, /* 184 */
  732. 2 /* 192 */
  733. };
  734. static inline int size_index_elem(size_t bytes)
  735. {
  736. return (bytes - 1) / 8;
  737. }
  738. /*
  739. * Find the kmem_cache structure that serves a given size of
  740. * allocation
  741. */
  742. struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
  743. {
  744. int index;
  745. if (unlikely(size > KMALLOC_MAX_SIZE)) {
  746. WARN_ON_ONCE(!(flags & __GFP_NOWARN));
  747. return NULL;
  748. }
  749. if (size <= 192) {
  750. if (!size)
  751. return ZERO_SIZE_PTR;
  752. index = size_index[size_index_elem(size)];
  753. } else
  754. index = fls(size - 1);
  755. #ifdef CONFIG_ZONE_DMA
  756. if (unlikely((flags & GFP_DMA)))
  757. return kmalloc_dma_caches[index];
  758. #endif
  759. return kmalloc_caches[index];
  760. }
  761. /*
  762. * kmalloc_info[] is to make slub_debug=,kmalloc-xx option work at boot time.
  763. * kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is
  764. * kmalloc-67108864.
  765. */
  766. static struct {
  767. const char *name;
  768. unsigned long size;
  769. } const kmalloc_info[] __initconst = {
  770. {NULL, 0}, {"kmalloc-96", 96},
  771. {"kmalloc-192", 192}, {"kmalloc-8", 8},
  772. {"kmalloc-16", 16}, {"kmalloc-32", 32},
  773. {"kmalloc-64", 64}, {"kmalloc-128", 128},
  774. {"kmalloc-256", 256}, {"kmalloc-512", 512},
  775. {"kmalloc-1024", 1024}, {"kmalloc-2048", 2048},
  776. {"kmalloc-4096", 4096}, {"kmalloc-8192", 8192},
  777. {"kmalloc-16384", 16384}, {"kmalloc-32768", 32768},
  778. {"kmalloc-65536", 65536}, {"kmalloc-131072", 131072},
  779. {"kmalloc-262144", 262144}, {"kmalloc-524288", 524288},
  780. {"kmalloc-1048576", 1048576}, {"kmalloc-2097152", 2097152},
  781. {"kmalloc-4194304", 4194304}, {"kmalloc-8388608", 8388608},
  782. {"kmalloc-16777216", 16777216}, {"kmalloc-33554432", 33554432},
  783. {"kmalloc-67108864", 67108864}
  784. };
  785. /*
  786. * Patch up the size_index table if we have strange large alignment
  787. * requirements for the kmalloc array. This is only the case for
  788. * MIPS it seems. The standard arches will not generate any code here.
  789. *
  790. * Largest permitted alignment is 256 bytes due to the way we
  791. * handle the index determination for the smaller caches.
  792. *
  793. * Make sure that nothing crazy happens if someone starts tinkering
  794. * around with ARCH_KMALLOC_MINALIGN
  795. */
  796. void __init setup_kmalloc_cache_index_table(void)
  797. {
  798. int i;
  799. BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
  800. (KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
  801. for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
  802. int elem = size_index_elem(i);
  803. if (elem >= ARRAY_SIZE(size_index))
  804. break;
  805. size_index[elem] = KMALLOC_SHIFT_LOW;
  806. }
  807. if (KMALLOC_MIN_SIZE >= 64) {
  808. /*
  809. * The 96 byte size cache is not used if the alignment
  810. * is 64 byte.
  811. */
  812. for (i = 64 + 8; i <= 96; i += 8)
  813. size_index[size_index_elem(i)] = 7;
  814. }
  815. if (KMALLOC_MIN_SIZE >= 128) {
  816. /*
  817. * The 192 byte sized cache is not used if the alignment
  818. * is 128 byte. Redirect kmalloc to use the 256 byte cache
  819. * instead.
  820. */
  821. for (i = 128 + 8; i <= 192; i += 8)
  822. size_index[size_index_elem(i)] = 8;
  823. }
  824. }
  825. static void __init new_kmalloc_cache(int idx, unsigned long flags)
  826. {
  827. kmalloc_caches[idx] = create_kmalloc_cache(kmalloc_info[idx].name,
  828. kmalloc_info[idx].size, flags);
  829. }
  830. /*
  831. * Create the kmalloc array. Some of the regular kmalloc arrays
  832. * may already have been created because they were needed to
  833. * enable allocations for slab creation.
  834. */
  835. void __init create_kmalloc_caches(unsigned long flags)
  836. {
  837. int i;
  838. for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
  839. if (!kmalloc_caches[i])
  840. new_kmalloc_cache(i, flags);
  841. /*
  842. * Caches that are not of the two-to-the-power-of size.
  843. * These have to be created immediately after the
  844. * earlier power of two caches
  845. */
  846. if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
  847. new_kmalloc_cache(1, flags);
  848. if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
  849. new_kmalloc_cache(2, flags);
  850. }
  851. /* Kmalloc array is now usable */
  852. slab_state = UP;
  853. #ifdef CONFIG_ZONE_DMA
  854. for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
  855. struct kmem_cache *s = kmalloc_caches[i];
  856. if (s) {
  857. int size = kmalloc_size(i);
  858. char *n = kasprintf(GFP_NOWAIT,
  859. "dma-kmalloc-%d", size);
  860. BUG_ON(!n);
  861. kmalloc_dma_caches[i] = create_kmalloc_cache(n,
  862. size, SLAB_CACHE_DMA | flags);
  863. }
  864. }
  865. #endif
  866. }
  867. #endif /* !CONFIG_SLOB */
  868. /*
  869. * To avoid unnecessary overhead, we pass through large allocation requests
  870. * directly to the page allocator. We use __GFP_COMP, because we will need to
  871. * know the allocation order to free the pages properly in kfree.
  872. */
  873. void *kmalloc_order(size_t size, gfp_t flags, unsigned int order)
  874. {
  875. void *ret;
  876. struct page *page;
  877. flags |= __GFP_COMP;
  878. page = alloc_pages(flags, order);
  879. ret = page ? page_address(page) : NULL;
  880. kmemleak_alloc(ret, size, 1, flags);
  881. kasan_kmalloc_large(ret, size, flags);
  882. return ret;
  883. }
  884. EXPORT_SYMBOL(kmalloc_order);
  885. #ifdef CONFIG_TRACING
  886. void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
  887. {
  888. void *ret = kmalloc_order(size, flags, order);
  889. trace_kmalloc(_RET_IP_, ret, size, PAGE_SIZE << order, flags);
  890. return ret;
  891. }
  892. EXPORT_SYMBOL(kmalloc_order_trace);
  893. #endif
  894. #ifdef CONFIG_SLAB_FREELIST_RANDOM
  895. /* Randomize a generic freelist */
  896. static void freelist_randomize(struct rnd_state *state, unsigned int *list,
  897. size_t count)
  898. {
  899. size_t i;
  900. unsigned int rand;
  901. for (i = 0; i < count; i++)
  902. list[i] = i;
  903. /* Fisher-Yates shuffle */
  904. for (i = count - 1; i > 0; i--) {
  905. rand = prandom_u32_state(state);
  906. rand %= (i + 1);
  907. swap(list[i], list[rand]);
  908. }
  909. }
  910. /* Create a random sequence per cache */
  911. int cache_random_seq_create(struct kmem_cache *cachep, unsigned int count,
  912. gfp_t gfp)
  913. {
  914. struct rnd_state state;
  915. if (count < 2 || cachep->random_seq)
  916. return 0;
  917. cachep->random_seq = kcalloc(count, sizeof(unsigned int), gfp);
  918. if (!cachep->random_seq)
  919. return -ENOMEM;
  920. /* Get best entropy at this stage of boot */
  921. prandom_seed_state(&state, get_random_long());
  922. freelist_randomize(&state, cachep->random_seq, count);
  923. return 0;
  924. }
  925. /* Destroy the per-cache random freelist sequence */
  926. void cache_random_seq_destroy(struct kmem_cache *cachep)
  927. {
  928. kfree(cachep->random_seq);
  929. cachep->random_seq = NULL;
  930. }
  931. #endif /* CONFIG_SLAB_FREELIST_RANDOM */
  932. #ifdef CONFIG_SLABINFO
  933. #ifdef CONFIG_SLAB
  934. #define SLABINFO_RIGHTS (S_IWUSR | S_IRUSR)
  935. #else
  936. #define SLABINFO_RIGHTS S_IRUSR
  937. #endif
  938. static void print_slabinfo_header(struct seq_file *m)
  939. {
  940. /*
  941. * Output format version, so at least we can change it
  942. * without _too_ many complaints.
  943. */
  944. #ifdef CONFIG_DEBUG_SLAB
  945. seq_puts(m, "slabinfo - version: 2.1 (statistics)\n");
  946. #else
  947. seq_puts(m, "slabinfo - version: 2.1\n");
  948. #endif
  949. seq_puts(m, "# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>");
  950. seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
  951. seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
  952. #ifdef CONFIG_DEBUG_SLAB
  953. seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> <error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
  954. seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
  955. #endif
  956. seq_putc(m, '\n');
  957. }
  958. void *slab_start(struct seq_file *m, loff_t *pos)
  959. {
  960. mutex_lock(&slab_mutex);
  961. return seq_list_start(&slab_caches, *pos);
  962. }
  963. void *slab_next(struct seq_file *m, void *p, loff_t *pos)
  964. {
  965. return seq_list_next(p, &slab_caches, pos);
  966. }
  967. void slab_stop(struct seq_file *m, void *p)
  968. {
  969. mutex_unlock(&slab_mutex);
  970. }
  971. static void
  972. memcg_accumulate_slabinfo(struct kmem_cache *s, struct slabinfo *info)
  973. {
  974. struct kmem_cache *c;
  975. struct slabinfo sinfo;
  976. if (!is_root_cache(s))
  977. return;
  978. for_each_memcg_cache(c, s) {
  979. memset(&sinfo, 0, sizeof(sinfo));
  980. get_slabinfo(c, &sinfo);
  981. info->active_slabs += sinfo.active_slabs;
  982. info->num_slabs += sinfo.num_slabs;
  983. info->shared_avail += sinfo.shared_avail;
  984. info->active_objs += sinfo.active_objs;
  985. info->num_objs += sinfo.num_objs;
  986. }
  987. }
  988. static void cache_show(struct kmem_cache *s, struct seq_file *m)
  989. {
  990. struct slabinfo sinfo;
  991. memset(&sinfo, 0, sizeof(sinfo));
  992. get_slabinfo(s, &sinfo);
  993. memcg_accumulate_slabinfo(s, &sinfo);
  994. seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d",
  995. cache_name(s), sinfo.active_objs, sinfo.num_objs, s->size,
  996. sinfo.objects_per_slab, (1 << sinfo.cache_order));
  997. seq_printf(m, " : tunables %4u %4u %4u",
  998. sinfo.limit, sinfo.batchcount, sinfo.shared);
  999. seq_printf(m, " : slabdata %6lu %6lu %6lu",
  1000. sinfo.active_slabs, sinfo.num_slabs, sinfo.shared_avail);
  1001. slabinfo_show_stats(m, s);
  1002. seq_putc(m, '\n');
  1003. }
  1004. static int slab_show(struct seq_file *m, void *p)
  1005. {
  1006. struct kmem_cache *s = list_entry(p, struct kmem_cache, list);
  1007. if (p == slab_caches.next)
  1008. print_slabinfo_header(m);
  1009. if (is_root_cache(s))
  1010. cache_show(s, m);
  1011. return 0;
  1012. }
  1013. #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
  1014. int memcg_slab_show(struct seq_file *m, void *p)
  1015. {
  1016. struct kmem_cache *s = list_entry(p, struct kmem_cache, list);
  1017. struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
  1018. if (p == slab_caches.next)
  1019. print_slabinfo_header(m);
  1020. if (!is_root_cache(s) && s->memcg_params.memcg == memcg)
  1021. cache_show(s, m);
  1022. return 0;
  1023. }
  1024. #endif
  1025. /*
  1026. * slabinfo_op - iterator that generates /proc/slabinfo
  1027. *
  1028. * Output layout:
  1029. * cache-name
  1030. * num-active-objs
  1031. * total-objs
  1032. * object size
  1033. * num-active-slabs
  1034. * total-slabs
  1035. * num-pages-per-slab
  1036. * + further values on SMP and with statistics enabled
  1037. */
  1038. static const struct seq_operations slabinfo_op = {
  1039. .start = slab_start,
  1040. .next = slab_next,
  1041. .stop = slab_stop,
  1042. .show = slab_show,
  1043. };
  1044. static int slabinfo_open(struct inode *inode, struct file *file)
  1045. {
  1046. return seq_open(file, &slabinfo_op);
  1047. }
  1048. static const struct file_operations proc_slabinfo_operations = {
  1049. .open = slabinfo_open,
  1050. .read = seq_read,
  1051. .write = slabinfo_write,
  1052. .llseek = seq_lseek,
  1053. .release = seq_release,
  1054. };
  1055. static int __init slab_proc_init(void)
  1056. {
  1057. proc_create("slabinfo", SLABINFO_RIGHTS, NULL,
  1058. &proc_slabinfo_operations);
  1059. return 0;
  1060. }
  1061. module_init(slab_proc_init);
  1062. #endif /* CONFIG_SLABINFO */
  1063. static __always_inline void *__do_krealloc(const void *p, size_t new_size,
  1064. gfp_t flags)
  1065. {
  1066. void *ret;
  1067. size_t ks = 0;
  1068. if (p)
  1069. ks = ksize(p);
  1070. if (ks >= new_size) {
  1071. kasan_krealloc((void *)p, new_size, flags);
  1072. return (void *)p;
  1073. }
  1074. ret = kmalloc_track_caller(new_size, flags);
  1075. if (ret && p)
  1076. memcpy(ret, p, ks);
  1077. return ret;
  1078. }
  1079. /**
  1080. * __krealloc - like krealloc() but don't free @p.
  1081. * @p: object to reallocate memory for.
  1082. * @new_size: how many bytes of memory are required.
  1083. * @flags: the type of memory to allocate.
  1084. *
  1085. * This function is like krealloc() except it never frees the originally
  1086. * allocated buffer. Use this if you don't want to free the buffer immediately
  1087. * like, for example, with RCU.
  1088. */
  1089. void *__krealloc(const void *p, size_t new_size, gfp_t flags)
  1090. {
  1091. if (unlikely(!new_size))
  1092. return ZERO_SIZE_PTR;
  1093. return __do_krealloc(p, new_size, flags);
  1094. }
  1095. EXPORT_SYMBOL(__krealloc);
  1096. /**
  1097. * krealloc - reallocate memory. The contents will remain unchanged.
  1098. * @p: object to reallocate memory for.
  1099. * @new_size: how many bytes of memory are required.
  1100. * @flags: the type of memory to allocate.
  1101. *
  1102. * The contents of the object pointed to are preserved up to the
  1103. * lesser of the new and old sizes. If @p is %NULL, krealloc()
  1104. * behaves exactly like kmalloc(). If @new_size is 0 and @p is not a
  1105. * %NULL pointer, the object pointed to is freed.
  1106. */
  1107. void *krealloc(const void *p, size_t new_size, gfp_t flags)
  1108. {
  1109. void *ret;
  1110. if (unlikely(!new_size)) {
  1111. kfree(p);
  1112. return ZERO_SIZE_PTR;
  1113. }
  1114. ret = __do_krealloc(p, new_size, flags);
  1115. if (ret && p != ret)
  1116. kfree(p);
  1117. return ret;
  1118. }
  1119. EXPORT_SYMBOL(krealloc);
  1120. /**
  1121. * kzfree - like kfree but zero memory
  1122. * @p: object to free memory of
  1123. *
  1124. * The memory of the object @p points to is zeroed before freed.
  1125. * If @p is %NULL, kzfree() does nothing.
  1126. *
  1127. * Note: this function zeroes the whole allocated buffer which can be a good
  1128. * deal bigger than the requested buffer size passed to kmalloc(). So be
  1129. * careful when using this function in performance sensitive code.
  1130. */
  1131. void kzfree(const void *p)
  1132. {
  1133. size_t ks;
  1134. void *mem = (void *)p;
  1135. if (unlikely(ZERO_OR_NULL_PTR(mem)))
  1136. return;
  1137. ks = ksize(mem);
  1138. memset(mem, 0, ks);
  1139. kfree(mem);
  1140. }
  1141. EXPORT_SYMBOL(kzfree);
  1142. /* Tracepoints definitions. */
  1143. EXPORT_TRACEPOINT_SYMBOL(kmalloc);
  1144. EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
  1145. EXPORT_TRACEPOINT_SYMBOL(kmalloc_node);
  1146. EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc_node);
  1147. EXPORT_TRACEPOINT_SYMBOL(kfree);
  1148. EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);