memcontrol.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /* memcontrol.h - Memory Controller
  2. *
  3. * Copyright IBM Corporation, 2007
  4. * Author Balbir Singh <balbir@linux.vnet.ibm.com>
  5. *
  6. * Copyright 2007 OpenVZ SWsoft Inc
  7. * Author: Pavel Emelianov <xemul@openvz.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #ifndef _LINUX_MEMCONTROL_H
  20. #define _LINUX_MEMCONTROL_H
  21. #include <linux/cgroup.h>
  22. #include <linux/vm_event_item.h>
  23. #include <linux/hardirq.h>
  24. #include <linux/jump_label.h>
  25. struct mem_cgroup;
  26. struct page_cgroup;
  27. struct page;
  28. struct mm_struct;
  29. struct kmem_cache;
  30. /*
  31. * The corresponding mem_cgroup_stat_names is defined in mm/memcontrol.c,
  32. * These two lists should keep in accord with each other.
  33. */
  34. enum mem_cgroup_stat_index {
  35. /*
  36. * For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
  37. */
  38. MEM_CGROUP_STAT_CACHE, /* # of pages charged as cache */
  39. MEM_CGROUP_STAT_RSS, /* # of pages charged as anon rss */
  40. MEM_CGROUP_STAT_RSS_HUGE, /* # of pages charged as anon huge */
  41. MEM_CGROUP_STAT_FILE_MAPPED, /* # of pages charged as file rss */
  42. MEM_CGROUP_STAT_WRITEBACK, /* # of pages under writeback */
  43. MEM_CGROUP_STAT_SWAP, /* # of pages, swapped out */
  44. MEM_CGROUP_STAT_NSTATS,
  45. };
  46. struct mem_cgroup_reclaim_cookie {
  47. struct zone *zone;
  48. int priority;
  49. unsigned int generation;
  50. };
  51. #ifdef CONFIG_MEMCG
  52. /*
  53. * All "charge" functions with gfp_mask should use GFP_KERNEL or
  54. * (gfp_mask & GFP_RECLAIM_MASK). In current implementatin, memcg doesn't
  55. * alloc memory but reclaims memory from all available zones. So, "where I want
  56. * memory from" bits of gfp_mask has no meaning. So any bits of that field is
  57. * available but adding a rule is better. charge functions' gfp_mask should
  58. * be set to GFP_KERNEL or gfp_mask & GFP_RECLAIM_MASK for avoiding ambiguous
  59. * codes.
  60. * (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.)
  61. */
  62. extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm,
  63. gfp_t gfp_mask);
  64. /* for swap handling */
  65. extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
  66. struct page *page, gfp_t mask, struct mem_cgroup **memcgp);
  67. extern void mem_cgroup_commit_charge_swapin(struct page *page,
  68. struct mem_cgroup *memcg);
  69. extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg);
  70. extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
  71. gfp_t gfp_mask);
  72. struct lruvec *mem_cgroup_zone_lruvec(struct zone *, struct mem_cgroup *);
  73. struct lruvec *mem_cgroup_page_lruvec(struct page *, struct zone *);
  74. /* For coalescing uncharge for reducing memcg' overhead*/
  75. extern void mem_cgroup_uncharge_start(void);
  76. extern void mem_cgroup_uncharge_end(void);
  77. extern void mem_cgroup_uncharge_page(struct page *page);
  78. extern void mem_cgroup_uncharge_cache_page(struct page *page);
  79. bool __mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg,
  80. struct mem_cgroup *memcg);
  81. bool task_in_mem_cgroup(struct task_struct *task,
  82. const struct mem_cgroup *memcg);
  83. extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
  84. extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
  85. extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
  86. extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
  87. extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
  88. static inline
  89. bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
  90. {
  91. struct mem_cgroup *task_memcg;
  92. bool match;
  93. rcu_read_lock();
  94. task_memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
  95. match = __mem_cgroup_same_or_subtree(memcg, task_memcg);
  96. rcu_read_unlock();
  97. return match;
  98. }
  99. extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg);
  100. extern void
  101. mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
  102. struct mem_cgroup **memcgp);
  103. extern void mem_cgroup_end_migration(struct mem_cgroup *memcg,
  104. struct page *oldpage, struct page *newpage, bool migration_ok);
  105. struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *,
  106. struct mem_cgroup *,
  107. struct mem_cgroup_reclaim_cookie *);
  108. void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);
  109. /*
  110. * For memory reclaim.
  111. */
  112. int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec);
  113. int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
  114. unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list);
  115. void mem_cgroup_update_lru_size(struct lruvec *, enum lru_list, int);
  116. extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
  117. struct task_struct *p);
  118. extern void mem_cgroup_replace_page_cache(struct page *oldpage,
  119. struct page *newpage);
  120. /**
  121. * mem_cgroup_toggle_oom - toggle the memcg OOM killer for the current task
  122. * @new: true to enable, false to disable
  123. *
  124. * Toggle whether a failed memcg charge should invoke the OOM killer
  125. * or just return -ENOMEM. Returns the previous toggle state.
  126. *
  127. * NOTE: Any path that enables the OOM killer before charging must
  128. * call mem_cgroup_oom_synchronize() afterward to finalize the
  129. * OOM handling and clean up.
  130. */
  131. static inline bool mem_cgroup_toggle_oom(bool new)
  132. {
  133. bool old;
  134. old = current->memcg_oom.may_oom;
  135. current->memcg_oom.may_oom = new;
  136. return old;
  137. }
  138. static inline void mem_cgroup_enable_oom(void)
  139. {
  140. bool old = mem_cgroup_toggle_oom(true);
  141. WARN_ON(old == true);
  142. }
  143. static inline void mem_cgroup_disable_oom(void)
  144. {
  145. bool old = mem_cgroup_toggle_oom(false);
  146. WARN_ON(old == false);
  147. }
  148. static inline bool task_in_memcg_oom(struct task_struct *p)
  149. {
  150. return p->memcg_oom.in_memcg_oom;
  151. }
  152. bool mem_cgroup_oom_synchronize(void);
  153. #ifdef CONFIG_MEMCG_SWAP
  154. extern int do_swap_account;
  155. #endif
  156. static inline bool mem_cgroup_disabled(void)
  157. {
  158. if (mem_cgroup_subsys.disabled)
  159. return true;
  160. return false;
  161. }
  162. void __mem_cgroup_begin_update_page_stat(struct page *page, bool *locked,
  163. unsigned long *flags);
  164. extern atomic_t memcg_moving;
  165. static inline void mem_cgroup_begin_update_page_stat(struct page *page,
  166. bool *locked, unsigned long *flags)
  167. {
  168. if (mem_cgroup_disabled())
  169. return;
  170. rcu_read_lock();
  171. *locked = false;
  172. if (atomic_read(&memcg_moving))
  173. __mem_cgroup_begin_update_page_stat(page, locked, flags);
  174. }
  175. void __mem_cgroup_end_update_page_stat(struct page *page,
  176. unsigned long *flags);
  177. static inline void mem_cgroup_end_update_page_stat(struct page *page,
  178. bool *locked, unsigned long *flags)
  179. {
  180. if (mem_cgroup_disabled())
  181. return;
  182. if (*locked)
  183. __mem_cgroup_end_update_page_stat(page, flags);
  184. rcu_read_unlock();
  185. }
  186. void mem_cgroup_update_page_stat(struct page *page,
  187. enum mem_cgroup_stat_index idx,
  188. int val);
  189. static inline void mem_cgroup_inc_page_stat(struct page *page,
  190. enum mem_cgroup_stat_index idx)
  191. {
  192. mem_cgroup_update_page_stat(page, idx, 1);
  193. }
  194. static inline void mem_cgroup_dec_page_stat(struct page *page,
  195. enum mem_cgroup_stat_index idx)
  196. {
  197. mem_cgroup_update_page_stat(page, idx, -1);
  198. }
  199. bool mem_cgroup_soft_reclaim_eligible(struct mem_cgroup *memcg);
  200. void __mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
  201. static inline void mem_cgroup_count_vm_event(struct mm_struct *mm,
  202. enum vm_event_item idx)
  203. {
  204. if (mem_cgroup_disabled())
  205. return;
  206. __mem_cgroup_count_vm_event(mm, idx);
  207. }
  208. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  209. void mem_cgroup_split_huge_fixup(struct page *head);
  210. #endif
  211. #ifdef CONFIG_DEBUG_VM
  212. bool mem_cgroup_bad_page_check(struct page *page);
  213. void mem_cgroup_print_bad_page(struct page *page);
  214. #endif
  215. #else /* CONFIG_MEMCG */
  216. struct mem_cgroup;
  217. static inline int mem_cgroup_newpage_charge(struct page *page,
  218. struct mm_struct *mm, gfp_t gfp_mask)
  219. {
  220. return 0;
  221. }
  222. static inline int mem_cgroup_cache_charge(struct page *page,
  223. struct mm_struct *mm, gfp_t gfp_mask)
  224. {
  225. return 0;
  226. }
  227. static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
  228. struct page *page, gfp_t gfp_mask, struct mem_cgroup **memcgp)
  229. {
  230. return 0;
  231. }
  232. static inline void mem_cgroup_commit_charge_swapin(struct page *page,
  233. struct mem_cgroup *memcg)
  234. {
  235. }
  236. static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg)
  237. {
  238. }
  239. static inline void mem_cgroup_uncharge_start(void)
  240. {
  241. }
  242. static inline void mem_cgroup_uncharge_end(void)
  243. {
  244. }
  245. static inline void mem_cgroup_uncharge_page(struct page *page)
  246. {
  247. }
  248. static inline void mem_cgroup_uncharge_cache_page(struct page *page)
  249. {
  250. }
  251. static inline struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,
  252. struct mem_cgroup *memcg)
  253. {
  254. return &zone->lruvec;
  255. }
  256. static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,
  257. struct zone *zone)
  258. {
  259. return &zone->lruvec;
  260. }
  261. static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
  262. {
  263. return NULL;
  264. }
  265. static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
  266. {
  267. return NULL;
  268. }
  269. static inline bool mm_match_cgroup(struct mm_struct *mm,
  270. struct mem_cgroup *memcg)
  271. {
  272. return true;
  273. }
  274. static inline bool task_in_mem_cgroup(struct task_struct *task,
  275. const struct mem_cgroup *memcg)
  276. {
  277. return true;
  278. }
  279. static inline struct cgroup_subsys_state
  280. *mem_cgroup_css(struct mem_cgroup *memcg)
  281. {
  282. return NULL;
  283. }
  284. static inline void
  285. mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
  286. struct mem_cgroup **memcgp)
  287. {
  288. }
  289. static inline void mem_cgroup_end_migration(struct mem_cgroup *memcg,
  290. struct page *oldpage, struct page *newpage, bool migration_ok)
  291. {
  292. }
  293. static inline struct mem_cgroup *
  294. mem_cgroup_iter(struct mem_cgroup *root,
  295. struct mem_cgroup *prev,
  296. struct mem_cgroup_reclaim_cookie *reclaim)
  297. {
  298. return NULL;
  299. }
  300. static inline void mem_cgroup_iter_break(struct mem_cgroup *root,
  301. struct mem_cgroup *prev)
  302. {
  303. }
  304. static inline bool mem_cgroup_disabled(void)
  305. {
  306. return true;
  307. }
  308. static inline int
  309. mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)
  310. {
  311. return 1;
  312. }
  313. static inline unsigned long
  314. mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list lru)
  315. {
  316. return 0;
  317. }
  318. static inline void
  319. mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
  320. int increment)
  321. {
  322. }
  323. static inline void
  324. mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
  325. {
  326. }
  327. static inline void mem_cgroup_begin_update_page_stat(struct page *page,
  328. bool *locked, unsigned long *flags)
  329. {
  330. }
  331. static inline void mem_cgroup_end_update_page_stat(struct page *page,
  332. bool *locked, unsigned long *flags)
  333. {
  334. }
  335. static inline bool mem_cgroup_toggle_oom(bool new)
  336. {
  337. return false;
  338. }
  339. static inline void mem_cgroup_enable_oom(void)
  340. {
  341. }
  342. static inline void mem_cgroup_disable_oom(void)
  343. {
  344. }
  345. static inline bool task_in_memcg_oom(struct task_struct *p)
  346. {
  347. return false;
  348. }
  349. static inline bool mem_cgroup_oom_synchronize(void)
  350. {
  351. return false;
  352. }
  353. static inline void mem_cgroup_inc_page_stat(struct page *page,
  354. enum mem_cgroup_stat_index idx)
  355. {
  356. }
  357. static inline void mem_cgroup_dec_page_stat(struct page *page,
  358. enum mem_cgroup_stat_index idx)
  359. {
  360. }
  361. static inline
  362. bool mem_cgroup_soft_reclaim_eligible(struct mem_cgroup *memcg)
  363. {
  364. return false;
  365. }
  366. static inline void mem_cgroup_split_huge_fixup(struct page *head)
  367. {
  368. }
  369. static inline
  370. void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
  371. {
  372. }
  373. static inline void mem_cgroup_replace_page_cache(struct page *oldpage,
  374. struct page *newpage)
  375. {
  376. }
  377. #endif /* CONFIG_MEMCG */
  378. #if !defined(CONFIG_MEMCG) || !defined(CONFIG_DEBUG_VM)
  379. static inline bool
  380. mem_cgroup_bad_page_check(struct page *page)
  381. {
  382. return false;
  383. }
  384. static inline void
  385. mem_cgroup_print_bad_page(struct page *page)
  386. {
  387. }
  388. #endif
  389. enum {
  390. UNDER_LIMIT,
  391. SOFT_LIMIT,
  392. OVER_LIMIT,
  393. };
  394. struct sock;
  395. #if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM)
  396. void sock_update_memcg(struct sock *sk);
  397. void sock_release_memcg(struct sock *sk);
  398. #else
  399. static inline void sock_update_memcg(struct sock *sk)
  400. {
  401. }
  402. static inline void sock_release_memcg(struct sock *sk)
  403. {
  404. }
  405. #endif /* CONFIG_INET && CONFIG_MEMCG_KMEM */
  406. #ifdef CONFIG_MEMCG_KMEM
  407. extern struct static_key memcg_kmem_enabled_key;
  408. extern int memcg_limited_groups_array_size;
  409. /*
  410. * Helper macro to loop through all memcg-specific caches. Callers must still
  411. * check if the cache is valid (it is either valid or NULL).
  412. * the slab_mutex must be held when looping through those caches
  413. */
  414. #define for_each_memcg_cache_index(_idx) \
  415. for ((_idx) = 0; (_idx) < memcg_limited_groups_array_size; (_idx)++)
  416. static inline bool memcg_kmem_enabled(void)
  417. {
  418. return static_key_false(&memcg_kmem_enabled_key);
  419. }
  420. /*
  421. * In general, we'll do everything in our power to not incur in any overhead
  422. * for non-memcg users for the kmem functions. Not even a function call, if we
  423. * can avoid it.
  424. *
  425. * Therefore, we'll inline all those functions so that in the best case, we'll
  426. * see that kmemcg is off for everybody and proceed quickly. If it is on,
  427. * we'll still do most of the flag checking inline. We check a lot of
  428. * conditions, but because they are pretty simple, they are expected to be
  429. * fast.
  430. */
  431. bool __memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg,
  432. int order);
  433. void __memcg_kmem_commit_charge(struct page *page,
  434. struct mem_cgroup *memcg, int order);
  435. void __memcg_kmem_uncharge_pages(struct page *page, int order);
  436. int memcg_cache_id(struct mem_cgroup *memcg);
  437. int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s,
  438. struct kmem_cache *root_cache);
  439. void memcg_release_cache(struct kmem_cache *cachep);
  440. void memcg_cache_list_add(struct mem_cgroup *memcg, struct kmem_cache *cachep);
  441. int memcg_update_cache_size(struct kmem_cache *s, int num_groups);
  442. void memcg_update_array_size(int num_groups);
  443. struct kmem_cache *
  444. __memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp);
  445. void mem_cgroup_destroy_cache(struct kmem_cache *cachep);
  446. void kmem_cache_destroy_memcg_children(struct kmem_cache *s);
  447. /**
  448. * memcg_kmem_newpage_charge: verify if a new kmem allocation is allowed.
  449. * @gfp: the gfp allocation flags.
  450. * @memcg: a pointer to the memcg this was charged against.
  451. * @order: allocation order.
  452. *
  453. * returns true if the memcg where the current task belongs can hold this
  454. * allocation.
  455. *
  456. * We return true automatically if this allocation is not to be accounted to
  457. * any memcg.
  458. */
  459. static inline bool
  460. memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg, int order)
  461. {
  462. if (!memcg_kmem_enabled())
  463. return true;
  464. /*
  465. * __GFP_NOFAIL allocations will move on even if charging is not
  466. * possible. Therefore we don't even try, and have this allocation
  467. * unaccounted. We could in theory charge it with
  468. * res_counter_charge_nofail, but we hope those allocations are rare,
  469. * and won't be worth the trouble.
  470. */
  471. if (!(gfp & __GFP_KMEMCG) || (gfp & __GFP_NOFAIL))
  472. return true;
  473. if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
  474. return true;
  475. /* If the test is dying, just let it go. */
  476. if (unlikely(fatal_signal_pending(current)))
  477. return true;
  478. return __memcg_kmem_newpage_charge(gfp, memcg, order);
  479. }
  480. /**
  481. * memcg_kmem_uncharge_pages: uncharge pages from memcg
  482. * @page: pointer to struct page being freed
  483. * @order: allocation order.
  484. *
  485. * there is no need to specify memcg here, since it is embedded in page_cgroup
  486. */
  487. static inline void
  488. memcg_kmem_uncharge_pages(struct page *page, int order)
  489. {
  490. if (memcg_kmem_enabled())
  491. __memcg_kmem_uncharge_pages(page, order);
  492. }
  493. /**
  494. * memcg_kmem_commit_charge: embeds correct memcg in a page
  495. * @page: pointer to struct page recently allocated
  496. * @memcg: the memcg structure we charged against
  497. * @order: allocation order.
  498. *
  499. * Needs to be called after memcg_kmem_newpage_charge, regardless of success or
  500. * failure of the allocation. if @page is NULL, this function will revert the
  501. * charges. Otherwise, it will commit the memcg given by @memcg to the
  502. * corresponding page_cgroup.
  503. */
  504. static inline void
  505. memcg_kmem_commit_charge(struct page *page, struct mem_cgroup *memcg, int order)
  506. {
  507. if (memcg_kmem_enabled() && memcg)
  508. __memcg_kmem_commit_charge(page, memcg, order);
  509. }
  510. /**
  511. * memcg_kmem_get_cache: selects the correct per-memcg cache for allocation
  512. * @cachep: the original global kmem cache
  513. * @gfp: allocation flags.
  514. *
  515. * This function assumes that the task allocating, which determines the memcg
  516. * in the page allocator, belongs to the same cgroup throughout the whole
  517. * process. Misacounting can happen if the task calls memcg_kmem_get_cache()
  518. * while belonging to a cgroup, and later on changes. This is considered
  519. * acceptable, and should only happen upon task migration.
  520. *
  521. * Before the cache is created by the memcg core, there is also a possible
  522. * imbalance: the task belongs to a memcg, but the cache being allocated from
  523. * is the global cache, since the child cache is not yet guaranteed to be
  524. * ready. This case is also fine, since in this case the GFP_KMEMCG will not be
  525. * passed and the page allocator will not attempt any cgroup accounting.
  526. */
  527. static __always_inline struct kmem_cache *
  528. memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
  529. {
  530. if (!memcg_kmem_enabled())
  531. return cachep;
  532. if (gfp & __GFP_NOFAIL)
  533. return cachep;
  534. if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
  535. return cachep;
  536. if (unlikely(fatal_signal_pending(current)))
  537. return cachep;
  538. return __memcg_kmem_get_cache(cachep, gfp);
  539. }
  540. #else
  541. #define for_each_memcg_cache_index(_idx) \
  542. for (; NULL; )
  543. static inline bool memcg_kmem_enabled(void)
  544. {
  545. return false;
  546. }
  547. static inline bool
  548. memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg, int order)
  549. {
  550. return true;
  551. }
  552. static inline void memcg_kmem_uncharge_pages(struct page *page, int order)
  553. {
  554. }
  555. static inline void
  556. memcg_kmem_commit_charge(struct page *page, struct mem_cgroup *memcg, int order)
  557. {
  558. }
  559. static inline int memcg_cache_id(struct mem_cgroup *memcg)
  560. {
  561. return -1;
  562. }
  563. static inline int
  564. memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s,
  565. struct kmem_cache *root_cache)
  566. {
  567. return 0;
  568. }
  569. static inline void memcg_release_cache(struct kmem_cache *cachep)
  570. {
  571. }
  572. static inline void memcg_cache_list_add(struct mem_cgroup *memcg,
  573. struct kmem_cache *s)
  574. {
  575. }
  576. static inline struct kmem_cache *
  577. memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
  578. {
  579. return cachep;
  580. }
  581. static inline void kmem_cache_destroy_memcg_children(struct kmem_cache *s)
  582. {
  583. }
  584. #endif /* CONFIG_MEMCG_KMEM */
  585. #endif /* _LINUX_MEMCONTROL_H */