include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / include / linux / memcontrol.h
blob3b535db00a94983324d42106fae5bd05670f3157
1 /* memcontrol.h - Memory Controller
3 * Copyright IBM Corporation, 2007
4 * Author Balbir Singh <balbir@linux.vnet.ibm.com>
6 * Copyright 2007 OpenVZ SWsoft Inc
7 * Author: Pavel Emelianov <xemul@openvz.org>
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.
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.
20 #ifndef _LINUX_MEMCONTROL_H
21 #define _LINUX_MEMCONTROL_H
22 #include <linux/cgroup.h>
23 #include <linux/vm_event_item.h>
25 struct mem_cgroup;
26 struct page_cgroup;
27 struct page;
28 struct mm_struct;
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 */
35 extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
36 struct list_head *dst,
37 unsigned long *scanned, int order,
38 int mode, struct zone *z,
39 struct mem_cgroup *mem_cont,
40 int active, int file);
42 struct memcg_scanrecord {
43 struct mem_cgroup *mem; /* scanend memory cgroup */
44 struct mem_cgroup *root; /* scan target hierarchy root */
45 int context; /* scanning context (see memcontrol.c) */
46 unsigned long nr_scanned[2]; /* the number of scanned pages */
47 unsigned long nr_rotated[2]; /* the number of rotated pages */
48 unsigned long nr_freed[2]; /* the number of freed pages */
49 unsigned long elapsed; /* nsec of time elapsed while scanning */
52 #ifdef CONFIG_CGROUP_MEM_RES_CTLR
54 * All "charge" functions with gfp_mask should use GFP_KERNEL or
55 * (gfp_mask & GFP_RECLAIM_MASK). In current implementatin, memcg doesn't
56 * alloc memory but reclaims memory from all available zones. So, "where I want
57 * memory from" bits of gfp_mask has no meaning. So any bits of that field is
58 * available but adding a rule is better. charge functions' gfp_mask should
59 * be set to GFP_KERNEL or gfp_mask & GFP_RECLAIM_MASK for avoiding ambiguous
60 * codes.
61 * (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.)
64 extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm,
65 gfp_t gfp_mask);
66 /* for swap handling */
67 extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
68 struct page *page, gfp_t mask, struct mem_cgroup **ptr);
69 extern void mem_cgroup_commit_charge_swapin(struct page *page,
70 struct mem_cgroup *ptr);
71 extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr);
73 extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
74 gfp_t gfp_mask);
75 extern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru);
76 extern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru);
77 extern void mem_cgroup_rotate_reclaimable_page(struct page *page);
78 extern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru);
79 extern void mem_cgroup_del_lru(struct page *page);
80 extern void mem_cgroup_move_lists(struct page *page,
81 enum lru_list from, enum lru_list to);
83 /* For coalescing uncharge for reducing memcg' overhead*/
84 extern void mem_cgroup_uncharge_start(void);
85 extern void mem_cgroup_uncharge_end(void);
87 extern void mem_cgroup_uncharge_page(struct page *page);
88 extern void mem_cgroup_uncharge_cache_page(struct page *page);
90 extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask);
91 int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);
93 extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
94 extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
95 extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
97 static inline
98 int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
100 struct mem_cgroup *mem;
101 rcu_read_lock();
102 mem = mem_cgroup_from_task(rcu_dereference((mm)->owner));
103 rcu_read_unlock();
104 return cgroup == mem;
107 extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem);
109 extern int
110 mem_cgroup_prepare_migration(struct page *page,
111 struct page *newpage, struct mem_cgroup **ptr, gfp_t gfp_mask);
112 extern void mem_cgroup_end_migration(struct mem_cgroup *mem,
113 struct page *oldpage, struct page *newpage, bool migration_ok);
116 * For memory reclaim.
118 int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg);
119 int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg);
120 int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
121 unsigned long mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg,
122 int nid, int zid, unsigned int lrumask);
123 struct zone_reclaim_stat *mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg,
124 struct zone *zone);
125 struct zone_reclaim_stat*
126 mem_cgroup_get_reclaim_stat_from_page(struct page *page);
127 extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
128 struct task_struct *p);
130 extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem,
131 gfp_t gfp_mask, bool noswap,
132 struct memcg_scanrecord *rec);
133 extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
134 gfp_t gfp_mask, bool noswap,
135 struct zone *zone,
136 struct memcg_scanrecord *rec,
137 unsigned long *nr_scanned);
139 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
140 extern int do_swap_account;
141 #endif
143 static inline bool mem_cgroup_disabled(void)
145 if (mem_cgroup_subsys.disabled)
146 return true;
147 return false;
150 void mem_cgroup_update_page_stat(struct page *page,
151 enum mem_cgroup_page_stat_item idx,
152 int val);
154 static inline void mem_cgroup_inc_page_stat(struct page *page,
155 enum mem_cgroup_page_stat_item idx)
157 mem_cgroup_update_page_stat(page, idx, 1);
160 static inline void mem_cgroup_dec_page_stat(struct page *page,
161 enum mem_cgroup_page_stat_item idx)
163 mem_cgroup_update_page_stat(page, idx, -1);
166 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
167 gfp_t gfp_mask,
168 unsigned long *total_scanned);
169 u64 mem_cgroup_get_limit(struct mem_cgroup *mem);
171 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
172 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
173 void mem_cgroup_split_huge_fixup(struct page *head, struct page *tail);
174 #endif
176 #ifdef CONFIG_DEBUG_VM
177 bool mem_cgroup_bad_page_check(struct page *page);
178 void mem_cgroup_print_bad_page(struct page *page);
179 #endif
180 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
181 struct mem_cgroup;
183 static inline int mem_cgroup_newpage_charge(struct page *page,
184 struct mm_struct *mm, gfp_t gfp_mask)
186 return 0;
189 static inline int mem_cgroup_cache_charge(struct page *page,
190 struct mm_struct *mm, gfp_t gfp_mask)
192 return 0;
195 static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
196 struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr)
198 return 0;
201 static inline void mem_cgroup_commit_charge_swapin(struct page *page,
202 struct mem_cgroup *ptr)
206 static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr)
210 static inline void mem_cgroup_uncharge_start(void)
214 static inline void mem_cgroup_uncharge_end(void)
218 static inline void mem_cgroup_uncharge_page(struct page *page)
222 static inline void mem_cgroup_uncharge_cache_page(struct page *page)
226 static inline void mem_cgroup_add_lru_list(struct page *page, int lru)
230 static inline void mem_cgroup_del_lru_list(struct page *page, int lru)
232 return ;
235 static inline void mem_cgroup_rotate_reclaimable_page(struct page *page)
237 return ;
240 static inline void mem_cgroup_rotate_lru_list(struct page *page, int lru)
242 return ;
245 static inline void mem_cgroup_del_lru(struct page *page)
247 return ;
250 static inline void
251 mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to)
255 static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
257 return NULL;
260 static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
262 return NULL;
265 static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem)
267 return 1;
270 static inline int task_in_mem_cgroup(struct task_struct *task,
271 const struct mem_cgroup *mem)
273 return 1;
276 static inline struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem)
278 return NULL;
281 static inline int
282 mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
283 struct mem_cgroup **ptr, gfp_t gfp_mask)
285 return 0;
288 static inline void mem_cgroup_end_migration(struct mem_cgroup *mem,
289 struct page *oldpage, struct page *newpage, bool migration_ok)
293 static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem)
295 return 0;
298 static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem,
299 int priority)
303 static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
304 int priority)
308 static inline bool mem_cgroup_disabled(void)
310 return true;
313 static inline int
314 mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg)
316 return 1;
319 static inline int
320 mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg)
322 return 1;
325 static inline unsigned long
326 mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,
327 unsigned int lru_mask)
329 return 0;
333 static inline struct zone_reclaim_stat*
334 mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg, struct zone *zone)
336 return NULL;
339 static inline struct zone_reclaim_stat*
340 mem_cgroup_get_reclaim_stat_from_page(struct page *page)
342 return NULL;
345 static inline void
346 mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
350 static inline void mem_cgroup_inc_page_stat(struct page *page,
351 enum mem_cgroup_page_stat_item idx)
355 static inline void mem_cgroup_dec_page_stat(struct page *page,
356 enum mem_cgroup_page_stat_item idx)
360 static inline
361 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
362 gfp_t gfp_mask,
363 unsigned long *total_scanned)
365 return 0;
368 static inline
369 u64 mem_cgroup_get_limit(struct mem_cgroup *mem)
371 return 0;
374 static inline void mem_cgroup_split_huge_fixup(struct page *head,
375 struct page *tail)
379 static inline
380 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
383 #endif /* CONFIG_CGROUP_MEM_CONT */
385 #if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM)
386 static inline bool
387 mem_cgroup_bad_page_check(struct page *page)
389 return false;
392 static inline void
393 mem_cgroup_print_bad_page(struct page *page)
396 #endif
398 #endif /* _LINUX_MEMCONTROL_H */