memcontrol.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. struct mem_cgroup;
  23. struct page_cgroup;
  24. struct page;
  25. struct mm_struct;
  26. extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
  27. struct list_head *dst,
  28. unsigned long *scanned, int order,
  29. int mode, struct zone *z,
  30. struct mem_cgroup *mem_cont,
  31. int active, int file);
  32. #ifdef CONFIG_CGROUP_MEM_RES_CTLR
  33. /*
  34. * All "charge" functions with gfp_mask should use GFP_KERNEL or
  35. * (gfp_mask & GFP_RECLAIM_MASK). In current implementatin, memcg doesn't
  36. * alloc memory but reclaims memory from all available zones. So, "where I want
  37. * memory from" bits of gfp_mask has no meaning. So any bits of that field is
  38. * available but adding a rule is better. charge functions' gfp_mask should
  39. * be set to GFP_KERNEL or gfp_mask & GFP_RECLAIM_MASK for avoiding ambiguous
  40. * codes.
  41. * (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.)
  42. */
  43. extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm,
  44. gfp_t gfp_mask);
  45. /* for swap handling */
  46. extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
  47. struct page *page, gfp_t mask, struct mem_cgroup **ptr);
  48. extern void mem_cgroup_commit_charge_swapin(struct page *page,
  49. struct mem_cgroup *ptr);
  50. extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr);
  51. extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
  52. gfp_t gfp_mask);
  53. extern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru);
  54. extern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru);
  55. extern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru);
  56. extern void mem_cgroup_del_lru(struct page *page);
  57. extern void mem_cgroup_move_lists(struct page *page,
  58. enum lru_list from, enum lru_list to);
  59. /* For coalescing uncharge for reducing memcg' overhead*/
  60. extern void mem_cgroup_uncharge_start(void);
  61. extern void mem_cgroup_uncharge_end(void);
  62. extern void mem_cgroup_uncharge_page(struct page *page);
  63. extern void mem_cgroup_uncharge_cache_page(struct page *page);
  64. extern int mem_cgroup_shmem_charge_fallback(struct page *page,
  65. struct mm_struct *mm, gfp_t gfp_mask);
  66. extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask);
  67. int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);
  68. extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
  69. extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
  70. static inline
  71. int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
  72. {
  73. struct mem_cgroup *mem;
  74. rcu_read_lock();
  75. mem = mem_cgroup_from_task(rcu_dereference((mm)->owner));
  76. rcu_read_unlock();
  77. return cgroup == mem;
  78. }
  79. extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem);
  80. extern int
  81. mem_cgroup_prepare_migration(struct page *page,
  82. struct page *newpage, struct mem_cgroup **ptr);
  83. extern void mem_cgroup_end_migration(struct mem_cgroup *mem,
  84. struct page *oldpage, struct page *newpage);
  85. /*
  86. * For memory reclaim.
  87. */
  88. extern int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem);
  89. extern void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem,
  90. int priority);
  91. extern void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
  92. int priority);
  93. int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg);
  94. int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg);
  95. unsigned long mem_cgroup_zone_nr_pages(struct mem_cgroup *memcg,
  96. struct zone *zone,
  97. enum lru_list lru);
  98. struct zone_reclaim_stat *mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg,
  99. struct zone *zone);
  100. struct zone_reclaim_stat*
  101. mem_cgroup_get_reclaim_stat_from_page(struct page *page);
  102. extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
  103. struct task_struct *p);
  104. #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
  105. extern int do_swap_account;
  106. #endif
  107. static inline bool mem_cgroup_disabled(void)
  108. {
  109. if (mem_cgroup_subsys.disabled)
  110. return true;
  111. return false;
  112. }
  113. void mem_cgroup_update_file_mapped(struct page *page, int val);
  114. unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
  115. gfp_t gfp_mask, int nid,
  116. int zid);
  117. #else /* CONFIG_CGROUP_MEM_RES_CTLR */
  118. struct mem_cgroup;
  119. static inline int mem_cgroup_newpage_charge(struct page *page,
  120. struct mm_struct *mm, gfp_t gfp_mask)
  121. {
  122. return 0;
  123. }
  124. static inline int mem_cgroup_cache_charge(struct page *page,
  125. struct mm_struct *mm, gfp_t gfp_mask)
  126. {
  127. return 0;
  128. }
  129. static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
  130. struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr)
  131. {
  132. return 0;
  133. }
  134. static inline void mem_cgroup_commit_charge_swapin(struct page *page,
  135. struct mem_cgroup *ptr)
  136. {
  137. }
  138. static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr)
  139. {
  140. }
  141. static inline void mem_cgroup_uncharge_start(void)
  142. {
  143. }
  144. static inline void mem_cgroup_uncharge_end(void)
  145. {
  146. }
  147. static inline void mem_cgroup_uncharge_page(struct page *page)
  148. {
  149. }
  150. static inline void mem_cgroup_uncharge_cache_page(struct page *page)
  151. {
  152. }
  153. static inline int mem_cgroup_shmem_charge_fallback(struct page *page,
  154. struct mm_struct *mm, gfp_t gfp_mask)
  155. {
  156. return 0;
  157. }
  158. static inline void mem_cgroup_add_lru_list(struct page *page, int lru)
  159. {
  160. }
  161. static inline void mem_cgroup_del_lru_list(struct page *page, int lru)
  162. {
  163. return ;
  164. }
  165. static inline void mem_cgroup_rotate_lru_list(struct page *page, int lru)
  166. {
  167. return ;
  168. }
  169. static inline void mem_cgroup_del_lru(struct page *page)
  170. {
  171. return ;
  172. }
  173. static inline void
  174. mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to)
  175. {
  176. }
  177. static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
  178. {
  179. return NULL;
  180. }
  181. static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem)
  182. {
  183. return 1;
  184. }
  185. static inline int task_in_mem_cgroup(struct task_struct *task,
  186. const struct mem_cgroup *mem)
  187. {
  188. return 1;
  189. }
  190. static inline struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem)
  191. {
  192. return NULL;
  193. }
  194. static inline int
  195. mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
  196. struct mem_cgroup **ptr)
  197. {
  198. return 0;
  199. }
  200. static inline void mem_cgroup_end_migration(struct mem_cgroup *mem,
  201. struct page *oldpage,
  202. struct page *newpage)
  203. {
  204. }
  205. static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem)
  206. {
  207. return 0;
  208. }
  209. static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem,
  210. int priority)
  211. {
  212. }
  213. static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
  214. int priority)
  215. {
  216. }
  217. static inline bool mem_cgroup_disabled(void)
  218. {
  219. return true;
  220. }
  221. static inline int
  222. mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg)
  223. {
  224. return 1;
  225. }
  226. static inline int
  227. mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg)
  228. {
  229. return 1;
  230. }
  231. static inline unsigned long
  232. mem_cgroup_zone_nr_pages(struct mem_cgroup *memcg, struct zone *zone,
  233. enum lru_list lru)
  234. {
  235. return 0;
  236. }
  237. static inline struct zone_reclaim_stat*
  238. mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg, struct zone *zone)
  239. {
  240. return NULL;
  241. }
  242. static inline struct zone_reclaim_stat*
  243. mem_cgroup_get_reclaim_stat_from_page(struct page *page)
  244. {
  245. return NULL;
  246. }
  247. static inline void
  248. mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
  249. {
  250. }
  251. static inline void mem_cgroup_update_file_mapped(struct page *page,
  252. int val)
  253. {
  254. }
  255. static inline
  256. unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
  257. gfp_t gfp_mask, int nid, int zid)
  258. {
  259. return 0;
  260. }
  261. #endif /* CONFIG_CGROUP_MEM_CONT */
  262. #endif /* _LINUX_MEMCONTROL_H */