blob: ca51ac72d6c0f7d77e0b6d5ca64aeaa2b343ec5d [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
22
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 Hiroyuki8c7c6e342009-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);
Lee Schermerhorn894bc312008-10-18 20:26:39 -070043extern void mem_cgroup_move_lists(struct page *page, enum lru_list lru);
Balbir Singh3c541e12008-02-07 00:14:41 -080044extern void mem_cgroup_uncharge_page(struct page *page);
KAMEZAWA Hiroyuki69029cd2008-07-25 01:47:14 -070045extern void mem_cgroup_uncharge_cache_page(struct page *page);
KAMEZAWA Hiroyukic9b0ed52008-07-25 01:47:15 -070046extern int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask);
47
Balbir Singh66e17072008-02-07 00:13:56 -080048extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
49 struct list_head *dst,
50 unsigned long *scanned, int order,
51 int mode, struct zone *z,
52 struct mem_cgroup *mem_cont,
Rik van Riel4f98a2f2008-10-18 20:26:32 -070053 int active, int file);
Pavel Emelianovc7ba5c92008-02-07 00:13:58 -080054extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask);
David Rientjes4c4a2212008-02-07 00:14:06 -080055int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);
David Rientjes3062fc62008-02-07 00:14:03 -080056
Balbir Singhcf475ad2008-04-29 01:00:16 -070057extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
58
Hugh Dickinsbd845e32008-03-04 14:29:01 -080059#define mm_match_cgroup(mm, cgroup) \
Balbir Singhcf475ad2008-04-29 01:00:16 -070060 ((cgroup) == mem_cgroup_from_task((mm)->owner))
Balbir Singh8a9f3cc2008-02-07 00:13:53 -080061
KAMEZAWA Hiroyukie8589cc2008-07-25 01:47:10 -070062extern int
KAMEZAWA Hiroyuki01b1ae62009-01-07 18:07:50 -080063mem_cgroup_prepare_migration(struct page *page, struct mem_cgroup **ptr);
64extern void mem_cgroup_end_migration(struct mem_cgroup *mem,
65 struct page *oldpage, struct page *newpage);
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -080066
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -080067/*
68 * For memory reclaim.
69 */
70extern int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem);
KAMEZAWA Hiroyuki5932f362008-02-07 00:14:33 -080071extern long mem_cgroup_reclaim_imbalance(struct mem_cgroup *mem);
72
KAMEZAWA Hiroyuki6c48a1d2008-02-07 00:14:34 -080073extern int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem);
74extern void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem,
75 int priority);
76extern void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
77 int priority);
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -080078
Christoph Lameterb69408e2008-10-18 20:26:14 -070079extern long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone,
80 int priority, enum lru_list lru);
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -080081
KAMEZAWA Hiroyukic0777192009-01-07 18:07:57 -080082#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
83extern int do_swap_account;
84#endif
Balbir Singh00f0b822008-03-04 14:28:39 -080085#else /* CONFIG_CGROUP_MEM_RES_CTLR */
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -080086struct mem_cgroup;
87
88static inline int mem_cgroup_newpage_charge(struct page *page,
Hugh Dickins82895462008-03-04 14:29:08 -080089 struct mm_struct *mm, gfp_t gfp_mask)
Balbir Singh8a9f3cc2008-02-07 00:13:53 -080090{
91 return 0;
92}
93
Hugh Dickins82895462008-03-04 14:29:08 -080094static inline int mem_cgroup_cache_charge(struct page *page,
95 struct mm_struct *mm, gfp_t gfp_mask)
Balbir Singh8a9f3cc2008-02-07 00:13:53 -080096{
Hugh Dickins82895462008-03-04 14:29:08 -080097 return 0;
Balbir Singh8a9f3cc2008-02-07 00:13:53 -080098}
99
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800100static inline int mem_cgroup_try_charge(struct mm_struct *mm,
KAMEZAWA Hiroyuki8c7c6e342009-01-07 18:08:00 -0800101 gfp_t gfp_mask, struct mem_cgroup **ptr)
102{
103 return 0;
104}
105
106static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
107 struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr)
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800108{
109 return 0;
110}
111
112static inline void mem_cgroup_commit_charge_swapin(struct page *page,
113 struct mem_cgroup *ptr)
114{
115}
116
117static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr)
118{
119}
120
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800121static inline void mem_cgroup_uncharge_page(struct page *page)
122{
123}
124
KAMEZAWA Hiroyuki69029cd2008-07-25 01:47:14 -0700125static inline void mem_cgroup_uncharge_cache_page(struct page *page)
126{
127}
128
KAMEZAWA Hiroyukic9b0ed52008-07-25 01:47:15 -0700129static inline int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask)
130{
131 return 0;
132}
133
Hugh Dickins427d5412008-03-04 14:29:03 -0800134static inline void mem_cgroup_move_lists(struct page *page, bool active)
Balbir Singh66e17072008-02-07 00:13:56 -0800135{
136}
137
Hugh Dickinsbd845e32008-03-04 14:29:01 -0800138static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem)
Balbir Singhbed71612008-02-07 00:14:01 -0800139{
David Rientjes60c12b12008-02-09 00:10:15 -0800140 return 1;
Balbir Singhbed71612008-02-07 00:14:01 -0800141}
142
David Rientjes4c4a2212008-02-07 00:14:06 -0800143static inline int task_in_mem_cgroup(struct task_struct *task,
144 const struct mem_cgroup *mem)
145{
146 return 1;
147}
148
KAMEZAWA Hiroyukie8589cc2008-07-25 01:47:10 -0700149static inline int
KAMEZAWA Hiroyuki01b1ae62009-01-07 18:07:50 -0800150mem_cgroup_prepare_migration(struct page *page, struct mem_cgroup **ptr)
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -0800151{
152 return 0;
153}
154
KAMEZAWA Hiroyuki01b1ae62009-01-07 18:07:50 -0800155static inline void mem_cgroup_end_migration(struct mem_cgroup *mem,
156 struct page *oldpage,
157 struct page *newpage)
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -0800158{
159}
160
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -0800161static inline int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem)
162{
163 return 0;
164}
KAMEZAWA Hiroyuki5932f362008-02-07 00:14:33 -0800165
166static inline int mem_cgroup_reclaim_imbalance(struct mem_cgroup *mem)
167{
168 return 0;
169}
170
KAMEZAWA Hiroyuki6c48a1d2008-02-07 00:14:34 -0800171static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem)
172{
173 return 0;
174}
175
176static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem,
177 int priority)
178{
179}
180
181static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
182 int priority)
183{
184}
185
Christoph Lameterb69408e2008-10-18 20:26:14 -0700186static inline long mem_cgroup_calc_reclaim(struct mem_cgroup *mem,
187 struct zone *zone, int priority,
188 enum lru_list lru)
KAMEZAWA Hiroyukicc381082008-02-07 00:14:35 -0800189{
190 return 0;
191}
Pavel Emelianov78fb7462008-02-07 00:13:51 -0800192#endif /* CONFIG_CGROUP_MEM_CONT */
193
Balbir Singh8cdea7c2008-02-07 00:13:50 -0800194#endif /* _LINUX_MEMCONTROL_H */
195