slab_common.c 32 KB

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