Commit | Line | Data |
---|---|---|
8cdea7c0 BS |
1 | /* memcontrol.h - Memory Controller |
2 | * | |
3 | * Copyright IBM Corporation, 2007 | |
4 | * Author Balbir Singh <balbir@linux.vnet.ibm.com> | |
5 | * | |
78fb7466 PE |
6 | * Copyright 2007 OpenVZ SWsoft Inc |
7 | * Author: Pavel Emelianov <xemul@openvz.org> | |
8 | * | |
8cdea7c0 BS |
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 | ||
20 | #ifndef _LINUX_MEMCONTROL_H | |
21 | #define _LINUX_MEMCONTROL_H | |
f8d66542 | 22 | #include <linux/cgroup.h> |
456f998e YH |
23 | #include <linux/vm_event_item.h> |
24 | ||
78fb7466 PE |
25 | struct mem_cgroup; |
26 | struct page_cgroup; | |
8697d331 BS |
27 | struct page; |
28 | struct mm_struct; | |
78fb7466 | 29 | |
2a7106f2 GT |
30 | /* Stats that can be updated by kernel. */ |
31 | enum mem_cgroup_page_stat_item { | |
32 | MEMCG_NR_FILE_MAPPED, /* # of pages charged as file rss */ | |
33 | }; | |
34 | ||
8b25c6d2 JW |
35 | extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, |
36 | struct list_head *dst, | |
37 | unsigned long *scanned, int order, | |
4356f21d MK |
38 | isolate_mode_t mode, |
39 | struct zone *z, | |
8b25c6d2 JW |
40 | struct mem_cgroup *mem_cont, |
41 | int active, int file); | |
42 | ||
00f0b825 | 43 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR |
2c26fdd7 KH |
44 | /* |
45 | * All "charge" functions with gfp_mask should use GFP_KERNEL or | |
46 | * (gfp_mask & GFP_RECLAIM_MASK). In current implementatin, memcg doesn't | |
47 | * alloc memory but reclaims memory from all available zones. So, "where I want | |
48 | * memory from" bits of gfp_mask has no meaning. So any bits of that field is | |
49 | * available but adding a rule is better. charge functions' gfp_mask should | |
50 | * be set to GFP_KERNEL or gfp_mask & GFP_RECLAIM_MASK for avoiding ambiguous | |
51 | * codes. | |
52 | * (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.) | |
53 | */ | |
78fb7466 | 54 | |
7a81b88c | 55 | extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm, |
e1a1cd59 | 56 | gfp_t gfp_mask); |
7a81b88c | 57 | /* for swap handling */ |
8c7c6e34 KH |
58 | extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm, |
59 | struct page *page, gfp_t mask, struct mem_cgroup **ptr); | |
7a81b88c KH |
60 | extern void mem_cgroup_commit_charge_swapin(struct page *page, |
61 | struct mem_cgroup *ptr); | |
62 | extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr); | |
63 | ||
8289546e HD |
64 | extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, |
65 | gfp_t gfp_mask); | |
08e552c6 KH |
66 | extern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru); |
67 | extern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru); | |
3f58a829 | 68 | extern void mem_cgroup_rotate_reclaimable_page(struct page *page); |
08e552c6 KH |
69 | extern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru); |
70 | extern void mem_cgroup_del_lru(struct page *page); | |
71 | extern void mem_cgroup_move_lists(struct page *page, | |
72 | enum lru_list from, enum lru_list to); | |
569b846d KH |
73 | |
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 | ||
3c541e14 | 78 | extern void mem_cgroup_uncharge_page(struct page *page); |
69029cd5 | 79 | extern void mem_cgroup_uncharge_cache_page(struct page *page); |
c9b0ed51 | 80 | |
c7ba5c9e | 81 | extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask); |
4c4a2214 | 82 | int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem); |
3062fc67 | 83 | |
e42d9d5d | 84 | extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page); |
cf475ad2 | 85 | extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); |
a433658c | 86 | extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm); |
cf475ad2 | 87 | |
2e4d4091 LJ |
88 | static inline |
89 | int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup) | |
90 | { | |
91 | struct mem_cgroup *mem; | |
92 | rcu_read_lock(); | |
e638c139 | 93 | mem = mem_cgroup_from_task(rcu_dereference((mm)->owner)); |
2e4d4091 LJ |
94 | rcu_read_unlock(); |
95 | return cgroup == mem; | |
96 | } | |
8a9f3ccd | 97 | |
d324236b WF |
98 | extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem); |
99 | ||
e8589cc1 | 100 | extern int |
ac39cf8c | 101 | mem_cgroup_prepare_migration(struct page *page, |
ef6a3c63 | 102 | struct page *newpage, struct mem_cgroup **ptr, gfp_t gfp_mask); |
01b1ae63 | 103 | extern void mem_cgroup_end_migration(struct mem_cgroup *mem, |
50de1dd9 | 104 | struct page *oldpage, struct page *newpage, bool migration_ok); |
ae41be37 | 105 | |
58ae83db KH |
106 | /* |
107 | * For memory reclaim. | |
108 | */ | |
c772be93 | 109 | int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg); |
56e49d21 | 110 | int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg); |
889976db | 111 | int mem_cgroup_select_victim_node(struct mem_cgroup *memcg); |
1bac180b | 112 | unsigned long mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, |
bb2a0de9 | 113 | int nid, int zid, unsigned int lrumask); |
3e2f41f1 KM |
114 | struct zone_reclaim_stat *mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg, |
115 | struct zone *zone); | |
116 | struct zone_reclaim_stat* | |
117 | mem_cgroup_get_reclaim_stat_from_page(struct page *page); | |
e222432b BS |
118 | extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, |
119 | struct task_struct *p); | |
58ae83db | 120 | |
c077719b KH |
121 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP |
122 | extern int do_swap_account; | |
123 | #endif | |
f8d66542 HT |
124 | |
125 | static inline bool mem_cgroup_disabled(void) | |
126 | { | |
127 | if (mem_cgroup_subsys.disabled) | |
128 | return true; | |
129 | return false; | |
130 | } | |
131 | ||
2a7106f2 GT |
132 | void mem_cgroup_update_page_stat(struct page *page, |
133 | enum mem_cgroup_page_stat_item idx, | |
134 | int val); | |
135 | ||
136 | static inline void mem_cgroup_inc_page_stat(struct page *page, | |
137 | enum mem_cgroup_page_stat_item idx) | |
138 | { | |
139 | mem_cgroup_update_page_stat(page, idx, 1); | |
140 | } | |
141 | ||
142 | static inline void mem_cgroup_dec_page_stat(struct page *page, | |
143 | enum mem_cgroup_page_stat_item idx) | |
144 | { | |
145 | mem_cgroup_update_page_stat(page, idx, -1); | |
146 | } | |
147 | ||
4e416953 | 148 | unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, |
0ae5e89c YH |
149 | gfp_t gfp_mask, |
150 | unsigned long *total_scanned); | |
a63d83f4 DR |
151 | u64 mem_cgroup_get_limit(struct mem_cgroup *mem); |
152 | ||
456f998e | 153 | void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx); |
ca3e0214 KH |
154 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
155 | void mem_cgroup_split_huge_fixup(struct page *head, struct page *tail); | |
156 | #endif | |
157 | ||
f212ad7c DN |
158 | #ifdef CONFIG_DEBUG_VM |
159 | bool mem_cgroup_bad_page_check(struct page *page); | |
160 | void mem_cgroup_print_bad_page(struct page *page); | |
161 | #endif | |
52d4b9ac | 162 | #else /* CONFIG_CGROUP_MEM_RES_CTLR */ |
7a81b88c KH |
163 | struct mem_cgroup; |
164 | ||
165 | static inline int mem_cgroup_newpage_charge(struct page *page, | |
8289546e | 166 | struct mm_struct *mm, gfp_t gfp_mask) |
8a9f3ccd BS |
167 | { |
168 | return 0; | |
169 | } | |
170 | ||
8289546e HD |
171 | static inline int mem_cgroup_cache_charge(struct page *page, |
172 | struct mm_struct *mm, gfp_t gfp_mask) | |
8a9f3ccd | 173 | { |
8289546e | 174 | return 0; |
8a9f3ccd BS |
175 | } |
176 | ||
8c7c6e34 KH |
177 | static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm, |
178 | struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr) | |
7a81b88c KH |
179 | { |
180 | return 0; | |
181 | } | |
182 | ||
183 | static inline void mem_cgroup_commit_charge_swapin(struct page *page, | |
184 | struct mem_cgroup *ptr) | |
185 | { | |
186 | } | |
187 | ||
188 | static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr) | |
189 | { | |
190 | } | |
191 | ||
569b846d KH |
192 | static inline void mem_cgroup_uncharge_start(void) |
193 | { | |
194 | } | |
195 | ||
196 | static inline void mem_cgroup_uncharge_end(void) | |
197 | { | |
198 | } | |
199 | ||
8a9f3ccd BS |
200 | static inline void mem_cgroup_uncharge_page(struct page *page) |
201 | { | |
202 | } | |
203 | ||
69029cd5 KH |
204 | static inline void mem_cgroup_uncharge_cache_page(struct page *page) |
205 | { | |
206 | } | |
207 | ||
08e552c6 KH |
208 | static inline void mem_cgroup_add_lru_list(struct page *page, int lru) |
209 | { | |
210 | } | |
211 | ||
212 | static inline void mem_cgroup_del_lru_list(struct page *page, int lru) | |
213 | { | |
214 | return ; | |
215 | } | |
216 | ||
67954fe9 | 217 | static inline void mem_cgroup_rotate_reclaimable_page(struct page *page) |
3f58a829 MK |
218 | { |
219 | return ; | |
220 | } | |
221 | ||
08e552c6 KH |
222 | static inline void mem_cgroup_rotate_lru_list(struct page *page, int lru) |
223 | { | |
224 | return ; | |
225 | } | |
226 | ||
227 | static inline void mem_cgroup_del_lru(struct page *page) | |
228 | { | |
229 | return ; | |
230 | } | |
231 | ||
232 | static inline void | |
233 | mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to) | |
66e1707b BS |
234 | { |
235 | } | |
236 | ||
e42d9d5d WF |
237 | static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) |
238 | { | |
239 | return NULL; | |
240 | } | |
241 | ||
a433658c KM |
242 | static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm) |
243 | { | |
244 | return NULL; | |
245 | } | |
246 | ||
bd845e38 | 247 | static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem) |
bed7161a | 248 | { |
60c12b12 | 249 | return 1; |
bed7161a BS |
250 | } |
251 | ||
4c4a2214 DR |
252 | static inline int task_in_mem_cgroup(struct task_struct *task, |
253 | const struct mem_cgroup *mem) | |
254 | { | |
255 | return 1; | |
256 | } | |
257 | ||
d324236b WF |
258 | static inline struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem) |
259 | { | |
260 | return NULL; | |
261 | } | |
262 | ||
e8589cc1 | 263 | static inline int |
ac39cf8c | 264 | mem_cgroup_prepare_migration(struct page *page, struct page *newpage, |
ef6a3c63 | 265 | struct mem_cgroup **ptr, gfp_t gfp_mask) |
ae41be37 KH |
266 | { |
267 | return 0; | |
268 | } | |
269 | ||
01b1ae63 | 270 | static inline void mem_cgroup_end_migration(struct mem_cgroup *mem, |
50de1dd9 | 271 | struct page *oldpage, struct page *newpage, bool migration_ok) |
ae41be37 KH |
272 | { |
273 | } | |
274 | ||
6c48a1d0 KH |
275 | static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem) |
276 | { | |
277 | return 0; | |
278 | } | |
279 | ||
280 | static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem, | |
281 | int priority) | |
282 | { | |
283 | } | |
284 | ||
285 | static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem, | |
286 | int priority) | |
287 | { | |
288 | } | |
289 | ||
f8d66542 HT |
290 | static inline bool mem_cgroup_disabled(void) |
291 | { | |
292 | return true; | |
293 | } | |
a636b327 | 294 | |
14797e23 | 295 | static inline int |
c772be93 | 296 | mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg) |
14797e23 KM |
297 | { |
298 | return 1; | |
299 | } | |
300 | ||
56e49d21 RR |
301 | static inline int |
302 | mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg) | |
303 | { | |
304 | return 1; | |
305 | } | |
306 | ||
a3d8e054 | 307 | static inline unsigned long |
bb2a0de9 KH |
308 | mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid, |
309 | unsigned int lru_mask) | |
a3d8e054 KM |
310 | { |
311 | return 0; | |
312 | } | |
313 | ||
314 | ||
3e2f41f1 KM |
315 | static inline struct zone_reclaim_stat* |
316 | mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg, struct zone *zone) | |
317 | { | |
318 | return NULL; | |
319 | } | |
320 | ||
321 | static inline struct zone_reclaim_stat* | |
322 | mem_cgroup_get_reclaim_stat_from_page(struct page *page) | |
323 | { | |
324 | return NULL; | |
325 | } | |
326 | ||
e222432b BS |
327 | static inline void |
328 | mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p) | |
329 | { | |
330 | } | |
331 | ||
2a7106f2 GT |
332 | static inline void mem_cgroup_inc_page_stat(struct page *page, |
333 | enum mem_cgroup_page_stat_item idx) | |
334 | { | |
335 | } | |
336 | ||
337 | static inline void mem_cgroup_dec_page_stat(struct page *page, | |
338 | enum mem_cgroup_page_stat_item idx) | |
d69b042f BS |
339 | { |
340 | } | |
341 | ||
4e416953 BS |
342 | static inline |
343 | unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, | |
0ae5e89c YH |
344 | gfp_t gfp_mask, |
345 | unsigned long *total_scanned) | |
4e416953 BS |
346 | { |
347 | return 0; | |
348 | } | |
349 | ||
a63d83f4 DR |
350 | static inline |
351 | u64 mem_cgroup_get_limit(struct mem_cgroup *mem) | |
352 | { | |
353 | return 0; | |
354 | } | |
355 | ||
ca3e0214 KH |
356 | static inline void mem_cgroup_split_huge_fixup(struct page *head, |
357 | struct page *tail) | |
358 | { | |
359 | } | |
360 | ||
456f998e YH |
361 | static inline |
362 | void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx) | |
363 | { | |
364 | } | |
78fb7466 PE |
365 | #endif /* CONFIG_CGROUP_MEM_CONT */ |
366 | ||
f212ad7c DN |
367 | #if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM) |
368 | static inline bool | |
369 | mem_cgroup_bad_page_check(struct page *page) | |
370 | { | |
371 | return false; | |
372 | } | |
373 | ||
374 | static inline void | |
375 | mem_cgroup_print_bad_page(struct page *page) | |
376 | { | |
377 | } | |
378 | #endif | |
379 | ||
8cdea7c0 BS |
380 | #endif /* _LINUX_MEMCONTROL_H */ |
381 |