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>
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 extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
36 struct list_head *dst,
37 unsigned long *scanned, int order,
40 struct mem_cgroup *mem_cont,
41 int active, int file);
43 #ifdef CONFIG_CGROUP_MEM_RES_CTLR
45 * All "charge" functions with gfp_mask should use GFP_KERNEL or
46 * (gfp_mask & GFP_RECLAIM_MASK). In current implementatin, memcg doesn't
47 * alloc memory but reclaims memory from all available zones. So, "where I want
48 * memory from" bits of gfp_mask has no meaning. So any bits of that field is
49 * available but adding a rule is better. charge functions' gfp_mask should
50 * be set to GFP_KERNEL or gfp_mask & GFP_RECLAIM_MASK for avoiding ambiguous
52 * (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.)
55 extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm,
57 /* for swap handling */
58 extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
59 struct page *page, gfp_t mask, struct mem_cgroup **ptr);
60 extern void mem_cgroup_commit_charge_swapin(struct page *page,
61 struct mem_cgroup *ptr);
62 extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr);
64 extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
66 extern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru);
67 extern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru);
68 extern void mem_cgroup_rotate_reclaimable_page(struct page *page);
69 extern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru);
70 extern void mem_cgroup_del_lru(struct page *page);
71 extern void mem_cgroup_move_lists(struct page *page,
72 enum lru_list from, enum lru_list to);
74 /* For coalescing uncharge for reducing memcg' overhead*/
75 extern void mem_cgroup_uncharge_start(void);
76 extern void mem_cgroup_uncharge_end(void);
78 extern void mem_cgroup_uncharge_page(struct page *page);
79 extern void mem_cgroup_uncharge_cache_page(struct page *page);
81 extern void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask);
82 int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg);
84 extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
85 extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
86 extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
88 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
89 extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
92 int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
94 struct mem_cgroup *memcg;
96 memcg = mem_cgroup_from_task(rcu_dereference((mm)->owner));
98 return cgroup == memcg;
101 extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg);
104 mem_cgroup_prepare_migration(struct page *page,
105 struct page *newpage, struct mem_cgroup **ptr, gfp_t gfp_mask);
106 extern void mem_cgroup_end_migration(struct mem_cgroup *memcg,
107 struct page *oldpage, struct page *newpage, bool migration_ok);
110 * For memory reclaim.
112 int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg,
114 int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg,
116 int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
117 unsigned long mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg,
118 int nid, int zid, unsigned int lrumask);
119 struct zone_reclaim_stat *mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg,
121 struct zone_reclaim_stat*
122 mem_cgroup_get_reclaim_stat_from_page(struct page *page);
123 extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
124 struct task_struct *p);
126 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
127 extern int do_swap_account;
130 static inline bool mem_cgroup_disabled(void)
132 if (mem_cgroup_subsys.disabled)
137 void mem_cgroup_update_page_stat(struct page *page,
138 enum mem_cgroup_page_stat_item idx,
141 static inline void mem_cgroup_inc_page_stat(struct page *page,
142 enum mem_cgroup_page_stat_item idx)
144 mem_cgroup_update_page_stat(page, idx, 1);
147 static inline void mem_cgroup_dec_page_stat(struct page *page,
148 enum mem_cgroup_page_stat_item idx)
150 mem_cgroup_update_page_stat(page, idx, -1);
153 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
155 unsigned long *total_scanned);
156 u64 mem_cgroup_get_limit(struct mem_cgroup *memcg);
158 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
159 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
160 void mem_cgroup_split_huge_fixup(struct page *head, struct page *tail);
163 #ifdef CONFIG_DEBUG_VM
164 bool mem_cgroup_bad_page_check(struct page *page);
165 void mem_cgroup_print_bad_page(struct page *page);
167 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
170 static inline int mem_cgroup_newpage_charge(struct page *page,
171 struct mm_struct *mm, gfp_t gfp_mask)
176 static inline int mem_cgroup_cache_charge(struct page *page,
177 struct mm_struct *mm, gfp_t gfp_mask)
182 static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
183 struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr)
188 static inline void mem_cgroup_commit_charge_swapin(struct page *page,
189 struct mem_cgroup *ptr)
193 static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr)
197 static inline void mem_cgroup_uncharge_start(void)
201 static inline void mem_cgroup_uncharge_end(void)
205 static inline void mem_cgroup_uncharge_page(struct page *page)
209 static inline void mem_cgroup_uncharge_cache_page(struct page *page)
213 static inline void mem_cgroup_add_lru_list(struct page *page, int lru)
217 static inline void mem_cgroup_del_lru_list(struct page *page, int lru)
222 static inline void mem_cgroup_rotate_reclaimable_page(struct page *page)
227 static inline void mem_cgroup_rotate_lru_list(struct page *page, int lru)
232 static inline void mem_cgroup_del_lru(struct page *page)
238 mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to)
242 static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
247 static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
252 static inline int mm_match_cgroup(struct mm_struct *mm,
253 struct mem_cgroup *memcg)
258 static inline int task_in_mem_cgroup(struct task_struct *task,
259 const struct mem_cgroup *memcg)
264 static inline struct cgroup_subsys_state
265 *mem_cgroup_css(struct mem_cgroup *memcg)
271 mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
272 struct mem_cgroup **ptr, gfp_t gfp_mask)
277 static inline void mem_cgroup_end_migration(struct mem_cgroup *memcg,
278 struct page *oldpage, struct page *newpage, bool migration_ok)
282 static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *memcg)
287 static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *memcg,
292 static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *memcg,
297 static inline bool mem_cgroup_disabled(void)
303 mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg, struct zone *zone)
309 mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg, struct zone *zone)
314 static inline unsigned long
315 mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,
316 unsigned int lru_mask)
322 static inline struct zone_reclaim_stat*
323 mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg, struct zone *zone)
328 static inline struct zone_reclaim_stat*
329 mem_cgroup_get_reclaim_stat_from_page(struct page *page)
335 mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
339 static inline void mem_cgroup_inc_page_stat(struct page *page,
340 enum mem_cgroup_page_stat_item idx)
344 static inline void mem_cgroup_dec_page_stat(struct page *page,
345 enum mem_cgroup_page_stat_item idx)
350 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
352 unsigned long *total_scanned)
358 u64 mem_cgroup_get_limit(struct mem_cgroup *memcg)
363 static inline void mem_cgroup_split_huge_fixup(struct page *head,
369 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
372 #endif /* CONFIG_CGROUP_MEM_CONT */
374 #if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM)
376 mem_cgroup_bad_page_check(struct page *page)
382 mem_cgroup_print_bad_page(struct page *page)
395 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
396 void sock_update_memcg(struct sock *sk);
397 void sock_release_memcg(struct sock *sk);
399 static inline void sock_update_memcg(struct sock *sk)
402 static inline void sock_release_memcg(struct sock *sk)
405 #endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */
406 #endif /* CONFIG_INET */
407 #endif /* _LINUX_MEMCONTROL_H */