blob: b87068a1a09ef84ece916a4a722ebf70e921d1c6 [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>
Ying Han456f9982011-05-26 16:25:38 -070023#include <linux/vm_event_item.h>
24
Pavel Emelianov78fb7462008-02-07 00:13:51 -080025struct mem_cgroup;
26struct page_cgroup;
Balbir Singh8697d332008-02-07 00:13:59 -080027struct page;
28struct mm_struct;
Pavel Emelianov78fb7462008-02-07 00:13:51 -080029
Greg Thelen2a7106f2011-01-13 15:47:37 -080030/* Stats that can be updated by kernel. */
31enum mem_cgroup_page_stat_item {
32 MEMCG_NR_FILE_MAPPED, /* # of pages charged as file rss */
33};
34
Johannes Weiner8b25c6d2010-05-24 14:32:40 -070035extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
36 struct list_head *dst,
37 unsigned long *scanned, int order,
Minchan Kim4356f212011-10-31 17:06:47 -070038 isolate_mode_t mode,
39 struct zone *z,
Johannes Weiner8b25c6d2010-05-24 14:32:40 -070040 struct mem_cgroup *mem_cont,
41 int active, int file);
42
Balbir Singh00f0b822008-03-04 14:28:39 -080043#ifdef CONFIG_CGROUP_MEM_RES_CTLR
KAMEZAWA Hiroyuki2c26fdd2009-01-07 18:08:10 -080044/*
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
51 * codes.
52 * (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.)
53 */
Pavel Emelianov78fb7462008-02-07 00:13:51 -080054
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -080055extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm,
Balbir Singhe1a1cd52008-02-07 00:14:02 -080056 gfp_t gfp_mask);
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -080057/* for swap handling */
KAMEZAWA Hiroyuki8c7c6e32009-01-07 18:08:00 -080058extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
59 struct page *page, gfp_t mask, struct mem_cgroup **ptr);
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -080060extern void mem_cgroup_commit_charge_swapin(struct page *page,
61 struct mem_cgroup *ptr);
62extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr);
63
Hugh Dickins82895462008-03-04 14:29:08 -080064extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
65 gfp_t gfp_mask);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080066extern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru);
67extern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru);
Minchan Kim3f58a822011-03-22 16:32:53 -070068extern void mem_cgroup_rotate_reclaimable_page(struct page *page);
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -080069extern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru);
70extern void mem_cgroup_del_lru(struct page *page);
71extern void mem_cgroup_move_lists(struct page *page,
72 enum lru_list from, enum lru_list to);
KAMEZAWA Hiroyuki569b8462009-12-15 16:47:03 -080073
74/* For coalescing uncharge for reducing memcg' overhead*/
75extern void mem_cgroup_uncharge_start(void);
76extern void mem_cgroup_uncharge_end(void);
77
Balbir Singh3c541e12008-02-07 00:14:41 -080078extern void mem_cgroup_uncharge_page(struct page *page);
KAMEZAWA Hiroyuki69029cd2008-07-25 01:47:14 -070079extern void mem_cgroup_uncharge_cache_page(struct page *page);
KAMEZAWA Hiroyukic9b0ed52008-07-25 01:47:15 -070080
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -070081extern void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask);
82int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg);
David Rientjes3062fc62008-02-07 00:14:03 -080083
Wu Fengguange42d9d52009-12-16 12:19:59 +010084extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
Balbir Singhcf475ad2008-04-29 01:00:16 -070085extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
KOSAKI Motohiroa4336582011-06-15 15:08:13 -070086extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
Balbir Singhcf475ad2008-04-29 01:00:16 -070087
Lai Jiangshan2e4d4092009-01-07 18:08:07 -080088static inline
89int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
90{
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -070091 struct mem_cgroup *memcg;
Lai Jiangshan2e4d4092009-01-07 18:08:07 -080092 rcu_read_lock();
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -070093 memcg = mem_cgroup_from_task(rcu_dereference((mm)->owner));
Lai Jiangshan2e4d4092009-01-07 18:08:07 -080094 rcu_read_unlock();
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -070095 return cgroup == memcg;
Lai Jiangshan2e4d4092009-01-07 18:08:07 -080096}
Balbir Singh8a9f3cc2008-02-07 00:13:53 -080097
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -070098extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg);
Wu Fengguangd3242362009-12-16 12:19:59 +010099
KAMEZAWA Hiroyukie8589cc2008-07-25 01:47:10 -0700100extern int
akpm@linux-foundation.orgac39cf82010-05-26 14:42:46 -0700101mem_cgroup_prepare_migration(struct page *page,
Miklos Szeredief6a3c62011-03-22 16:30:52 -0700102 struct page *newpage, struct mem_cgroup **ptr, gfp_t gfp_mask);
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700103extern void mem_cgroup_end_migration(struct mem_cgroup *memcg,
Daisuke Nishimura50de1dd2011-01-13 15:47:43 -0800104 struct page *oldpage, struct page *newpage, bool migration_ok);
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -0800105
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -0800106/*
107 * For memory reclaim.
108 */
Johannes Weiner9b272972011-11-02 13:38:23 -0700109int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg,
110 struct zone *zone);
111int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg,
112 struct zone *zone);
Ying Han889976d2011-05-26 16:25:33 -0700113int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
Ying Han1bac1802011-05-26 16:25:36 -0700114unsigned long mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg,
KAMEZAWA Hiroyukibb2a0de2011-07-26 16:08:22 -0700115 int nid, int zid, unsigned int lrumask);
KOSAKI Motohiro3e2f41f2009-01-07 18:08:20 -0800116struct zone_reclaim_stat *mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg,
117 struct zone *zone);
118struct zone_reclaim_stat*
119mem_cgroup_get_reclaim_stat_from_page(struct page *page);
Balbir Singhe2224322009-04-02 16:57:39 -0700120extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
121 struct task_struct *p);
KAMEZAWA Hiroyuki58ae83d2008-02-07 00:14:32 -0800122
KAMEZAWA Hiroyukic0777192009-01-07 18:07:57 -0800123#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
124extern int do_swap_account;
125#endif
Hirokazu Takahashif8d66542009-01-07 18:08:02 -0800126
127static inline bool mem_cgroup_disabled(void)
128{
129 if (mem_cgroup_subsys.disabled)
130 return true;
131 return false;
132}
133
Greg Thelen2a7106f2011-01-13 15:47:37 -0800134void mem_cgroup_update_page_stat(struct page *page,
135 enum mem_cgroup_page_stat_item idx,
136 int val);
137
138static inline void mem_cgroup_inc_page_stat(struct page *page,
139 enum mem_cgroup_page_stat_item idx)
140{
141 mem_cgroup_update_page_stat(page, idx, 1);
142}
143
144static inline void mem_cgroup_dec_page_stat(struct page *page,
145 enum mem_cgroup_page_stat_item idx)
146{
147 mem_cgroup_update_page_stat(page, idx, -1);
148}
149
Balbir Singh4e416952009-09-23 15:56:39 -0700150unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
Ying Han0ae5e892011-05-26 16:25:25 -0700151 gfp_t gfp_mask,
152 unsigned long *total_scanned);
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700153u64 mem_cgroup_get_limit(struct mem_cgroup *memcg);
David Rientjesa63d83f2010-08-09 17:19:46 -0700154
Ying Han456f9982011-05-26 16:25:38 -0700155void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
KAMEZAWA Hiroyukica3e0212011-01-20 14:44:24 -0800156#ifdef CONFIG_TRANSPARENT_HUGEPAGE
157void mem_cgroup_split_huge_fixup(struct page *head, struct page *tail);
158#endif
159
Daisuke Nishimuraf212ad72011-03-23 16:42:25 -0700160#ifdef CONFIG_DEBUG_VM
161bool mem_cgroup_bad_page_check(struct page *page);
162void mem_cgroup_print_bad_page(struct page *page);
163#endif
Balbir Singh00f0b822008-03-04 14:28:39 -0800164#else /* CONFIG_CGROUP_MEM_RES_CTLR */
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800165struct mem_cgroup;
166
167static inline int mem_cgroup_newpage_charge(struct page *page,
Hugh Dickins82895462008-03-04 14:29:08 -0800168 struct mm_struct *mm, gfp_t gfp_mask)
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800169{
170 return 0;
171}
172
Hugh Dickins82895462008-03-04 14:29:08 -0800173static inline int mem_cgroup_cache_charge(struct page *page,
174 struct mm_struct *mm, gfp_t gfp_mask)
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800175{
Hugh Dickins82895462008-03-04 14:29:08 -0800176 return 0;
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800177}
178
KAMEZAWA Hiroyuki8c7c6e32009-01-07 18:08:00 -0800179static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
180 struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr)
KAMEZAWA Hiroyuki7a81b882009-01-07 18:07:48 -0800181{
182 return 0;
183}
184
185static inline void mem_cgroup_commit_charge_swapin(struct page *page,
186 struct mem_cgroup *ptr)
187{
188}
189
190static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr)
191{
192}
193
KAMEZAWA Hiroyuki569b8462009-12-15 16:47:03 -0800194static inline void mem_cgroup_uncharge_start(void)
195{
196}
197
198static inline void mem_cgroup_uncharge_end(void)
199{
200}
201
Balbir Singh8a9f3cc2008-02-07 00:13:53 -0800202static inline void mem_cgroup_uncharge_page(struct page *page)
203{
204}
205
KAMEZAWA Hiroyuki69029cd2008-07-25 01:47:14 -0700206static inline void mem_cgroup_uncharge_cache_page(struct page *page)
207{
208}
209
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -0800210static inline void mem_cgroup_add_lru_list(struct page *page, int lru)
211{
212}
213
214static inline void mem_cgroup_del_lru_list(struct page *page, int lru)
215{
216 return ;
217}
218
Eric Dumazet67954fe2011-04-14 15:21:52 -0700219static inline void mem_cgroup_rotate_reclaimable_page(struct page *page)
Minchan Kim3f58a822011-03-22 16:32:53 -0700220{
221 return ;
222}
223
KAMEZAWA Hiroyuki08e552c2009-01-07 18:08:01 -0800224static inline void mem_cgroup_rotate_lru_list(struct page *page, int lru)
225{
226 return ;
227}
228
229static inline void mem_cgroup_del_lru(struct page *page)
230{
231 return ;
232}
233
234static inline void
235mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to)
Balbir Singh66e17072008-02-07 00:13:56 -0800236{
237}
238
Wu Fengguange42d9d52009-12-16 12:19:59 +0100239static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
240{
241 return NULL;
242}
243
KOSAKI Motohiroa4336582011-06-15 15:08:13 -0700244static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
245{
246 return NULL;
247}
248
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700249static inline int mm_match_cgroup(struct mm_struct *mm,
250 struct mem_cgroup *memcg)
Balbir Singhbed71612008-02-07 00:14:01 -0800251{
David Rientjes60c12b12008-02-09 00:10:15 -0800252 return 1;
Balbir Singhbed71612008-02-07 00:14:01 -0800253}
254
David Rientjes4c4a2212008-02-07 00:14:06 -0800255static inline int task_in_mem_cgroup(struct task_struct *task,
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700256 const struct mem_cgroup *memcg)
David Rientjes4c4a2212008-02-07 00:14:06 -0800257{
258 return 1;
259}
260
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700261static inline struct cgroup_subsys_state
262 *mem_cgroup_css(struct mem_cgroup *memcg)
Wu Fengguangd3242362009-12-16 12:19:59 +0100263{
264 return NULL;
265}
266
KAMEZAWA Hiroyukie8589cc2008-07-25 01:47:10 -0700267static inline int
akpm@linux-foundation.orgac39cf82010-05-26 14:42:46 -0700268mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
Miklos Szeredief6a3c62011-03-22 16:30:52 -0700269 struct mem_cgroup **ptr, gfp_t gfp_mask)
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -0800270{
271 return 0;
272}
273
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700274static inline void mem_cgroup_end_migration(struct mem_cgroup *memcg,
Daisuke Nishimura50de1dd2011-01-13 15:47:43 -0800275 struct page *oldpage, struct page *newpage, bool migration_ok)
KAMEZAWA Hiroyukiae41be32008-02-07 00:14:10 -0800276{
277}
278
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700279static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *memcg)
KAMEZAWA Hiroyuki6c48a1d2008-02-07 00:14:34 -0800280{
281 return 0;
282}
283
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700284static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *memcg,
KAMEZAWA Hiroyuki6c48a1d2008-02-07 00:14:34 -0800285 int priority)
286{
287}
288
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700289static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *memcg,
KAMEZAWA Hiroyuki6c48a1d2008-02-07 00:14:34 -0800290 int priority)
291{
292}
293
Hirokazu Takahashif8d66542009-01-07 18:08:02 -0800294static inline bool mem_cgroup_disabled(void)
295{
296 return true;
297}
KAMEZAWA Hiroyukia636b322009-01-07 18:08:08 -0800298
KOSAKI Motohiro14797e22009-01-07 18:08:18 -0800299static inline int
Johannes Weiner9b272972011-11-02 13:38:23 -0700300mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg, struct zone *zone)
KOSAKI Motohiro14797e22009-01-07 18:08:18 -0800301{
302 return 1;
303}
304
Rik van Riel56e49d22009-06-16 15:32:28 -0700305static inline int
Johannes Weiner9b272972011-11-02 13:38:23 -0700306mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg, struct zone *zone)
Rik van Riel56e49d22009-06-16 15:32:28 -0700307{
308 return 1;
309}
310
KOSAKI Motohiroa3d8e052009-01-07 18:08:19 -0800311static inline unsigned long
KAMEZAWA Hiroyukibb2a0de2011-07-26 16:08:22 -0700312mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,
313 unsigned int lru_mask)
KOSAKI Motohiroa3d8e052009-01-07 18:08:19 -0800314{
315 return 0;
316}
317
318
KOSAKI Motohiro3e2f41f2009-01-07 18:08:20 -0800319static inline struct zone_reclaim_stat*
320mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg, struct zone *zone)
321{
322 return NULL;
323}
324
325static inline struct zone_reclaim_stat*
326mem_cgroup_get_reclaim_stat_from_page(struct page *page)
327{
328 return NULL;
329}
330
Balbir Singhe2224322009-04-02 16:57:39 -0700331static inline void
332mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
333{
334}
335
Greg Thelen2a7106f2011-01-13 15:47:37 -0800336static inline void mem_cgroup_inc_page_stat(struct page *page,
337 enum mem_cgroup_page_stat_item idx)
338{
339}
340
341static inline void mem_cgroup_dec_page_stat(struct page *page,
342 enum mem_cgroup_page_stat_item idx)
Balbir Singhd69b0422009-06-17 16:26:34 -0700343{
344}
345
Balbir Singh4e416952009-09-23 15:56:39 -0700346static inline
347unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
Ying Han0ae5e892011-05-26 16:25:25 -0700348 gfp_t gfp_mask,
349 unsigned long *total_scanned)
Balbir Singh4e416952009-09-23 15:56:39 -0700350{
351 return 0;
352}
353
David Rientjesa63d83f2010-08-09 17:19:46 -0700354static inline
Raghavendra K Tc0ff4b82011-11-02 13:38:15 -0700355u64 mem_cgroup_get_limit(struct mem_cgroup *memcg)
David Rientjesa63d83f2010-08-09 17:19:46 -0700356{
357 return 0;
358}
359
KAMEZAWA Hiroyukica3e0212011-01-20 14:44:24 -0800360static inline void mem_cgroup_split_huge_fixup(struct page *head,
361 struct page *tail)
362{
363}
364
Ying Han456f9982011-05-26 16:25:38 -0700365static inline
366void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
367{
368}
Pavel Emelianov78fb7462008-02-07 00:13:51 -0800369#endif /* CONFIG_CGROUP_MEM_CONT */
370
Daisuke Nishimuraf212ad72011-03-23 16:42:25 -0700371#if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM)
372static inline bool
373mem_cgroup_bad_page_check(struct page *page)
374{
375 return false;
376}
377
378static inline void
379mem_cgroup_print_bad_page(struct page *page)
380{
381}
382#endif
383
Balbir Singh8cdea7c2008-02-07 00:13:50 -0800384#endif /* _LINUX_MEMCONTROL_H */
385