per-zone and reclaim enhancements for memory controller: calculate mapper_ratio per...
[safe/jmp/linux-2.6] / include / linux / memcontrol.h
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
20 #ifndef _LINUX_MEMCONTROL_H
21 #define _LINUX_MEMCONTROL_H
22
23 #include <linux/rcupdate.h>
24 #include <linux/mm.h>
25
26 struct mem_cgroup;
27 struct page_cgroup;
28 struct page;
29 struct mm_struct;
30
31 #ifdef CONFIG_CGROUP_MEM_CONT
32
33 extern void mm_init_cgroup(struct mm_struct *mm, struct task_struct *p);
34 extern void mm_free_cgroup(struct mm_struct *mm);
35 extern void page_assign_page_cgroup(struct page *page,
36                                         struct page_cgroup *pc);
37 extern struct page_cgroup *page_get_page_cgroup(struct page *page);
38 extern int mem_cgroup_charge(struct page *page, struct mm_struct *mm,
39                                 gfp_t gfp_mask);
40 extern void mem_cgroup_uncharge(struct page_cgroup *pc);
41 extern void mem_cgroup_move_lists(struct page_cgroup *pc, bool active);
42 extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
43                                         struct list_head *dst,
44                                         unsigned long *scanned, int order,
45                                         int mode, struct zone *z,
46                                         struct mem_cgroup *mem_cont,
47                                         int active);
48 extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask);
49 extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
50                                         gfp_t gfp_mask);
51 int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);
52
53 static inline struct mem_cgroup *mm_cgroup(const struct mm_struct *mm)
54 {
55         return rcu_dereference(mm->mem_cgroup);
56 }
57
58 static inline void mem_cgroup_uncharge_page(struct page *page)
59 {
60         mem_cgroup_uncharge(page_get_page_cgroup(page));
61 }
62
63 extern int mem_cgroup_prepare_migration(struct page *page);
64 extern void mem_cgroup_end_migration(struct page *page);
65 extern void mem_cgroup_page_migration(struct page *page, struct page *newpage);
66
67 /*
68  * For memory reclaim.
69  */
70 extern int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem);
71
72
73 #else /* CONFIG_CGROUP_MEM_CONT */
74 static inline void mm_init_cgroup(struct mm_struct *mm,
75                                         struct task_struct *p)
76 {
77 }
78
79 static inline void mm_free_cgroup(struct mm_struct *mm)
80 {
81 }
82
83 static inline void page_assign_page_cgroup(struct page *page,
84                                                 struct page_cgroup *pc)
85 {
86 }
87
88 static inline struct page_cgroup *page_get_page_cgroup(struct page *page)
89 {
90         return NULL;
91 }
92
93 static inline int mem_cgroup_charge(struct page *page, struct mm_struct *mm,
94                                         gfp_t gfp_mask)
95 {
96         return 0;
97 }
98
99 static inline void mem_cgroup_uncharge(struct page_cgroup *pc)
100 {
101 }
102
103 static inline void mem_cgroup_uncharge_page(struct page *page)
104 {
105 }
106
107 static inline void mem_cgroup_move_lists(struct page_cgroup *pc,
108                                                 bool active)
109 {
110 }
111
112 static inline int mem_cgroup_cache_charge(struct page *page,
113                                                 struct mm_struct *mm,
114                                                 gfp_t gfp_mask)
115 {
116         return 0;
117 }
118
119 static inline struct mem_cgroup *mm_cgroup(const struct mm_struct *mm)
120 {
121         return NULL;
122 }
123
124 static inline int task_in_mem_cgroup(struct task_struct *task,
125                                      const struct mem_cgroup *mem)
126 {
127         return 1;
128 }
129
130 static inline int mem_cgroup_prepare_migration(struct page *page)
131 {
132         return 0;
133 }
134
135 static inline void mem_cgroup_end_migration(struct page *page)
136 {
137 }
138
139 static inline void
140 mem_cgroup_page_migration(struct page *page, struct page *newpage)
141 {
142 }
143
144 static inline int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem)
145 {
146         return 0;
147 }
148 #endif /* CONFIG_CGROUP_MEM_CONT */
149
150 #endif /* _LINUX_MEMCONTROL_H */
151