cgroup, cpuset: remove cgroup_subsys->post_clone()
[linux-2.6/libata-dev.git] / include / linux / memcontrol.h
blob11ddc7ffeba88972f21937a8b45d65191d40fc35
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 struct mem_cgroup_reclaim_cookie {
36 struct zone *zone;
37 int priority;
38 unsigned int generation;
41 #ifdef CONFIG_MEMCG
43 * All "charge" functions with gfp_mask should use GFP_KERNEL or
44 * (gfp_mask & GFP_RECLAIM_MASK). In current implementatin, memcg doesn't
45 * alloc memory but reclaims memory from all available zones. So, "where I want
46 * memory from" bits of gfp_mask has no meaning. So any bits of that field is
47 * available but adding a rule is better. charge functions' gfp_mask should
48 * be set to GFP_KERNEL or gfp_mask & GFP_RECLAIM_MASK for avoiding ambiguous
49 * codes.
50 * (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.)
53 extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm,
54 gfp_t gfp_mask);
55 /* for swap handling */
56 extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
57 struct page *page, gfp_t mask, struct mem_cgroup **memcgp);
58 extern void mem_cgroup_commit_charge_swapin(struct page *page,
59 struct mem_cgroup *memcg);
60 extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg);
62 extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
63 gfp_t gfp_mask);
65 struct lruvec *mem_cgroup_zone_lruvec(struct zone *, struct mem_cgroup *);
66 struct lruvec *mem_cgroup_page_lruvec(struct page *, struct zone *);
68 /* For coalescing uncharge for reducing memcg' overhead*/
69 extern void mem_cgroup_uncharge_start(void);
70 extern void mem_cgroup_uncharge_end(void);
72 extern void mem_cgroup_uncharge_page(struct page *page);
73 extern void mem_cgroup_uncharge_cache_page(struct page *page);
75 bool __mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg,
76 struct mem_cgroup *memcg);
77 int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg);
79 extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
80 extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
81 extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
83 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
84 extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
86 static inline
87 bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
89 struct mem_cgroup *task_memcg;
90 bool match;
92 rcu_read_lock();
93 task_memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
94 match = __mem_cgroup_same_or_subtree(memcg, task_memcg);
95 rcu_read_unlock();
96 return match;
99 extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg);
101 extern void
102 mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
103 struct mem_cgroup **memcgp);
104 extern void mem_cgroup_end_migration(struct mem_cgroup *memcg,
105 struct page *oldpage, struct page *newpage, bool migration_ok);
107 struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *,
108 struct mem_cgroup *,
109 struct mem_cgroup_reclaim_cookie *);
110 void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);
113 * For memory reclaim.
115 int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec);
116 int mem_cgroup_inactive_file_is_low(struct lruvec *lruvec);
117 int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
118 unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list);
119 void mem_cgroup_update_lru_size(struct lruvec *, enum lru_list, int);
120 extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
121 struct task_struct *p);
122 extern void mem_cgroup_replace_page_cache(struct page *oldpage,
123 struct page *newpage);
125 #ifdef CONFIG_MEMCG_SWAP
126 extern int do_swap_account;
127 #endif
129 static inline bool mem_cgroup_disabled(void)
131 if (mem_cgroup_subsys.disabled)
132 return true;
133 return false;
136 void __mem_cgroup_begin_update_page_stat(struct page *page, bool *locked,
137 unsigned long *flags);
139 extern atomic_t memcg_moving;
141 static inline void mem_cgroup_begin_update_page_stat(struct page *page,
142 bool *locked, unsigned long *flags)
144 if (mem_cgroup_disabled())
145 return;
146 rcu_read_lock();
147 *locked = false;
148 if (atomic_read(&memcg_moving))
149 __mem_cgroup_begin_update_page_stat(page, locked, flags);
152 void __mem_cgroup_end_update_page_stat(struct page *page,
153 unsigned long *flags);
154 static inline void mem_cgroup_end_update_page_stat(struct page *page,
155 bool *locked, unsigned long *flags)
157 if (mem_cgroup_disabled())
158 return;
159 if (*locked)
160 __mem_cgroup_end_update_page_stat(page, flags);
161 rcu_read_unlock();
164 void mem_cgroup_update_page_stat(struct page *page,
165 enum mem_cgroup_page_stat_item idx,
166 int val);
168 static inline void mem_cgroup_inc_page_stat(struct page *page,
169 enum mem_cgroup_page_stat_item idx)
171 mem_cgroup_update_page_stat(page, idx, 1);
174 static inline void mem_cgroup_dec_page_stat(struct page *page,
175 enum mem_cgroup_page_stat_item idx)
177 mem_cgroup_update_page_stat(page, idx, -1);
180 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
181 gfp_t gfp_mask,
182 unsigned long *total_scanned);
184 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
185 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
186 void mem_cgroup_split_huge_fixup(struct page *head);
187 #endif
189 #ifdef CONFIG_DEBUG_VM
190 bool mem_cgroup_bad_page_check(struct page *page);
191 void mem_cgroup_print_bad_page(struct page *page);
192 #endif
193 #else /* CONFIG_MEMCG */
194 struct mem_cgroup;
196 static inline int mem_cgroup_newpage_charge(struct page *page,
197 struct mm_struct *mm, gfp_t gfp_mask)
199 return 0;
202 static inline int mem_cgroup_cache_charge(struct page *page,
203 struct mm_struct *mm, gfp_t gfp_mask)
205 return 0;
208 static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
209 struct page *page, gfp_t gfp_mask, struct mem_cgroup **memcgp)
211 return 0;
214 static inline void mem_cgroup_commit_charge_swapin(struct page *page,
215 struct mem_cgroup *memcg)
219 static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg)
223 static inline void mem_cgroup_uncharge_start(void)
227 static inline void mem_cgroup_uncharge_end(void)
231 static inline void mem_cgroup_uncharge_page(struct page *page)
235 static inline void mem_cgroup_uncharge_cache_page(struct page *page)
239 static inline struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,
240 struct mem_cgroup *memcg)
242 return &zone->lruvec;
245 static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,
246 struct zone *zone)
248 return &zone->lruvec;
251 static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
253 return NULL;
256 static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
258 return NULL;
261 static inline bool mm_match_cgroup(struct mm_struct *mm,
262 struct mem_cgroup *memcg)
264 return true;
267 static inline int task_in_mem_cgroup(struct task_struct *task,
268 const struct mem_cgroup *memcg)
270 return 1;
273 static inline struct cgroup_subsys_state
274 *mem_cgroup_css(struct mem_cgroup *memcg)
276 return NULL;
279 static inline void
280 mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
281 struct mem_cgroup **memcgp)
285 static inline void mem_cgroup_end_migration(struct mem_cgroup *memcg,
286 struct page *oldpage, struct page *newpage, bool migration_ok)
290 static inline struct mem_cgroup *
291 mem_cgroup_iter(struct mem_cgroup *root,
292 struct mem_cgroup *prev,
293 struct mem_cgroup_reclaim_cookie *reclaim)
295 return NULL;
298 static inline void mem_cgroup_iter_break(struct mem_cgroup *root,
299 struct mem_cgroup *prev)
303 static inline bool mem_cgroup_disabled(void)
305 return true;
308 static inline int
309 mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)
311 return 1;
314 static inline int
315 mem_cgroup_inactive_file_is_low(struct lruvec *lruvec)
317 return 1;
320 static inline unsigned long
321 mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list lru)
323 return 0;
326 static inline void
327 mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
328 int increment)
332 static inline void
333 mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
337 static inline void mem_cgroup_begin_update_page_stat(struct page *page,
338 bool *locked, unsigned long *flags)
342 static inline void mem_cgroup_end_update_page_stat(struct page *page,
343 bool *locked, unsigned long *flags)
347 static inline void mem_cgroup_inc_page_stat(struct page *page,
348 enum mem_cgroup_page_stat_item idx)
352 static inline void mem_cgroup_dec_page_stat(struct page *page,
353 enum mem_cgroup_page_stat_item idx)
357 static inline
358 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
359 gfp_t gfp_mask,
360 unsigned long *total_scanned)
362 return 0;
365 static inline void mem_cgroup_split_huge_fixup(struct page *head)
369 static inline
370 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
373 static inline void mem_cgroup_replace_page_cache(struct page *oldpage,
374 struct page *newpage)
377 #endif /* CONFIG_MEMCG */
379 #if !defined(CONFIG_MEMCG) || !defined(CONFIG_DEBUG_VM)
380 static inline bool
381 mem_cgroup_bad_page_check(struct page *page)
383 return false;
386 static inline void
387 mem_cgroup_print_bad_page(struct page *page)
390 #endif
392 enum {
393 UNDER_LIMIT,
394 SOFT_LIMIT,
395 OVER_LIMIT,
398 struct sock;
399 #if defined(CONFIG_INET) && defined(CONFIG_MEMCG_KMEM)
400 void sock_update_memcg(struct sock *sk);
401 void sock_release_memcg(struct sock *sk);
402 #else
403 static inline void sock_update_memcg(struct sock *sk)
406 static inline void sock_release_memcg(struct sock *sk)
409 #endif /* CONFIG_INET && CONFIG_MEMCG_KMEM */
410 #endif /* _LINUX_MEMCONTROL_H */