slab_common.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  1. /*
  2. * Slab allocator functions that are independent of the allocator strategy
  3. *
  4. * (C) 2012 Christoph Lameter <[email protected]>
  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. /* free asan quarantined objects */
  388. kasan_cache_shutdown(s);
  389. if (__kmem_cache_shutdown(s) != 0)
  390. return -EBUSY;
  391. if (s->flags & SLAB_DESTROY_BY_RCU)
  392. *need_rcu_barrier = true;
  393. list_move(&s->list, release);
  394. return 0;
  395. }
  396. static void release_caches(struct list_head *release, bool need_rcu_barrier)
  397. {
  398. struct kmem_cache *s, *s2;
  399. if (need_rcu_barrier)
  400. rcu_barrier();
  401. list_for_each_entry_safe(s, s2, release, list) {
  402. #ifdef SLAB_SUPPORTS_SYSFS
  403. sysfs_slab_remove(s);
  404. #else
  405. slab_kmem_cache_release(s);
  406. #endif
  407. }
  408. }
  409. #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
  410. /*
  411. * memcg_create_kmem_cache - Create a cache for a memory cgroup.
  412. * @memcg: The memory cgroup the new cache is for.
  413. * @root_cache: The parent of the new cache.
  414. *
  415. * This function attempts to create a kmem cache that will serve allocation
  416. * requests going from @memcg to @root_cache. The new cache inherits properties
  417. * from its parent.
  418. */
  419. void memcg_create_kmem_cache(struct mem_cgroup *memcg,
  420. struct kmem_cache *root_cache)
  421. {
  422. static char memcg_name_buf[NAME_MAX + 1]; /* protected by slab_mutex */
  423. struct cgroup_subsys_state *css = &memcg->css;
  424. struct memcg_cache_array *arr;
  425. struct kmem_cache *s = NULL;
  426. char *cache_name;
  427. int idx;
  428. get_online_cpus();
  429. get_online_mems();
  430. mutex_lock(&slab_mutex);
  431. /*
  432. * The memory cgroup could have been offlined while the cache
  433. * creation work was pending.
  434. */
  435. if (memcg->kmem_state != KMEM_ONLINE)
  436. goto out_unlock;
  437. idx = memcg_cache_id(memcg);
  438. arr = rcu_dereference_protected(root_cache->memcg_params.memcg_caches,
  439. lockdep_is_held(&slab_mutex));
  440. /*
  441. * Since per-memcg caches are created asynchronously on first
  442. * allocation (see memcg_kmem_get_cache()), several threads can try to
  443. * create the same cache, but only one of them may succeed.
  444. */
  445. if (arr->entries[idx])
  446. goto out_unlock;
  447. cgroup_name(css->cgroup, memcg_name_buf, sizeof(memcg_name_buf));
  448. cache_name = kasprintf(GFP_KERNEL, "%s(%llu:%s)", root_cache->name,
  449. css->serial_nr, memcg_name_buf);
  450. if (!cache_name)
  451. goto out_unlock;
  452. s = create_cache(cache_name, root_cache->object_size,
  453. root_cache->size, root_cache->align,
  454. root_cache->flags & CACHE_CREATE_MASK,
  455. root_cache->ctor, memcg, root_cache);
  456. /*
  457. * If we could not create a memcg cache, do not complain, because
  458. * that's not critical at all as we can always proceed with the root
  459. * cache.
  460. */
  461. if (IS_ERR(s)) {
  462. kfree(cache_name);
  463. goto out_unlock;
  464. }
  465. list_add(&s->memcg_params.list, &root_cache->memcg_params.list);
  466. /*
  467. * Since readers won't lock (see cache_from_memcg_idx()), we need a
  468. * barrier here to ensure nobody will see the kmem_cache partially
  469. * initialized.
  470. */
  471. smp_wmb();
  472. arr->entries[idx] = s;
  473. out_unlock:
  474. mutex_unlock(&slab_mutex);
  475. put_online_mems();
  476. put_online_cpus();
  477. }
  478. void memcg_deactivate_kmem_caches(struct mem_cgroup *memcg)
  479. {
  480. int idx;
  481. struct memcg_cache_array *arr;
  482. struct kmem_cache *s, *c;
  483. idx = memcg_cache_id(memcg);
  484. get_online_cpus();
  485. get_online_mems();
  486. #ifdef CONFIG_SLUB
  487. /*
  488. * In case of SLUB, we need to disable empty slab caching to
  489. * avoid pinning the offline memory cgroup by freeable kmem
  490. * pages charged to it. SLAB doesn't need this, as it
  491. * periodically purges unused slabs.
  492. */
  493. mutex_lock(&slab_mutex);
  494. list_for_each_entry(s, &slab_caches, list) {
  495. c = is_root_cache(s) ? cache_from_memcg_idx(s, idx) : NULL;
  496. if (c) {
  497. c->cpu_partial = 0;
  498. c->min_partial = 0;
  499. }
  500. }
  501. mutex_unlock(&slab_mutex);
  502. /*
  503. * kmem_cache->cpu_partial is checked locklessly (see
  504. * put_cpu_partial()). Make sure the change is visible.
  505. */
  506. synchronize_sched();
  507. #endif
  508. mutex_lock(&slab_mutex);
  509. list_for_each_entry(s, &slab_caches, list) {
  510. if (!is_root_cache(s))
  511. continue;
  512. arr = rcu_dereference_protected(s->memcg_params.memcg_caches,
  513. lockdep_is_held(&slab_mutex));
  514. c = arr->entries[idx];
  515. if (!c)
  516. continue;
  517. __kmem_cache_shrink(c);
  518. arr->entries[idx] = NULL;
  519. }
  520. mutex_unlock(&slab_mutex);
  521. put_online_mems();
  522. put_online_cpus();
  523. }
  524. static int __shutdown_memcg_cache(struct kmem_cache *s,
  525. struct list_head *release, bool *need_rcu_barrier)
  526. {
  527. BUG_ON(is_root_cache(s));
  528. if (shutdown_cache(s, release, need_rcu_barrier))
  529. return -EBUSY;
  530. list_del(&s->memcg_params.list);
  531. return 0;
  532. }
  533. void memcg_destroy_kmem_caches(struct mem_cgroup *memcg)
  534. {
  535. LIST_HEAD(release);
  536. bool need_rcu_barrier = false;
  537. struct kmem_cache *s, *s2;
  538. get_online_cpus();
  539. get_online_mems();
  540. mutex_lock(&slab_mutex);
  541. list_for_each_entry_safe(s, s2, &slab_caches, list) {
  542. if (is_root_cache(s) || s->memcg_params.memcg != memcg)
  543. continue;
  544. /*
  545. * The cgroup is about to be freed and therefore has no charges
  546. * left. Hence, all its caches must be empty by now.
  547. */
  548. BUG_ON(__shutdown_memcg_cache(s, &release, &need_rcu_barrier));
  549. }
  550. mutex_unlock(&slab_mutex);
  551. put_online_mems();
  552. put_online_cpus();
  553. release_caches(&release, need_rcu_barrier);
  554. }
  555. static int shutdown_memcg_caches(struct kmem_cache *s,
  556. struct list_head *release, bool *need_rcu_barrier)
  557. {
  558. struct memcg_cache_array *arr;
  559. struct kmem_cache *c, *c2;
  560. LIST_HEAD(busy);
  561. int i;
  562. BUG_ON(!is_root_cache(s));
  563. /*
  564. * First, shutdown active caches, i.e. caches that belong to online
  565. * memory cgroups.
  566. */
  567. arr = rcu_dereference_protected(s->memcg_params.memcg_caches,
  568. lockdep_is_held(&slab_mutex));
  569. for_each_memcg_cache_index(i) {
  570. c = arr->entries[i];
  571. if (!c)
  572. continue;
  573. if (__shutdown_memcg_cache(c, release, need_rcu_barrier))
  574. /*
  575. * The cache still has objects. Move it to a temporary
  576. * list so as not to try to destroy it for a second
  577. * time while iterating over inactive caches below.
  578. */
  579. list_move(&c->memcg_params.list, &busy);
  580. else
  581. /*
  582. * The cache is empty and will be destroyed soon. Clear
  583. * the pointer to it in the memcg_caches array so that
  584. * it will never be accessed even if the root cache
  585. * stays alive.
  586. */
  587. arr->entries[i] = NULL;
  588. }
  589. /*
  590. * Second, shutdown all caches left from memory cgroups that are now
  591. * offline.
  592. */
  593. list_for_each_entry_safe(c, c2, &s->memcg_params.list,
  594. memcg_params.list)
  595. __shutdown_memcg_cache(c, release, need_rcu_barrier);
  596. list_splice(&busy, &s->memcg_params.list);
  597. /*
  598. * A cache being destroyed must be empty. In particular, this means
  599. * that all per memcg caches attached to it must be empty too.
  600. */
  601. if (!list_empty(&s->memcg_params.list))
  602. return -EBUSY;
  603. return 0;
  604. }
  605. #else
  606. static inline int shutdown_memcg_caches(struct kmem_cache *s,
  607. struct list_head *release, bool *need_rcu_barrier)
  608. {
  609. return 0;
  610. }
  611. #endif /* CONFIG_MEMCG && !CONFIG_SLOB */
  612. void slab_kmem_cache_release(struct kmem_cache *s)
  613. {
  614. __kmem_cache_release(s);
  615. destroy_memcg_params(s);
  616. kfree_const(s->name);
  617. kmem_cache_free(kmem_cache, s);
  618. }
  619. void kmem_cache_destroy(struct kmem_cache *s)
  620. {
  621. LIST_HEAD(release);
  622. bool need_rcu_barrier = false;
  623. int err;
  624. if (unlikely(!s))
  625. return;
  626. get_online_cpus();
  627. get_online_mems();
  628. mutex_lock(&slab_mutex);
  629. s->refcount--;
  630. if (s->refcount)
  631. goto out_unlock;
  632. err = shutdown_memcg_caches(s, &release, &need_rcu_barrier);
  633. if (!err)
  634. err = shutdown_cache(s, &release, &need_rcu_barrier);
  635. if (err) {
  636. pr_err("kmem_cache_destroy %s: Slab cache still has objects\n",
  637. s->name);
  638. dump_stack();
  639. }
  640. out_unlock:
  641. mutex_unlock(&slab_mutex);
  642. put_online_mems();
  643. put_online_cpus();
  644. release_caches(&release, need_rcu_barrier);
  645. }
  646. EXPORT_SYMBOL(kmem_cache_destroy);
  647. /**
  648. * kmem_cache_shrink - Shrink a cache.
  649. * @cachep: The cache to shrink.
  650. *
  651. * Releases as many slabs as possible for a cache.
  652. * To help debugging, a zero exit status indicates all slabs were released.
  653. */
  654. int kmem_cache_shrink(struct kmem_cache *cachep)
  655. {
  656. int ret;
  657. get_online_cpus();
  658. get_online_mems();
  659. kasan_cache_shrink(cachep);
  660. ret = __kmem_cache_shrink(cachep);
  661. put_online_mems();
  662. put_online_cpus();
  663. return ret;
  664. }
  665. EXPORT_SYMBOL(kmem_cache_shrink);
  666. bool slab_is_available(void)
  667. {
  668. return slab_state >= UP;
  669. }
  670. #ifndef CONFIG_SLOB
  671. /* Create a cache during boot when no slab services are available yet */
  672. void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t size,
  673. unsigned long flags)
  674. {
  675. int err;
  676. s->name = name;
  677. s->size = s->object_size = size;
  678. s->align = calculate_alignment(flags, ARCH_KMALLOC_MINALIGN, size);
  679. slab_init_memcg_params(s);
  680. err = __kmem_cache_create(s, flags);
  681. if (err)
  682. panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
  683. name, size, err);
  684. s->refcount = -1; /* Exempt from merging for now */
  685. }
  686. struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
  687. unsigned long flags)
  688. {
  689. struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
  690. if (!s)
  691. panic("Out of memory when creating slab %s\n", name);
  692. create_boot_cache(s, name, size, flags);
  693. list_add(&s->list, &slab_caches);
  694. s->refcount = 1;
  695. return s;
  696. }
  697. struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
  698. EXPORT_SYMBOL(kmalloc_caches);
  699. #ifdef CONFIG_ZONE_DMA
  700. struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
  701. EXPORT_SYMBOL(kmalloc_dma_caches);
  702. #endif
  703. /*
  704. * Conversion table for small slabs sizes / 8 to the index in the
  705. * kmalloc array. This is necessary for slabs < 192 since we have non power
  706. * of two cache sizes there. The size of larger slabs can be determined using
  707. * fls.
  708. */
  709. static s8 size_index[24] = {
  710. 3, /* 8 */
  711. 4, /* 16 */
  712. 5, /* 24 */
  713. 5, /* 32 */
  714. 6, /* 40 */
  715. 6, /* 48 */
  716. 6, /* 56 */
  717. 6, /* 64 */
  718. 1, /* 72 */
  719. 1, /* 80 */
  720. 1, /* 88 */
  721. 1, /* 96 */
  722. 7, /* 104 */
  723. 7, /* 112 */
  724. 7, /* 120 */
  725. 7, /* 128 */
  726. 2, /* 136 */
  727. 2, /* 144 */
  728. 2, /* 152 */
  729. 2, /* 160 */
  730. 2, /* 168 */
  731. 2, /* 176 */
  732. 2, /* 184 */
  733. 2 /* 192 */
  734. };
  735. static inline int size_index_elem(size_t bytes)
  736. {
  737. return (bytes - 1) / 8;
  738. }
  739. /*
  740. * Find the kmem_cache structure that serves a given size of
  741. * allocation
  742. */
  743. struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
  744. {
  745. int index;
  746. if (size <= 192) {
  747. if (!size)
  748. return ZERO_SIZE_PTR;
  749. index = size_index[size_index_elem(size)];
  750. } else {
  751. if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) {
  752. WARN_ON(1);
  753. return NULL;
  754. }
  755. index = fls(size - 1);
  756. }
  757. #ifdef CONFIG_ZONE_DMA
  758. if (unlikely((flags & GFP_DMA)))
  759. return kmalloc_dma_caches[index];
  760. #endif
  761. return kmalloc_caches[index];
  762. }
  763. /*
  764. * kmalloc_info[] is to make slub_debug=,kmalloc-xx option work at boot time.
  765. * kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is
  766. * kmalloc-67108864.
  767. */
  768. static struct {
  769. const char *name;
  770. unsigned long size;
  771. } const kmalloc_info[] __initconst = {
  772. {NULL, 0}, {"kmalloc-96", 96},
  773. {"kmalloc-192", 192}, {"kmalloc-8", 8},
  774. {"kmalloc-16", 16}, {"kmalloc-32", 32},
  775. {"kmalloc-64", 64}, {"kmalloc-128", 128},
  776. {"kmalloc-256", 256}, {"kmalloc-512", 512},
  777. {"kmalloc-1024", 1024}, {"kmalloc-2048", 2048},
  778. {"kmalloc-4096", 4096}, {"kmalloc-8192", 8192},
  779. {"kmalloc-16384", 16384}, {"kmalloc-32768", 32768},
  780. {"kmalloc-65536", 65536}, {"kmalloc-131072", 131072},
  781. {"kmalloc-262144", 262144}, {"kmalloc-524288", 524288},
  782. {"kmalloc-1048576", 1048576}, {"kmalloc-2097152", 2097152},
  783. {"kmalloc-4194304", 4194304}, {"kmalloc-8388608", 8388608},
  784. {"kmalloc-16777216", 16777216}, {"kmalloc-33554432", 33554432},
  785. {"kmalloc-67108864", 67108864}
  786. };
  787. /*
  788. * Patch up the size_index table if we have strange large alignment
  789. * requirements for the kmalloc array. This is only the case for
  790. * MIPS it seems. The standard arches will not generate any code here.
  791. *
  792. * Largest permitted alignment is 256 bytes due to the way we
  793. * handle the index determination for the smaller caches.
  794. *
  795. * Make sure that nothing crazy happens if someone starts tinkering
  796. * around with ARCH_KMALLOC_MINALIGN
  797. */
  798. void __init setup_kmalloc_cache_index_table(void)
  799. {
  800. int i;
  801. BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
  802. (KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
  803. for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
  804. int elem = size_index_elem(i);
  805. if (elem >= ARRAY_SIZE(size_index))
  806. break;
  807. size_index[elem] = KMALLOC_SHIFT_LOW;
  808. }
  809. if (KMALLOC_MIN_SIZE >= 64) {
  810. /*
  811. * The 96 byte size cache is not used if the alignment
  812. * is 64 byte.
  813. */
  814. for (i = 64 + 8; i <= 96; i += 8)
  815. size_index[size_index_elem(i)] = 7;
  816. }
  817. if (KMALLOC_MIN_SIZE >= 128) {
  818. /*
  819. * The 192 byte sized cache is not used if the alignment
  820. * is 128 byte. Redirect kmalloc to use the 256 byte cache
  821. * instead.
  822. */
  823. for (i = 128 + 8; i <= 192; i += 8)
  824. size_index[size_index_elem(i)] = 8;
  825. }
  826. }
  827. static void __init new_kmalloc_cache(int idx, unsigned long flags)
  828. {
  829. kmalloc_caches[idx] = create_kmalloc_cache(kmalloc_info[idx].name,
  830. kmalloc_info[idx].size, flags);
  831. }
  832. /*
  833. * Create the kmalloc array. Some of the regular kmalloc arrays
  834. * may already have been created because they were needed to
  835. * enable allocations for slab creation.
  836. */
  837. void __init create_kmalloc_caches(unsigned long flags)
  838. {
  839. int i;
  840. for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
  841. if (!kmalloc_caches[i])
  842. new_kmalloc_cache(i, flags);
  843. /*
  844. * Caches that are not of the two-to-the-power-of size.
  845. * These have to be created immediately after the
  846. * earlier power of two caches
  847. */
  848. if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
  849. new_kmalloc_cache(1, flags);
  850. if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
  851. new_kmalloc_cache(2, flags);
  852. }
  853. /* Kmalloc array is now usable */
  854. slab_state = UP;
  855. #ifdef CONFIG_ZONE_DMA
  856. for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
  857. struct kmem_cache *s = kmalloc_caches[i];
  858. if (s) {
  859. int size = kmalloc_size(i);
  860. char *n = kasprintf(GFP_NOWAIT,
  861. "dma-kmalloc-%d", size);
  862. BUG_ON(!n);
  863. kmalloc_dma_caches[i] = create_kmalloc_cache(n,
  864. size, SLAB_CACHE_DMA | flags);
  865. }
  866. }
  867. #endif
  868. }
  869. #endif /* !CONFIG_SLOB */
  870. /*
  871. * To avoid unnecessary overhead, we pass through large allocation requests
  872. * directly to the page allocator. We use __GFP_COMP, because we will need to
  873. * know the allocation order to free the pages properly in kfree.
  874. */
  875. void *kmalloc_order(size_t size, gfp_t flags, unsigned int order)
  876. {
  877. void *ret;
  878. struct page *page;
  879. flags |= __GFP_COMP;
  880. page = alloc_pages(flags, order);
  881. ret = page ? page_address(page) : NULL;
  882. kmemleak_alloc(ret, size, 1, flags);
  883. kasan_kmalloc_large(ret, size, flags);
  884. return ret;
  885. }
  886. EXPORT_SYMBOL(kmalloc_order);
  887. #ifdef CONFIG_TRACING
  888. void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
  889. {
  890. void *ret = kmalloc_order(size, flags, order);
  891. trace_kmalloc(_RET_IP_, ret, size, PAGE_SIZE << order, flags);
  892. return ret;
  893. }
  894. EXPORT_SYMBOL(kmalloc_order_trace);
  895. #endif
  896. #ifdef CONFIG_SLAB_FREELIST_RANDOM
  897. /* Randomize a generic freelist */
  898. static void freelist_randomize(struct rnd_state *state, unsigned int *list,
  899. size_t count)
  900. {
  901. size_t i;
  902. unsigned int rand;
  903. for (i = 0; i < count; i++)
  904. list[i] = i;
  905. /* Fisher-Yates shuffle */
  906. for (i = count - 1; i > 0; i--) {
  907. rand = prandom_u32_state(state);
  908. rand %= (i + 1);
  909. swap(list[i], list[rand]);
  910. }
  911. }
  912. /* Create a random sequence per cache */
  913. int cache_random_seq_create(struct kmem_cache *cachep, unsigned int count,
  914. gfp_t gfp)
  915. {
  916. struct rnd_state state;
  917. if (count < 2 || cachep->random_seq)
  918. return 0;
  919. cachep->random_seq = kcalloc(count, sizeof(unsigned int), gfp);
  920. if (!cachep->random_seq)
  921. return -ENOMEM;
  922. /* Get best entropy at this stage of boot */
  923. prandom_seed_state(&state, get_random_long());
  924. freelist_randomize(&state, cachep->random_seq, count);
  925. return 0;
  926. }
  927. /* Destroy the per-cache random freelist sequence */
  928. void cache_random_seq_destroy(struct kmem_cache *cachep)
  929. {
  930. kfree(cachep->random_seq);
  931. cachep->random_seq = NULL;
  932. }
  933. #endif /* CONFIG_SLAB_FREELIST_RANDOM */
  934. #ifdef CONFIG_SLABINFO
  935. #ifdef CONFIG_SLAB
  936. #define SLABINFO_RIGHTS (S_IWUSR | S_IRUSR)
  937. #else
  938. #define SLABINFO_RIGHTS S_IRUSR
  939. #endif
  940. static void print_slabinfo_header(struct seq_file *m)
  941. {
  942. /*
  943. * Output format version, so at least we can change it
  944. * without _too_ many complaints.
  945. */
  946. #ifdef CONFIG_DEBUG_SLAB
  947. seq_puts(m, "slabinfo - version: 2.1 (statistics)\n");
  948. #else
  949. seq_puts(m, "slabinfo - version: 2.1\n");
  950. #endif
  951. seq_puts(m, "# name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>");
  952. seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
  953. seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
  954. #ifdef CONFIG_DEBUG_SLAB
  955. seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> <error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
  956. seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
  957. #endif
  958. seq_putc(m, '\n');
  959. }
  960. void *slab_start(struct seq_file *m, loff_t *pos)
  961. {
  962. mutex_lock(&slab_mutex);
  963. return seq_list_start(&slab_caches, *pos);
  964. }
  965. void *slab_next(struct seq_file *m, void *p, loff_t *pos)
  966. {
  967. return seq_list_next(p, &slab_caches, pos);
  968. }
  969. void slab_stop(struct seq_file *m, void *p)
  970. {
  971. mutex_unlock(&slab_mutex);
  972. }
  973. static void
  974. memcg_accumulate_slabinfo(struct kmem_cache *s, struct slabinfo *info)
  975. {
  976. struct kmem_cache *c;
  977. struct slabinfo sinfo;
  978. if (!is_root_cache(s))
  979. return;
  980. for_each_memcg_cache(c, s) {
  981. memset(&sinfo, 0, sizeof(sinfo));
  982. get_slabinfo(c, &sinfo);
  983. info->active_slabs += sinfo.active_slabs;
  984. info->num_slabs += sinfo.num_slabs;
  985. info->shared_avail += sinfo.shared_avail;
  986. info->active_objs += sinfo.active_objs;
  987. info->num_objs += sinfo.num_objs;
  988. }
  989. }
  990. static void cache_show(struct kmem_cache *s, struct seq_file *m)
  991. {
  992. struct slabinfo sinfo;
  993. memset(&sinfo, 0, sizeof(sinfo));
  994. get_slabinfo(s, &sinfo);
  995. memcg_accumulate_slabinfo(s, &sinfo);
  996. seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d",
  997. cache_name(s), sinfo.active_objs, sinfo.num_objs, s->size,
  998. sinfo.objects_per_slab, (1 << sinfo.cache_order));
  999. seq_printf(m, " : tunables %4u %4u %4u",
  1000. sinfo.limit, sinfo.batchcount, sinfo.shared);
  1001. seq_printf(m, " : slabdata %6lu %6lu %6lu",
  1002. sinfo.active_slabs, sinfo.num_slabs, sinfo.shared_avail);
  1003. slabinfo_show_stats(m, s);
  1004. seq_putc(m, '\n');
  1005. }
  1006. static int slab_show(struct seq_file *m, void *p)
  1007. {
  1008. struct kmem_cache *s = list_entry(p, struct kmem_cache, list);
  1009. if (p == slab_caches.next)
  1010. print_slabinfo_header(m);
  1011. if (is_root_cache(s))
  1012. cache_show(s, m);
  1013. return 0;
  1014. }
  1015. #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
  1016. int memcg_slab_show(struct seq_file *m, void *p)
  1017. {
  1018. struct kmem_cache *s = list_entry(p, struct kmem_cache, list);
  1019. struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
  1020. if (p == slab_caches.next)
  1021. print_slabinfo_header(m);
  1022. if (!is_root_cache(s) && s->memcg_params.memcg == memcg)
  1023. cache_show(s, m);
  1024. return 0;
  1025. }
  1026. #endif
  1027. /*
  1028. * slabinfo_op - iterator that generates /proc/slabinfo
  1029. *
  1030. * Output layout:
  1031. * cache-name
  1032. * num-active-objs
  1033. * total-objs
  1034. * object size
  1035. * num-active-slabs
  1036. * total-slabs
  1037. * num-pages-per-slab
  1038. * + further values on SMP and with statistics enabled
  1039. */
  1040. static const struct seq_operations slabinfo_op = {
  1041. .start = slab_start,
  1042. .next = slab_next,
  1043. .stop = slab_stop,
  1044. .show = slab_show,
  1045. };
  1046. static int slabinfo_open(struct inode *inode, struct file *file)
  1047. {
  1048. return seq_open(file, &slabinfo_op);
  1049. }
  1050. static const struct file_operations proc_slabinfo_operations = {
  1051. .open = slabinfo_open,
  1052. .read = seq_read,
  1053. .write = slabinfo_write,
  1054. .llseek = seq_lseek,
  1055. .release = seq_release,
  1056. };
  1057. static int __init slab_proc_init(void)
  1058. {
  1059. proc_create("slabinfo", SLABINFO_RIGHTS, NULL,
  1060. &proc_slabinfo_operations);
  1061. return 0;
  1062. }
  1063. module_init(slab_proc_init);
  1064. #endif /* CONFIG_SLABINFO */
  1065. static __always_inline void *__do_krealloc(const void *p, size_t new_size,
  1066. gfp_t flags)
  1067. {
  1068. void *ret;
  1069. size_t ks = 0;
  1070. if (p)
  1071. ks = ksize(p);
  1072. if (ks >= new_size) {
  1073. kasan_krealloc((void *)p, new_size, flags);
  1074. return (void *)p;
  1075. }
  1076. ret = kmalloc_track_caller(new_size, flags);
  1077. if (ret && p)
  1078. memcpy(ret, p, ks);
  1079. return ret;
  1080. }
  1081. /**
  1082. * __krealloc - like krealloc() but don't free @p.
  1083. * @p: object to reallocate memory for.
  1084. * @new_size: how many bytes of memory are required.
  1085. * @flags: the type of memory to allocate.
  1086. *
  1087. * This function is like krealloc() except it never frees the originally
  1088. * allocated buffer. Use this if you don't want to free the buffer immediately
  1089. * like, for example, with RCU.
  1090. */
  1091. void *__krealloc(const void *p, size_t new_size, gfp_t flags)
  1092. {
  1093. if (unlikely(!new_size))
  1094. return ZERO_SIZE_PTR;
  1095. return __do_krealloc(p, new_size, flags);
  1096. }
  1097. EXPORT_SYMBOL(__krealloc);
  1098. /**
  1099. * krealloc - reallocate memory. The contents will remain unchanged.
  1100. * @p: object to reallocate memory for.
  1101. * @new_size: how many bytes of memory are required.
  1102. * @flags: the type of memory to allocate.
  1103. *
  1104. * The contents of the object pointed to are preserved up to the
  1105. * lesser of the new and old sizes. If @p is %NULL, krealloc()
  1106. * behaves exactly like kmalloc(). If @new_size is 0 and @p is not a
  1107. * %NULL pointer, the object pointed to is freed.
  1108. */
  1109. void *krealloc(const void *p, size_t new_size, gfp_t flags)
  1110. {
  1111. void *ret;
  1112. if (unlikely(!new_size)) {
  1113. kfree(p);
  1114. return ZERO_SIZE_PTR;
  1115. }
  1116. ret = __do_krealloc(p, new_size, flags);
  1117. if (ret && p != ret)
  1118. kfree(p);
  1119. return ret;
  1120. }
  1121. EXPORT_SYMBOL(krealloc);
  1122. /**
  1123. * kzfree - like kfree but zero memory
  1124. * @p: object to free memory of
  1125. *
  1126. * The memory of the object @p points to is zeroed before freed.
  1127. * If @p is %NULL, kzfree() does nothing.
  1128. *
  1129. * Note: this function zeroes the whole allocated buffer which can be a good
  1130. * deal bigger than the requested buffer size passed to kmalloc(). So be
  1131. * careful when using this function in performance sensitive code.
  1132. */
  1133. void kzfree(const void *p)
  1134. {
  1135. size_t ks;
  1136. void *mem = (void *)p;
  1137. if (unlikely(ZERO_OR_NULL_PTR(mem)))
  1138. return;
  1139. ks = ksize(mem);
  1140. memset(mem, 0, ks);
  1141. kfree(mem);
  1142. }
  1143. EXPORT_SYMBOL(kzfree);
  1144. /* Tracepoints definitions. */
  1145. EXPORT_TRACEPOINT_SYMBOL(kmalloc);
  1146. EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
  1147. EXPORT_TRACEPOINT_SYMBOL(kmalloc_node);
  1148. EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc_node);
  1149. EXPORT_TRACEPOINT_SYMBOL(kfree);
  1150. EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);