blob: 2fdd1380bf0ae48ee3e66b918a9f41c1667269e1 [file] [log] [blame]
Balbir Singh8cdea7c2008-02-07 00:13:50 -08001/* memcontrol.h - Memory Controller
2 *
3 * Copyright IBM Corporation, 2007
4 * Author Balbir Singh <balbir@linux.vnet.ibm.com>
5 *
Pavel Emelianov78fb7462008-02-07 00:13:51 -08006 * Copyright 2007 OpenVZ SWsoft Inc
7 * Author: Pavel Emelianov <xemul@openvz.org>
8 *
Balbir Singh8cdea7c2008-02-07 00:13:50 -08009 * 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 Takahashif8d66542009-01-07 18:08:02 -080022#include <linux/cgroup.h>
Pavel Emelianov78fb7462008-02-07 00:13:51 -080023struct mem_cgroup;
24struct page_cgroup;
Balbir Singh8697d332008-02-07 00:13:59 -080025struct page;
26struct mm_struct;
Pavel Emelianov78fb7462008-02-07 00:13:51 -080027
Balbir Singh00f0b822008-03-04 14:28:39 -080028#ifdef CONFIG_CGROUP_MEM_RES_CTLR
Pavel Emelianov78fb7462008-02-07 00:13:51 -080029
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -080030extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm,
Balbir Singhe1a1cd52008-02-07 00:14:02 -080031 gfp_t gfp_mask);
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -080032/* for swap handling */
33extern int mem_cgroup_try_charge(struct mm_struct *mm,
34 gfp_t gfp_mask, struct mem_cgroup **ptr);
KAMEZAWA Hiroyuki8c7c6e32009-01-07 18:08:00 -080035extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
36 struct page *page, gfp_t mask, struct mem_cgroup **ptr);
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -080037extern void mem_cgroup_commit_charge_swapin(struct page *page,
38 struct mem_cgroup *ptr);
39extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr);
40
Hugh Dickins82895462008-03-04 14:29:08 -080041extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
42 gfp_t gfp_mask);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080043extern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru);
44extern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru);
45extern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru);
46extern void mem_cgroup_del_lru(struct page *page);
47extern void mem_cgroup_move_lists(struct page *page,
48 enum lru_list from, enum lru_list to);
Balbir Singh3c541e12008-02-07 00:14:41 -080049extern void mem_cgroup_uncharge_page(struct page *page);
KAMEZAWA Hiroyuki69029cd2008-07-25 01:47:14 -070050extern void mem_cgroup_uncharge_cache_page(struct page *page);
KAMEZAWA Hiroyukic9b0ed52008-07-25 01:47:15 -070051extern int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask);
52
Balbir Singh66e17072008-02-07 00:13:56 -080053extern 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 Riel4f98a2f2008-10-18 20:26:32 -070058 int active, int file);
Pavel Emelianovc7ba5c92008-02-07 00:13:58 -080059extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask);
David Rientjes4c4a2212008-02-07 00:14:06 -080060int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);
David Rientjes3062fc62008-02-07 00:14:03 -080061
Balbir Singhcf475ad2008-04-29 01:00:16 -070062extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
63
Lai Jiangshan2e4d4092009-01-07 18:08:07 -080064static inline
65int 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 Singh8a9f3cc2008-02-07 00:13:53 -080073
KAMEZAWA Hiroyukie8589cc2008-07-25 01:47:10 -070074extern int
KAMEZAWA Hiroyuki01b1ae62009-01-07 18:07:50 -080075mem_cgroup_prepare_migration(struct page *page, struct mem_cgroup **ptr);
76extern void mem_cgroup_end_migration(struct mem_cgroup *mem,
77 struct page *oldpage, struct page *newpage);
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -080078
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -080079/*
80 * For memory reclaim.
81 */
82extern int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem);
KAMEZAWA Hiroyuki5932f362008-02-07 00:14:33 -080083extern long mem_cgroup_reclaim_imbalance(struct mem_cgroup *mem);
84
KAMEZAWA Hiroyuki6c48a1d2008-02-07 00:14:34 -080085extern int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem);
86extern void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem,
87 int priority);
88extern void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
89 int priority);
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -080090
Christoph Lameterb69408e2008-10-18 20:26:14 -070091extern long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone,
92 int priority, enum lru_list lru);
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -080093
KAMEZAWA Hiroyukic0777192009-01-07 18:07:57 -080094#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
95extern int do_swap_account;
96#endif
Hirokazu Takahashif8d66542009-01-07 18:08:02 -080097
98static inline bool mem_cgroup_disabled(void)
99{
100 if (mem_cgroup_subsys.disabled)
101 return true;
102 return false;
103}
104
KAMEZAWA Hiroyukia636b322009-01-07 18:08:08 -0800105extern bool mem_cgroup_oom_called(struct task_struct *task);
106
Balbir Singh00f0b822008-03-04 14:28:39 -0800107#else /* CONFIG_CGROUP_MEM_RES_CTLR */
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800108struct mem_cgroup;
109
110static inline int mem_cgroup_newpage_charge(struct page *page,
Hugh Dickins82895462008-03-04 14:29:08 -0800111 struct mm_struct *mm, gfp_t gfp_mask)
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800112{
113 return 0;
114}
115
Hugh Dickins82895462008-03-04 14:29:08 -0800116static inline int mem_cgroup_cache_charge(struct page *page,
117 struct mm_struct *mm, gfp_t gfp_mask)
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800118{
Hugh Dickins82895462008-03-04 14:29:08 -0800119 return 0;
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800120}
121
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800122static inline int mem_cgroup_try_charge(struct mm_struct *mm,
KAMEZAWA Hiroyuki8c7c6e32009-01-07 18:08:00 -0800123 gfp_t gfp_mask, struct mem_cgroup **ptr)
124{
125 return 0;
126}
127
128static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
129 struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr)
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800130{
131 return 0;
132}
133
134static inline void mem_cgroup_commit_charge_swapin(struct page *page,
135 struct mem_cgroup *ptr)
136{
137}
138
139static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr)
140{
141}
142
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800143static inline void mem_cgroup_uncharge_page(struct page *page)
144{
145}
146
KAMEZAWA Hiroyuki69029cd2008-07-25 01:47:14 -0700147static inline void mem_cgroup_uncharge_cache_page(struct page *page)
148{
149}
150
KAMEZAWA Hiroyukic9b0ed52008-07-25 01:47:15 -0700151static inline int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask)
152{
153 return 0;
154}
155
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -0800156static inline void mem_cgroup_add_lru_list(struct page *page, int lru)
157{
158}
159
160static inline void mem_cgroup_del_lru_list(struct page *page, int lru)
161{
162 return ;
163}
164
165static inline void mem_cgroup_rotate_lru_list(struct page *page, int lru)
166{
167 return ;
168}
169
170static inline void mem_cgroup_del_lru(struct page *page)
171{
172 return ;
173}
174
175static inline void
176mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to)
Balbir Singh66e17072008-02-07 00:13:56 -0800177{
178}
179
Hugh Dickinsbd845e32008-03-04 14:29:01 -0800180static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem)
Balbir Singhbed71612008-02-07 00:14:01 -0800181{
David Rientjes60c12b12008-02-09 00:10:15 -0800182 return 1;
Balbir Singhbed71612008-02-07 00:14:01 -0800183}
184
David Rientjes4c4a2212008-02-07 00:14:06 -0800185static inline int task_in_mem_cgroup(struct task_struct *task,
186 const struct mem_cgroup *mem)
187{
188 return 1;
189}
190
KAMEZAWA Hiroyukie8589cc2008-07-25 01:47:10 -0700191static inline int
KAMEZAWA Hiroyuki01b1ae62009-01-07 18:07:50 -0800192mem_cgroup_prepare_migration(struct page *page, struct mem_cgroup **ptr)
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -0800193{
194 return 0;
195}
196
KAMEZAWA Hiroyuki01b1ae62009-01-07 18:07:50 -0800197static inline void mem_cgroup_end_migration(struct mem_cgroup *mem,
198 struct page *oldpage,
199 struct page *newpage)
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -0800200{
201}
202
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -0800203static inline int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem)
204{
205 return 0;
206}
KAMEZAWA Hiroyuki5932f362008-02-07 00:14:33 -0800207
208static inline int mem_cgroup_reclaim_imbalance(struct mem_cgroup *mem)
209{
210 return 0;
211}
212
KAMEZAWA Hiroyuki6c48a1d2008-02-07 00:14:34 -0800213static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem)
214{
215 return 0;
216}
217
218static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem,
219 int priority)
220{
221}
222
223static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
224 int priority)
225{
226}
227
Christoph Lameterb69408e2008-10-18 20:26:14 -0700228static inline long mem_cgroup_calc_reclaim(struct mem_cgroup *mem,
229 struct zone *zone, int priority,
230 enum lru_list lru)
KAMEZAWA Hiroyukicc381082008-02-07 00:14:35 -0800231{
232 return 0;
233}
Hirokazu Takahashif8d66542009-01-07 18:08:02 -0800234
235static inline bool mem_cgroup_disabled(void)
236{
237 return true;
238}
KAMEZAWA Hiroyukia636b322009-01-07 18:08:08 -0800239
240static inline bool mem_cgroup_oom_called(struct task_struct *task)
241{
242 return false;
243}
Pavel Emelianov78fb7462008-02-07 00:13:51 -0800244#endif /* CONFIG_CGROUP_MEM_CONT */
245
Balbir Singh8cdea7c2008-02-07 00:13:50 -0800246#endif /* _LINUX_MEMCONTROL_H */
247