Use dentry_path() to create full path to inode object
[pohmelfs.git] / include / linux / memcontrol.h
blobb80de520670b64a67dc2ceb8b4e4e11c1d623071
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_CGROUP_MEM_RES_CTLR
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_lru_add_list(struct zone *, struct page *,
67 enum lru_list);
68 void mem_cgroup_lru_del_list(struct page *, enum lru_list);
69 void mem_cgroup_lru_del(struct page *);
70 struct lruvec *mem_cgroup_lru_move_lists(struct zone *, struct page *,
71 enum lru_list, enum lru_list);
73 /* For coalescing uncharge for reducing memcg' overhead*/
74 extern void mem_cgroup_uncharge_start(void);
75 extern void mem_cgroup_uncharge_end(void);
77 extern void mem_cgroup_uncharge_page(struct page *page);
78 extern void mem_cgroup_uncharge_cache_page(struct page *page);
80 extern void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask);
81 int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg);
83 extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
84 extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
85 extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
87 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
88 extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
90 static inline
91 int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
93 struct mem_cgroup *memcg;
94 rcu_read_lock();
95 memcg = mem_cgroup_from_task(rcu_dereference((mm)->owner));
96 rcu_read_unlock();
97 return cgroup == memcg;
100 extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg);
102 extern int
103 mem_cgroup_prepare_migration(struct page *page,
104 struct page *newpage, struct mem_cgroup **memcgp, gfp_t gfp_mask);
105 extern void mem_cgroup_end_migration(struct mem_cgroup *memcg,
106 struct page *oldpage, struct page *newpage, bool migration_ok);
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 *);
114 * For memory reclaim.
116 int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg,
117 struct zone *zone);
118 int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg,
119 struct zone *zone);
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);
129 extern void mem_cgroup_replace_page_cache(struct page *oldpage,
130 struct page *newpage);
132 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
133 extern int do_swap_account;
134 #endif
136 static inline bool mem_cgroup_disabled(void)
138 if (mem_cgroup_subsys.disabled)
139 return true;
140 return false;
143 void mem_cgroup_update_page_stat(struct page *page,
144 enum mem_cgroup_page_stat_item idx,
145 int val);
147 static inline void mem_cgroup_inc_page_stat(struct page *page,
148 enum mem_cgroup_page_stat_item idx)
150 mem_cgroup_update_page_stat(page, idx, 1);
153 static inline void mem_cgroup_dec_page_stat(struct page *page,
154 enum mem_cgroup_page_stat_item idx)
156 mem_cgroup_update_page_stat(page, idx, -1);
159 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
160 gfp_t gfp_mask,
161 unsigned long *total_scanned);
162 u64 mem_cgroup_get_limit(struct mem_cgroup *memcg);
164 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
165 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
166 void mem_cgroup_split_huge_fixup(struct page *head);
167 #endif
169 #ifdef CONFIG_DEBUG_VM
170 bool mem_cgroup_bad_page_check(struct page *page);
171 void mem_cgroup_print_bad_page(struct page *page);
172 #endif
173 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
174 struct mem_cgroup;
176 static inline int mem_cgroup_newpage_charge(struct page *page,
177 struct mm_struct *mm, gfp_t gfp_mask)
179 return 0;
182 static inline int mem_cgroup_cache_charge(struct page *page,
183 struct mm_struct *mm, gfp_t gfp_mask)
185 return 0;
188 static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
189 struct page *page, gfp_t gfp_mask, struct mem_cgroup **memcgp)
191 return 0;
194 static inline void mem_cgroup_commit_charge_swapin(struct page *page,
195 struct mem_cgroup *memcg)
199 static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg)
203 static inline void mem_cgroup_uncharge_start(void)
207 static inline void mem_cgroup_uncharge_end(void)
211 static inline void mem_cgroup_uncharge_page(struct page *page)
215 static inline void mem_cgroup_uncharge_cache_page(struct page *page)
219 static inline struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,
220 struct mem_cgroup *memcg)
222 return &zone->lruvec;
225 static inline struct lruvec *mem_cgroup_lru_add_list(struct zone *zone,
226 struct page *page,
227 enum lru_list lru)
229 return &zone->lruvec;
232 static inline void mem_cgroup_lru_del_list(struct page *page, enum lru_list lru)
236 static inline void mem_cgroup_lru_del(struct page *page)
240 static inline struct lruvec *mem_cgroup_lru_move_lists(struct zone *zone,
241 struct page *page,
242 enum lru_list from,
243 enum lru_list to)
245 return &zone->lruvec;
248 static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
250 return NULL;
253 static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
255 return NULL;
258 static inline int mm_match_cgroup(struct mm_struct *mm,
259 struct mem_cgroup *memcg)
261 return 1;
264 static inline int task_in_mem_cgroup(struct task_struct *task,
265 const struct mem_cgroup *memcg)
267 return 1;
270 static inline struct cgroup_subsys_state
271 *mem_cgroup_css(struct mem_cgroup *memcg)
273 return NULL;
276 static inline int
277 mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
278 struct mem_cgroup **memcgp, gfp_t gfp_mask)
280 return 0;
283 static inline void mem_cgroup_end_migration(struct mem_cgroup *memcg,
284 struct page *oldpage, struct page *newpage, bool migration_ok)
288 static inline struct mem_cgroup *
289 mem_cgroup_iter(struct mem_cgroup *root,
290 struct mem_cgroup *prev,
291 struct mem_cgroup_reclaim_cookie *reclaim)
293 return NULL;
296 static inline void mem_cgroup_iter_break(struct mem_cgroup *root,
297 struct mem_cgroup *prev)
301 static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *memcg)
303 return 0;
306 static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *memcg,
307 int priority)
311 static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *memcg,
312 int priority)
316 static inline bool mem_cgroup_disabled(void)
318 return true;
321 static inline int
322 mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg, struct zone *zone)
324 return 1;
327 static inline int
328 mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg, struct zone *zone)
330 return 1;
333 static inline unsigned long
334 mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,
335 unsigned int lru_mask)
337 return 0;
341 static inline struct zone_reclaim_stat*
342 mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg, struct zone *zone)
344 return NULL;
347 static inline struct zone_reclaim_stat*
348 mem_cgroup_get_reclaim_stat_from_page(struct page *page)
350 return NULL;
353 static inline void
354 mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
358 static inline void mem_cgroup_inc_page_stat(struct page *page,
359 enum mem_cgroup_page_stat_item idx)
363 static inline void mem_cgroup_dec_page_stat(struct page *page,
364 enum mem_cgroup_page_stat_item idx)
368 static inline
369 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
370 gfp_t gfp_mask,
371 unsigned long *total_scanned)
373 return 0;
376 static inline
377 u64 mem_cgroup_get_limit(struct mem_cgroup *memcg)
379 return 0;
382 static inline void mem_cgroup_split_huge_fixup(struct page *head)
386 static inline
387 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
390 static inline void mem_cgroup_replace_page_cache(struct page *oldpage,
391 struct page *newpage)
394 #endif /* CONFIG_CGROUP_MEM_CONT */
396 #if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM)
397 static inline bool
398 mem_cgroup_bad_page_check(struct page *page)
400 return false;
403 static inline void
404 mem_cgroup_print_bad_page(struct page *page)
407 #endif
409 enum {
410 UNDER_LIMIT,
411 SOFT_LIMIT,
412 OVER_LIMIT,
415 struct sock;
416 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
417 void sock_update_memcg(struct sock *sk);
418 void sock_release_memcg(struct sock *sk);
419 #else
420 static inline void sock_update_memcg(struct sock *sk)
423 static inline void sock_release_memcg(struct sock *sk)
426 #endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */
427 #endif /* _LINUX_MEMCONTROL_H */