Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1 | /* memcontrol.h - Memory Controller |
| 2 | * |
| 3 | * Copyright IBM Corporation, 2007 |
| 4 | * Author Balbir Singh <balbir@linux.vnet.ibm.com> |
| 5 | * |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 6 | * Copyright 2007 OpenVZ SWsoft Inc |
| 7 | * Author: Pavel Emelianov <xemul@openvz.org> |
| 8 | * |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 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 |
Hirokazu Takahashi | f8d6654 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 22 | #include <linux/cgroup.h> |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 23 | struct mem_cgroup; |
| 24 | struct page_cgroup; |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 25 | struct page; |
| 26 | struct mm_struct; |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 27 | |
Balbir Singh | 00f0b82 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 28 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 29 | |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 30 | extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm, |
Balbir Singh | e1a1cd5 | 2008-02-07 00:14:02 -0800 | [diff] [blame] | 31 | gfp_t gfp_mask); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 32 | /* for swap handling */ |
| 33 | extern int mem_cgroup_try_charge(struct mm_struct *mm, |
| 34 | gfp_t gfp_mask, struct mem_cgroup **ptr); |
KAMEZAWA Hiroyuki | 8c7c6e3 | 2009-01-07 18:08:00 -0800 | [diff] [blame] | 35 | extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm, |
| 36 | struct page *page, gfp_t mask, struct mem_cgroup **ptr); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 37 | extern void mem_cgroup_commit_charge_swapin(struct page *page, |
| 38 | struct mem_cgroup *ptr); |
| 39 | extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr); |
| 40 | |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 41 | extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, |
| 42 | gfp_t gfp_mask); |
KAMEZAWA Hiroyuki | 08e552c | 2009-01-07 18:08:01 -0800 | [diff] [blame] | 43 | extern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru); |
| 44 | extern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru); |
| 45 | extern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru); |
| 46 | extern void mem_cgroup_del_lru(struct page *page); |
| 47 | extern void mem_cgroup_move_lists(struct page *page, |
| 48 | enum lru_list from, enum lru_list to); |
Balbir Singh | 3c541e1 | 2008-02-07 00:14:41 -0800 | [diff] [blame] | 49 | extern void mem_cgroup_uncharge_page(struct page *page); |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 50 | extern void mem_cgroup_uncharge_cache_page(struct page *page); |
KAMEZAWA Hiroyuki | c9b0ed5 | 2008-07-25 01:47:15 -0700 | [diff] [blame] | 51 | extern int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask); |
| 52 | |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 53 | extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, |
| 54 | struct list_head *dst, |
| 55 | unsigned long *scanned, int order, |
| 56 | int mode, struct zone *z, |
| 57 | struct mem_cgroup *mem_cont, |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 58 | int active, int file); |
Pavel Emelianov | c7ba5c9 | 2008-02-07 00:13:58 -0800 | [diff] [blame] | 59 | extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask); |
David Rientjes | 4c4a221 | 2008-02-07 00:14:06 -0800 | [diff] [blame] | 60 | int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem); |
David Rientjes | 3062fc6 | 2008-02-07 00:14:03 -0800 | [diff] [blame] | 61 | |
Balbir Singh | cf475ad | 2008-04-29 01:00:16 -0700 | [diff] [blame] | 62 | extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); |
| 63 | |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 64 | static inline |
| 65 | int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup) |
| 66 | { |
| 67 | struct mem_cgroup *mem; |
| 68 | rcu_read_lock(); |
| 69 | mem = mem_cgroup_from_task((mm)->owner); |
| 70 | rcu_read_unlock(); |
| 71 | return cgroup == mem; |
| 72 | } |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 73 | |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 74 | extern int |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 75 | mem_cgroup_prepare_migration(struct page *page, struct mem_cgroup **ptr); |
| 76 | extern void mem_cgroup_end_migration(struct mem_cgroup *mem, |
| 77 | struct page *oldpage, struct page *newpage); |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 78 | |
KAMEZAWA Hiroyuki | 58ae83d | 2008-02-07 00:14:32 -0800 | [diff] [blame] | 79 | /* |
| 80 | * For memory reclaim. |
| 81 | */ |
| 82 | extern int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem); |
KAMEZAWA Hiroyuki | 5932f36 | 2008-02-07 00:14:33 -0800 | [diff] [blame] | 83 | extern long mem_cgroup_reclaim_imbalance(struct mem_cgroup *mem); |
| 84 | |
KAMEZAWA Hiroyuki | 6c48a1d | 2008-02-07 00:14:34 -0800 | [diff] [blame] | 85 | extern int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem); |
| 86 | extern void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem, |
| 87 | int priority); |
| 88 | extern void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem, |
| 89 | int priority); |
KAMEZAWA Hiroyuki | 58ae83d | 2008-02-07 00:14:32 -0800 | [diff] [blame] | 90 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 91 | extern long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone, |
| 92 | int priority, enum lru_list lru); |
KAMEZAWA Hiroyuki | 58ae83d | 2008-02-07 00:14:32 -0800 | [diff] [blame] | 93 | |
KAMEZAWA Hiroyuki | c077719 | 2009-01-07 18:07:57 -0800 | [diff] [blame] | 94 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP |
| 95 | extern int do_swap_account; |
| 96 | #endif |
Hirokazu Takahashi | f8d6654 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 97 | |
| 98 | static inline bool mem_cgroup_disabled(void) |
| 99 | { |
| 100 | if (mem_cgroup_subsys.disabled) |
| 101 | return true; |
| 102 | return false; |
| 103 | } |
| 104 | |
KAMEZAWA Hiroyuki | a636b32 | 2009-01-07 18:08:08 -0800 | [diff] [blame^] | 105 | extern bool mem_cgroup_oom_called(struct task_struct *task); |
| 106 | |
Balbir Singh | 00f0b82 | 2008-03-04 14:28:39 -0800 | [diff] [blame] | 107 | #else /* CONFIG_CGROUP_MEM_RES_CTLR */ |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 108 | struct mem_cgroup; |
| 109 | |
| 110 | static inline int mem_cgroup_newpage_charge(struct page *page, |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 111 | struct mm_struct *mm, gfp_t gfp_mask) |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 112 | { |
| 113 | return 0; |
| 114 | } |
| 115 | |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 116 | static inline int mem_cgroup_cache_charge(struct page *page, |
| 117 | struct mm_struct *mm, gfp_t gfp_mask) |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 118 | { |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 119 | return 0; |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 120 | } |
| 121 | |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 122 | static inline int mem_cgroup_try_charge(struct mm_struct *mm, |
KAMEZAWA Hiroyuki | 8c7c6e3 | 2009-01-07 18:08:00 -0800 | [diff] [blame] | 123 | gfp_t gfp_mask, struct mem_cgroup **ptr) |
| 124 | { |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm, |
| 129 | struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr) |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 130 | { |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static inline void mem_cgroup_commit_charge_swapin(struct page *page, |
| 135 | struct mem_cgroup *ptr) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr) |
| 140 | { |
| 141 | } |
| 142 | |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 143 | static inline void mem_cgroup_uncharge_page(struct page *page) |
| 144 | { |
| 145 | } |
| 146 | |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 147 | static inline void mem_cgroup_uncharge_cache_page(struct page *page) |
| 148 | { |
| 149 | } |
| 150 | |
KAMEZAWA Hiroyuki | c9b0ed5 | 2008-07-25 01:47:15 -0700 | [diff] [blame] | 151 | static inline int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask) |
| 152 | { |
| 153 | return 0; |
| 154 | } |
| 155 | |
KAMEZAWA Hiroyuki | 08e552c | 2009-01-07 18:08:01 -0800 | [diff] [blame] | 156 | static inline void mem_cgroup_add_lru_list(struct page *page, int lru) |
| 157 | { |
| 158 | } |
| 159 | |
| 160 | static inline void mem_cgroup_del_lru_list(struct page *page, int lru) |
| 161 | { |
| 162 | return ; |
| 163 | } |
| 164 | |
| 165 | static inline void mem_cgroup_rotate_lru_list(struct page *page, int lru) |
| 166 | { |
| 167 | return ; |
| 168 | } |
| 169 | |
| 170 | static inline void mem_cgroup_del_lru(struct page *page) |
| 171 | { |
| 172 | return ; |
| 173 | } |
| 174 | |
| 175 | static inline void |
| 176 | mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to) |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 177 | { |
| 178 | } |
| 179 | |
Hugh Dickins | bd845e3 | 2008-03-04 14:29:01 -0800 | [diff] [blame] | 180 | static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem) |
Balbir Singh | bed7161 | 2008-02-07 00:14:01 -0800 | [diff] [blame] | 181 | { |
David Rientjes | 60c12b1 | 2008-02-09 00:10:15 -0800 | [diff] [blame] | 182 | return 1; |
Balbir Singh | bed7161 | 2008-02-07 00:14:01 -0800 | [diff] [blame] | 183 | } |
| 184 | |
David Rientjes | 4c4a221 | 2008-02-07 00:14:06 -0800 | [diff] [blame] | 185 | static inline int task_in_mem_cgroup(struct task_struct *task, |
| 186 | const struct mem_cgroup *mem) |
| 187 | { |
| 188 | return 1; |
| 189 | } |
| 190 | |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 191 | static inline int |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 192 | mem_cgroup_prepare_migration(struct page *page, struct mem_cgroup **ptr) |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 193 | { |
| 194 | return 0; |
| 195 | } |
| 196 | |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 197 | static inline void mem_cgroup_end_migration(struct mem_cgroup *mem, |
| 198 | struct page *oldpage, |
| 199 | struct page *newpage) |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 200 | { |
| 201 | } |
| 202 | |
KAMEZAWA Hiroyuki | 58ae83d | 2008-02-07 00:14:32 -0800 | [diff] [blame] | 203 | static inline int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem) |
| 204 | { |
| 205 | return 0; |
| 206 | } |
KAMEZAWA Hiroyuki | 5932f36 | 2008-02-07 00:14:33 -0800 | [diff] [blame] | 207 | |
| 208 | static inline int mem_cgroup_reclaim_imbalance(struct mem_cgroup *mem) |
| 209 | { |
| 210 | return 0; |
| 211 | } |
| 212 | |
KAMEZAWA Hiroyuki | 6c48a1d | 2008-02-07 00:14:34 -0800 | [diff] [blame] | 213 | static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem) |
| 214 | { |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem, |
| 219 | int priority) |
| 220 | { |
| 221 | } |
| 222 | |
| 223 | static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem, |
| 224 | int priority) |
| 225 | { |
| 226 | } |
| 227 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 228 | static inline long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, |
| 229 | struct zone *zone, int priority, |
| 230 | enum lru_list lru) |
KAMEZAWA Hiroyuki | cc38108 | 2008-02-07 00:14:35 -0800 | [diff] [blame] | 231 | { |
| 232 | return 0; |
| 233 | } |
Hirokazu Takahashi | f8d6654 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 234 | |
| 235 | static inline bool mem_cgroup_disabled(void) |
| 236 | { |
| 237 | return true; |
| 238 | } |
KAMEZAWA Hiroyuki | a636b32 | 2009-01-07 18:08:08 -0800 | [diff] [blame^] | 239 | |
| 240 | static inline bool mem_cgroup_oom_called(struct task_struct *task) |
| 241 | { |
| 242 | return false; |
| 243 | } |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 244 | #endif /* CONFIG_CGROUP_MEM_CONT */ |
| 245 | |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 246 | #endif /* _LINUX_MEMCONTROL_H */ |
| 247 | |