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 | f8d66542 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 22 | #include <linux/cgroup.h> |
Ying Han | 456f998 | 2011-05-26 16:25:38 -0700 | [diff] [blame] | 23 | #include <linux/vm_event_item.h> |
Glauber Costa | 7ae1e1d | 2012-12-18 14:21:56 -0800 | [diff] [blame^] | 24 | #include <linux/hardirq.h> |
Ying Han | 456f998 | 2011-05-26 16:25:38 -0700 | [diff] [blame] | 25 | |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 26 | struct mem_cgroup; |
| 27 | struct page_cgroup; |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 28 | struct page; |
| 29 | struct mm_struct; |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 30 | |
Greg Thelen | 2a7106f | 2011-01-13 15:47:37 -0800 | [diff] [blame] | 31 | /* Stats that can be updated by kernel. */ |
| 32 | enum mem_cgroup_page_stat_item { |
| 33 | MEMCG_NR_FILE_MAPPED, /* # of pages charged as file rss */ |
| 34 | }; |
| 35 | |
Johannes Weiner | 5660048 | 2012-01-12 17:17:59 -0800 | [diff] [blame] | 36 | struct mem_cgroup_reclaim_cookie { |
| 37 | struct zone *zone; |
| 38 | int priority; |
| 39 | unsigned int generation; |
| 40 | }; |
| 41 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_MEMCG |
KAMEZAWA Hiroyuki | 2c26fdd | 2009-01-07 18:08:10 -0800 | [diff] [blame] | 43 | /* |
| 44 | * All "charge" functions with gfp_mask should use GFP_KERNEL or |
| 45 | * (gfp_mask & GFP_RECLAIM_MASK). In current implementatin, memcg doesn't |
| 46 | * alloc memory but reclaims memory from all available zones. So, "where I want |
| 47 | * memory from" bits of gfp_mask has no meaning. So any bits of that field is |
| 48 | * available but adding a rule is better. charge functions' gfp_mask should |
| 49 | * be set to GFP_KERNEL or gfp_mask & GFP_RECLAIM_MASK for avoiding ambiguous |
| 50 | * codes. |
| 51 | * (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.) |
| 52 | */ |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 53 | |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 54 | 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] | 55 | gfp_t gfp_mask); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 56 | /* for swap handling */ |
KAMEZAWA Hiroyuki | 8c7c6e34 | 2009-01-07 18:08:00 -0800 | [diff] [blame] | 57 | extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm, |
Johannes Weiner | 72835c8 | 2012-01-12 17:18:32 -0800 | [diff] [blame] | 58 | struct page *page, gfp_t mask, struct mem_cgroup **memcgp); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 59 | extern void mem_cgroup_commit_charge_swapin(struct page *page, |
Johannes Weiner | 72835c8 | 2012-01-12 17:18:32 -0800 | [diff] [blame] | 60 | struct mem_cgroup *memcg); |
| 61 | extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 62 | |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 63 | extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, |
| 64 | gfp_t gfp_mask); |
Johannes Weiner | 925b767 | 2012-01-12 17:18:15 -0800 | [diff] [blame] | 65 | |
| 66 | struct lruvec *mem_cgroup_zone_lruvec(struct zone *, struct mem_cgroup *); |
Hugh Dickins | fa9add6 | 2012-05-29 15:07:09 -0700 | [diff] [blame] | 67 | struct lruvec *mem_cgroup_page_lruvec(struct page *, struct zone *); |
KAMEZAWA Hiroyuki | 569b846 | 2009-12-15 16:47:03 -0800 | [diff] [blame] | 68 | |
| 69 | /* For coalescing uncharge for reducing memcg' overhead*/ |
| 70 | extern void mem_cgroup_uncharge_start(void); |
| 71 | extern void mem_cgroup_uncharge_end(void); |
| 72 | |
Balbir Singh | 3c541e1 | 2008-02-07 00:14:41 -0800 | [diff] [blame] | 73 | extern void mem_cgroup_uncharge_page(struct page *page); |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 74 | extern void mem_cgroup_uncharge_cache_page(struct page *page); |
KAMEZAWA Hiroyuki | c9b0ed5 | 2008-07-25 01:47:15 -0700 | [diff] [blame] | 75 | |
Johannes Weiner | c3ac9a8 | 2012-05-29 15:06:25 -0700 | [diff] [blame] | 76 | bool __mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg, |
| 77 | struct mem_cgroup *memcg); |
Raghavendra K T | c0ff4b8 | 2011-11-02 13:38:15 -0700 | [diff] [blame] | 78 | int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg); |
David Rientjes | 3062fc6 | 2008-02-07 00:14:03 -0800 | [diff] [blame] | 79 | |
Wu Fengguang | e42d9d5 | 2009-12-16 12:19:59 +0100 | [diff] [blame] | 80 | extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page); |
Balbir Singh | cf475ad | 2008-04-29 01:00:16 -0700 | [diff] [blame] | 81 | extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); |
KOSAKI Motohiro | a433658 | 2011-06-15 15:08:13 -0700 | [diff] [blame] | 82 | extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm); |
Balbir Singh | cf475ad | 2008-04-29 01:00:16 -0700 | [diff] [blame] | 83 | |
Glauber Costa | e1aab16 | 2011-12-11 21:47:03 +0000 | [diff] [blame] | 84 | extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg); |
Glauber Costa | d1a4c0b | 2011-12-11 21:47:04 +0000 | [diff] [blame] | 85 | extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont); |
Glauber Costa | e1aab16 | 2011-12-11 21:47:03 +0000 | [diff] [blame] | 86 | |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 87 | static inline |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 88 | bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg) |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 89 | { |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 90 | struct mem_cgroup *task_memcg; |
| 91 | bool match; |
Johannes Weiner | c3ac9a8 | 2012-05-29 15:06:25 -0700 | [diff] [blame] | 92 | |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 93 | rcu_read_lock(); |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 94 | task_memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); |
| 95 | match = __mem_cgroup_same_or_subtree(memcg, task_memcg); |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 96 | rcu_read_unlock(); |
Johannes Weiner | c3ac9a8 | 2012-05-29 15:06:25 -0700 | [diff] [blame] | 97 | return match; |
Lai Jiangshan | 2e4d409 | 2009-01-07 18:08:07 -0800 | [diff] [blame] | 98 | } |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 99 | |
Raghavendra K T | c0ff4b8 | 2011-11-02 13:38:15 -0700 | [diff] [blame] | 100 | extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg); |
Wu Fengguang | d324236 | 2009-12-16 12:19:59 +0100 | [diff] [blame] | 101 | |
Johannes Weiner | 0030f53 | 2012-07-31 16:45:25 -0700 | [diff] [blame] | 102 | extern void |
| 103 | mem_cgroup_prepare_migration(struct page *page, struct page *newpage, |
| 104 | struct mem_cgroup **memcgp); |
Raghavendra K T | c0ff4b8 | 2011-11-02 13:38:15 -0700 | [diff] [blame] | 105 | extern void mem_cgroup_end_migration(struct mem_cgroup *memcg, |
Daisuke Nishimura | 50de1dd | 2011-01-13 15:47:43 -0800 | [diff] [blame] | 106 | struct page *oldpage, struct page *newpage, bool migration_ok); |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 107 | |
Johannes Weiner | 5660048 | 2012-01-12 17:17:59 -0800 | [diff] [blame] | 108 | struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *, |
| 109 | struct mem_cgroup *, |
| 110 | struct mem_cgroup_reclaim_cookie *); |
| 111 | void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *); |
| 112 | |
KAMEZAWA Hiroyuki | 58ae83d | 2008-02-07 00:14:32 -0800 | [diff] [blame] | 113 | /* |
| 114 | * For memory reclaim. |
| 115 | */ |
Konstantin Khlebnikov | c56d5c7 | 2012-05-29 15:07:00 -0700 | [diff] [blame] | 116 | int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec); |
| 117 | int mem_cgroup_inactive_file_is_low(struct lruvec *lruvec); |
Ying Han | 889976d | 2011-05-26 16:25:33 -0700 | [diff] [blame] | 118 | int mem_cgroup_select_victim_node(struct mem_cgroup *memcg); |
Hugh Dickins | 4d7dcca | 2012-05-29 15:07:08 -0700 | [diff] [blame] | 119 | unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list); |
Hugh Dickins | fa9add6 | 2012-05-29 15:07:09 -0700 | [diff] [blame] | 120 | void mem_cgroup_update_lru_size(struct lruvec *, enum lru_list, int); |
Balbir Singh | e222432 | 2009-04-02 16:57:39 -0700 | [diff] [blame] | 121 | extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, |
| 122 | struct task_struct *p); |
KAMEZAWA Hiroyuki | ab936cb | 2012-01-12 17:17:44 -0800 | [diff] [blame] | 123 | extern void mem_cgroup_replace_page_cache(struct page *oldpage, |
| 124 | struct page *newpage); |
KAMEZAWA Hiroyuki | 58ae83d | 2008-02-07 00:14:32 -0800 | [diff] [blame] | 125 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 126 | #ifdef CONFIG_MEMCG_SWAP |
KAMEZAWA Hiroyuki | c077719 | 2009-01-07 18:07:57 -0800 | [diff] [blame] | 127 | extern int do_swap_account; |
| 128 | #endif |
Hirokazu Takahashi | f8d66542 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 129 | |
| 130 | static inline bool mem_cgroup_disabled(void) |
| 131 | { |
| 132 | if (mem_cgroup_subsys.disabled) |
| 133 | return true; |
| 134 | return false; |
| 135 | } |
| 136 | |
KAMEZAWA Hiroyuki | 89c06bd | 2012-03-21 16:34:25 -0700 | [diff] [blame] | 137 | void __mem_cgroup_begin_update_page_stat(struct page *page, bool *locked, |
| 138 | unsigned long *flags); |
| 139 | |
KAMEZAWA Hiroyuki | 4331f7d | 2012-03-21 16:34:26 -0700 | [diff] [blame] | 140 | extern atomic_t memcg_moving; |
| 141 | |
KAMEZAWA Hiroyuki | 89c06bd | 2012-03-21 16:34:25 -0700 | [diff] [blame] | 142 | static inline void mem_cgroup_begin_update_page_stat(struct page *page, |
| 143 | bool *locked, unsigned long *flags) |
| 144 | { |
| 145 | if (mem_cgroup_disabled()) |
| 146 | return; |
| 147 | rcu_read_lock(); |
| 148 | *locked = false; |
KAMEZAWA Hiroyuki | 4331f7d | 2012-03-21 16:34:26 -0700 | [diff] [blame] | 149 | if (atomic_read(&memcg_moving)) |
| 150 | __mem_cgroup_begin_update_page_stat(page, locked, flags); |
KAMEZAWA Hiroyuki | 89c06bd | 2012-03-21 16:34:25 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | void __mem_cgroup_end_update_page_stat(struct page *page, |
| 154 | unsigned long *flags); |
| 155 | static inline void mem_cgroup_end_update_page_stat(struct page *page, |
| 156 | bool *locked, unsigned long *flags) |
| 157 | { |
| 158 | if (mem_cgroup_disabled()) |
| 159 | return; |
| 160 | if (*locked) |
| 161 | __mem_cgroup_end_update_page_stat(page, flags); |
| 162 | rcu_read_unlock(); |
| 163 | } |
| 164 | |
Greg Thelen | 2a7106f | 2011-01-13 15:47:37 -0800 | [diff] [blame] | 165 | void mem_cgroup_update_page_stat(struct page *page, |
| 166 | enum mem_cgroup_page_stat_item idx, |
| 167 | int val); |
| 168 | |
| 169 | static inline void mem_cgroup_inc_page_stat(struct page *page, |
| 170 | enum mem_cgroup_page_stat_item idx) |
| 171 | { |
| 172 | mem_cgroup_update_page_stat(page, idx, 1); |
| 173 | } |
| 174 | |
| 175 | static inline void mem_cgroup_dec_page_stat(struct page *page, |
| 176 | enum mem_cgroup_page_stat_item idx) |
| 177 | { |
| 178 | mem_cgroup_update_page_stat(page, idx, -1); |
| 179 | } |
| 180 | |
Balbir Singh | 4e41695 | 2009-09-23 15:56:39 -0700 | [diff] [blame] | 181 | unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, |
Ying Han | 0ae5e89 | 2011-05-26 16:25:25 -0700 | [diff] [blame] | 182 | gfp_t gfp_mask, |
| 183 | unsigned long *total_scanned); |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 184 | |
David Rientjes | 68ae564 | 2012-12-12 13:51:57 -0800 | [diff] [blame] | 185 | void __mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx); |
| 186 | static inline void mem_cgroup_count_vm_event(struct mm_struct *mm, |
| 187 | enum vm_event_item idx) |
| 188 | { |
| 189 | if (mem_cgroup_disabled()) |
| 190 | return; |
| 191 | __mem_cgroup_count_vm_event(mm, idx); |
| 192 | } |
KAMEZAWA Hiroyuki | ca3e021 | 2011-01-20 14:44:24 -0800 | [diff] [blame] | 193 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
KAMEZAWA Hiroyuki | e94c8a9 | 2012-01-12 17:18:20 -0800 | [diff] [blame] | 194 | void mem_cgroup_split_huge_fixup(struct page *head); |
KAMEZAWA Hiroyuki | ca3e021 | 2011-01-20 14:44:24 -0800 | [diff] [blame] | 195 | #endif |
| 196 | |
Daisuke Nishimura | f212ad7 | 2011-03-23 16:42:25 -0700 | [diff] [blame] | 197 | #ifdef CONFIG_DEBUG_VM |
| 198 | bool mem_cgroup_bad_page_check(struct page *page); |
| 199 | void mem_cgroup_print_bad_page(struct page *page); |
| 200 | #endif |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 201 | #else /* CONFIG_MEMCG */ |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 202 | struct mem_cgroup; |
| 203 | |
| 204 | static inline int mem_cgroup_newpage_charge(struct page *page, |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 205 | struct mm_struct *mm, gfp_t gfp_mask) |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 206 | { |
| 207 | return 0; |
| 208 | } |
| 209 | |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 210 | static inline int mem_cgroup_cache_charge(struct page *page, |
| 211 | struct mm_struct *mm, gfp_t gfp_mask) |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 212 | { |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 213 | return 0; |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 214 | } |
| 215 | |
KAMEZAWA Hiroyuki | 8c7c6e34 | 2009-01-07 18:08:00 -0800 | [diff] [blame] | 216 | static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm, |
Johannes Weiner | 72835c8 | 2012-01-12 17:18:32 -0800 | [diff] [blame] | 217 | struct page *page, gfp_t gfp_mask, struct mem_cgroup **memcgp) |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 218 | { |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static inline void mem_cgroup_commit_charge_swapin(struct page *page, |
Johannes Weiner | 72835c8 | 2012-01-12 17:18:32 -0800 | [diff] [blame] | 223 | struct mem_cgroup *memcg) |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 224 | { |
| 225 | } |
| 226 | |
Johannes Weiner | 72835c8 | 2012-01-12 17:18:32 -0800 | [diff] [blame] | 227 | static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg) |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 228 | { |
| 229 | } |
| 230 | |
KAMEZAWA Hiroyuki | 569b846 | 2009-12-15 16:47:03 -0800 | [diff] [blame] | 231 | static inline void mem_cgroup_uncharge_start(void) |
| 232 | { |
| 233 | } |
| 234 | |
| 235 | static inline void mem_cgroup_uncharge_end(void) |
| 236 | { |
| 237 | } |
| 238 | |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 239 | static inline void mem_cgroup_uncharge_page(struct page *page) |
| 240 | { |
| 241 | } |
| 242 | |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 243 | static inline void mem_cgroup_uncharge_cache_page(struct page *page) |
| 244 | { |
| 245 | } |
| 246 | |
Johannes Weiner | 925b767 | 2012-01-12 17:18:15 -0800 | [diff] [blame] | 247 | static inline struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone, |
| 248 | struct mem_cgroup *memcg) |
| 249 | { |
| 250 | return &zone->lruvec; |
| 251 | } |
| 252 | |
Hugh Dickins | fa9add6 | 2012-05-29 15:07:09 -0700 | [diff] [blame] | 253 | static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page, |
| 254 | struct zone *zone) |
Minchan Kim | 3f58a82 | 2011-03-22 16:32:53 -0700 | [diff] [blame] | 255 | { |
Johannes Weiner | 925b767 | 2012-01-12 17:18:15 -0800 | [diff] [blame] | 256 | return &zone->lruvec; |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Wu Fengguang | e42d9d5 | 2009-12-16 12:19:59 +0100 | [diff] [blame] | 259 | static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) |
| 260 | { |
| 261 | return NULL; |
| 262 | } |
| 263 | |
KOSAKI Motohiro | a433658 | 2011-06-15 15:08:13 -0700 | [diff] [blame] | 264 | static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm) |
| 265 | { |
| 266 | return NULL; |
| 267 | } |
| 268 | |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 269 | static inline bool mm_match_cgroup(struct mm_struct *mm, |
Raghavendra K T | c0ff4b8 | 2011-11-02 13:38:15 -0700 | [diff] [blame] | 270 | struct mem_cgroup *memcg) |
Balbir Singh | bed7161 | 2008-02-07 00:14:01 -0800 | [diff] [blame] | 271 | { |
Johannes Weiner | 587af30 | 2012-10-08 16:34:12 -0700 | [diff] [blame] | 272 | return true; |
Balbir Singh | bed7161 | 2008-02-07 00:14:01 -0800 | [diff] [blame] | 273 | } |
| 274 | |
David Rientjes | 4c4a221 | 2008-02-07 00:14:06 -0800 | [diff] [blame] | 275 | static inline int task_in_mem_cgroup(struct task_struct *task, |
Raghavendra K T | c0ff4b8 | 2011-11-02 13:38:15 -0700 | [diff] [blame] | 276 | const struct mem_cgroup *memcg) |
David Rientjes | 4c4a221 | 2008-02-07 00:14:06 -0800 | [diff] [blame] | 277 | { |
| 278 | return 1; |
| 279 | } |
| 280 | |
Raghavendra K T | c0ff4b8 | 2011-11-02 13:38:15 -0700 | [diff] [blame] | 281 | static inline struct cgroup_subsys_state |
| 282 | *mem_cgroup_css(struct mem_cgroup *memcg) |
Wu Fengguang | d324236 | 2009-12-16 12:19:59 +0100 | [diff] [blame] | 283 | { |
| 284 | return NULL; |
| 285 | } |
| 286 | |
Johannes Weiner | 0030f53 | 2012-07-31 16:45:25 -0700 | [diff] [blame] | 287 | static inline void |
akpm@linux-foundation.org | ac39cf8 | 2010-05-26 14:42:46 -0700 | [diff] [blame] | 288 | mem_cgroup_prepare_migration(struct page *page, struct page *newpage, |
Johannes Weiner | 0030f53 | 2012-07-31 16:45:25 -0700 | [diff] [blame] | 289 | struct mem_cgroup **memcgp) |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 290 | { |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Raghavendra K T | c0ff4b8 | 2011-11-02 13:38:15 -0700 | [diff] [blame] | 293 | static inline void mem_cgroup_end_migration(struct mem_cgroup *memcg, |
Daisuke Nishimura | 50de1dd | 2011-01-13 15:47:43 -0800 | [diff] [blame] | 294 | struct page *oldpage, struct page *newpage, bool migration_ok) |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 295 | { |
| 296 | } |
| 297 | |
Johannes Weiner | 5660048 | 2012-01-12 17:17:59 -0800 | [diff] [blame] | 298 | static inline struct mem_cgroup * |
| 299 | mem_cgroup_iter(struct mem_cgroup *root, |
| 300 | struct mem_cgroup *prev, |
| 301 | struct mem_cgroup_reclaim_cookie *reclaim) |
| 302 | { |
| 303 | return NULL; |
| 304 | } |
| 305 | |
| 306 | static inline void mem_cgroup_iter_break(struct mem_cgroup *root, |
| 307 | struct mem_cgroup *prev) |
| 308 | { |
| 309 | } |
| 310 | |
Hirokazu Takahashi | f8d66542 | 2009-01-07 18:08:02 -0800 | [diff] [blame] | 311 | static inline bool mem_cgroup_disabled(void) |
| 312 | { |
| 313 | return true; |
| 314 | } |
KAMEZAWA Hiroyuki | a636b32 | 2009-01-07 18:08:08 -0800 | [diff] [blame] | 315 | |
KOSAKI Motohiro | 14797e2 | 2009-01-07 18:08:18 -0800 | [diff] [blame] | 316 | static inline int |
Konstantin Khlebnikov | c56d5c7 | 2012-05-29 15:07:00 -0700 | [diff] [blame] | 317 | mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec) |
KOSAKI Motohiro | 14797e2 | 2009-01-07 18:08:18 -0800 | [diff] [blame] | 318 | { |
| 319 | return 1; |
| 320 | } |
| 321 | |
Rik van Riel | 56e49d2 | 2009-06-16 15:32:28 -0700 | [diff] [blame] | 322 | static inline int |
Konstantin Khlebnikov | c56d5c7 | 2012-05-29 15:07:00 -0700 | [diff] [blame] | 323 | mem_cgroup_inactive_file_is_low(struct lruvec *lruvec) |
Rik van Riel | 56e49d2 | 2009-06-16 15:32:28 -0700 | [diff] [blame] | 324 | { |
| 325 | return 1; |
| 326 | } |
| 327 | |
KOSAKI Motohiro | a3d8e05 | 2009-01-07 18:08:19 -0800 | [diff] [blame] | 328 | static inline unsigned long |
Hugh Dickins | 4d7dcca | 2012-05-29 15:07:08 -0700 | [diff] [blame] | 329 | mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list lru) |
KOSAKI Motohiro | a3d8e05 | 2009-01-07 18:08:19 -0800 | [diff] [blame] | 330 | { |
| 331 | return 0; |
| 332 | } |
| 333 | |
Hugh Dickins | fa9add6 | 2012-05-29 15:07:09 -0700 | [diff] [blame] | 334 | static inline void |
| 335 | mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru, |
| 336 | int increment) |
KOSAKI Motohiro | 3e2f41f | 2009-01-07 18:08:20 -0800 | [diff] [blame] | 337 | { |
KOSAKI Motohiro | 3e2f41f | 2009-01-07 18:08:20 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Balbir Singh | e222432 | 2009-04-02 16:57:39 -0700 | [diff] [blame] | 340 | static inline void |
| 341 | mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p) |
| 342 | { |
| 343 | } |
| 344 | |
KAMEZAWA Hiroyuki | 89c06bd | 2012-03-21 16:34:25 -0700 | [diff] [blame] | 345 | static inline void mem_cgroup_begin_update_page_stat(struct page *page, |
| 346 | bool *locked, unsigned long *flags) |
| 347 | { |
| 348 | } |
| 349 | |
| 350 | static inline void mem_cgroup_end_update_page_stat(struct page *page, |
| 351 | bool *locked, unsigned long *flags) |
| 352 | { |
| 353 | } |
| 354 | |
Greg Thelen | 2a7106f | 2011-01-13 15:47:37 -0800 | [diff] [blame] | 355 | static inline void mem_cgroup_inc_page_stat(struct page *page, |
| 356 | enum mem_cgroup_page_stat_item idx) |
| 357 | { |
| 358 | } |
| 359 | |
| 360 | static inline void mem_cgroup_dec_page_stat(struct page *page, |
| 361 | enum mem_cgroup_page_stat_item idx) |
Balbir Singh | d69b042 | 2009-06-17 16:26:34 -0700 | [diff] [blame] | 362 | { |
| 363 | } |
| 364 | |
Balbir Singh | 4e41695 | 2009-09-23 15:56:39 -0700 | [diff] [blame] | 365 | static inline |
| 366 | unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, |
Ying Han | 0ae5e89 | 2011-05-26 16:25:25 -0700 | [diff] [blame] | 367 | gfp_t gfp_mask, |
| 368 | unsigned long *total_scanned) |
Balbir Singh | 4e41695 | 2009-09-23 15:56:39 -0700 | [diff] [blame] | 369 | { |
| 370 | return 0; |
| 371 | } |
| 372 | |
KAMEZAWA Hiroyuki | e94c8a9 | 2012-01-12 17:18:20 -0800 | [diff] [blame] | 373 | static inline void mem_cgroup_split_huge_fixup(struct page *head) |
KAMEZAWA Hiroyuki | ca3e021 | 2011-01-20 14:44:24 -0800 | [diff] [blame] | 374 | { |
| 375 | } |
| 376 | |
Ying Han | 456f998 | 2011-05-26 16:25:38 -0700 | [diff] [blame] | 377 | static inline |
| 378 | void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx) |
| 379 | { |
| 380 | } |
KAMEZAWA Hiroyuki | ab936cb | 2012-01-12 17:17:44 -0800 | [diff] [blame] | 381 | static inline void mem_cgroup_replace_page_cache(struct page *oldpage, |
| 382 | struct page *newpage) |
| 383 | { |
| 384 | } |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 385 | #endif /* CONFIG_MEMCG */ |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 386 | |
Andrew Morton | c255a45 | 2012-07-31 16:43:02 -0700 | [diff] [blame] | 387 | #if !defined(CONFIG_MEMCG) || !defined(CONFIG_DEBUG_VM) |
Daisuke Nishimura | f212ad7 | 2011-03-23 16:42:25 -0700 | [diff] [blame] | 388 | static inline bool |
| 389 | mem_cgroup_bad_page_check(struct page *page) |
| 390 | { |
| 391 | return false; |
| 392 | } |
| 393 | |
| 394 | static inline void |
| 395 | mem_cgroup_print_bad_page(struct page *page) |
| 396 | { |
| 397 | } |
| 398 | #endif |
| 399 | |
Glauber Costa | e1aab16 | 2011-12-11 21:47:03 +0000 | [diff] [blame] | 400 | enum { |
| 401 | UNDER_LIMIT, |
| 402 | SOFT_LIMIT, |
| 403 | OVER_LIMIT, |
| 404 | }; |
| 405 | |
| 406 | struct sock; |
David Rientjes | cd59085 | 2012-10-10 15:54:08 -0700 | [diff] [blame] | 407 | #if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM) |
Glauber Costa | e1aab16 | 2011-12-11 21:47:03 +0000 | [diff] [blame] | 408 | void sock_update_memcg(struct sock *sk); |
| 409 | void sock_release_memcg(struct sock *sk); |
| 410 | #else |
| 411 | static inline void sock_update_memcg(struct sock *sk) |
| 412 | { |
| 413 | } |
| 414 | static inline void sock_release_memcg(struct sock *sk) |
| 415 | { |
| 416 | } |
David Rientjes | cd59085 | 2012-10-10 15:54:08 -0700 | [diff] [blame] | 417 | #endif /* CONFIG_INET && CONFIG_MEMCG_KMEM */ |
Glauber Costa | 7ae1e1d | 2012-12-18 14:21:56 -0800 | [diff] [blame^] | 418 | |
| 419 | #ifdef CONFIG_MEMCG_KMEM |
| 420 | static inline bool memcg_kmem_enabled(void) |
| 421 | { |
| 422 | return true; |
| 423 | } |
| 424 | |
| 425 | /* |
| 426 | * In general, we'll do everything in our power to not incur in any overhead |
| 427 | * for non-memcg users for the kmem functions. Not even a function call, if we |
| 428 | * can avoid it. |
| 429 | * |
| 430 | * Therefore, we'll inline all those functions so that in the best case, we'll |
| 431 | * see that kmemcg is off for everybody and proceed quickly. If it is on, |
| 432 | * we'll still do most of the flag checking inline. We check a lot of |
| 433 | * conditions, but because they are pretty simple, they are expected to be |
| 434 | * fast. |
| 435 | */ |
| 436 | bool __memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg, |
| 437 | int order); |
| 438 | void __memcg_kmem_commit_charge(struct page *page, |
| 439 | struct mem_cgroup *memcg, int order); |
| 440 | void __memcg_kmem_uncharge_pages(struct page *page, int order); |
| 441 | |
| 442 | /** |
| 443 | * memcg_kmem_newpage_charge: verify if a new kmem allocation is allowed. |
| 444 | * @gfp: the gfp allocation flags. |
| 445 | * @memcg: a pointer to the memcg this was charged against. |
| 446 | * @order: allocation order. |
| 447 | * |
| 448 | * returns true if the memcg where the current task belongs can hold this |
| 449 | * allocation. |
| 450 | * |
| 451 | * We return true automatically if this allocation is not to be accounted to |
| 452 | * any memcg. |
| 453 | */ |
| 454 | static inline bool |
| 455 | memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg, int order) |
| 456 | { |
| 457 | if (!memcg_kmem_enabled()) |
| 458 | return true; |
| 459 | |
| 460 | /* |
| 461 | * __GFP_NOFAIL allocations will move on even if charging is not |
| 462 | * possible. Therefore we don't even try, and have this allocation |
| 463 | * unaccounted. We could in theory charge it with |
| 464 | * res_counter_charge_nofail, but we hope those allocations are rare, |
| 465 | * and won't be worth the trouble. |
| 466 | */ |
| 467 | if (!(gfp & __GFP_KMEMCG) || (gfp & __GFP_NOFAIL)) |
| 468 | return true; |
| 469 | if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD)) |
| 470 | return true; |
| 471 | |
| 472 | /* If the test is dying, just let it go. */ |
| 473 | if (unlikely(fatal_signal_pending(current))) |
| 474 | return true; |
| 475 | |
| 476 | return __memcg_kmem_newpage_charge(gfp, memcg, order); |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * memcg_kmem_uncharge_pages: uncharge pages from memcg |
| 481 | * @page: pointer to struct page being freed |
| 482 | * @order: allocation order. |
| 483 | * |
| 484 | * there is no need to specify memcg here, since it is embedded in page_cgroup |
| 485 | */ |
| 486 | static inline void |
| 487 | memcg_kmem_uncharge_pages(struct page *page, int order) |
| 488 | { |
| 489 | if (memcg_kmem_enabled()) |
| 490 | __memcg_kmem_uncharge_pages(page, order); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * memcg_kmem_commit_charge: embeds correct memcg in a page |
| 495 | * @page: pointer to struct page recently allocated |
| 496 | * @memcg: the memcg structure we charged against |
| 497 | * @order: allocation order. |
| 498 | * |
| 499 | * Needs to be called after memcg_kmem_newpage_charge, regardless of success or |
| 500 | * failure of the allocation. if @page is NULL, this function will revert the |
| 501 | * charges. Otherwise, it will commit the memcg given by @memcg to the |
| 502 | * corresponding page_cgroup. |
| 503 | */ |
| 504 | static inline void |
| 505 | memcg_kmem_commit_charge(struct page *page, struct mem_cgroup *memcg, int order) |
| 506 | { |
| 507 | if (memcg_kmem_enabled() && memcg) |
| 508 | __memcg_kmem_commit_charge(page, memcg, order); |
| 509 | } |
| 510 | |
| 511 | #else |
| 512 | static inline bool |
| 513 | memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg, int order) |
| 514 | { |
| 515 | return true; |
| 516 | } |
| 517 | |
| 518 | static inline void memcg_kmem_uncharge_pages(struct page *page, int order) |
| 519 | { |
| 520 | } |
| 521 | |
| 522 | static inline void |
| 523 | memcg_kmem_commit_charge(struct page *page, struct mem_cgroup *memcg, int order) |
| 524 | { |
| 525 | } |
| 526 | #endif /* CONFIG_MEMCG_KMEM */ |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 527 | #endif /* _LINUX_MEMCONTROL_H */ |
| 528 | |