blob: b02195dfc1b0d3eb3044972db401b50acb0ad27d [file] [log] [blame]
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -07001#ifndef __LINUX_PAGE_CGROUP_H
2#define __LINUX_PAGE_CGROUP_H
3
4#ifdef CONFIG_CGROUP_MEM_RES_CTLR
5#include <linux/bit_spinlock.h>
6/*
7 * Page Cgroup can be considered as an extended mem_map.
8 * A page_cgroup page is associated with every page descriptor. The
9 * page_cgroup helps us identify information about the cgroup
10 * All page cgroups are allocated at boot or memory hotplug event,
11 * then the page cgroup for pfn always exists.
12 */
13struct page_cgroup {
14 unsigned long flags;
15 struct mem_cgroup *mem_cgroup;
16 struct page *page;
17 struct list_head lru; /* per cgroup LRU list */
18};
19
Al Viro31168482008-11-22 17:33:24 +000020void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
KAMEZAWA Hiroyukica371c02009-06-12 10:33:53 +030021
22#ifdef CONFIG_SPARSEMEM
23static inline void __init page_cgroup_init_flatmem(void)
24{
25}
26extern void __init page_cgroup_init(void);
27#else
28void __init page_cgroup_init_flatmem(void);
29static inline void __init page_cgroup_init(void)
30{
31}
32#endif
33
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070034struct page_cgroup *lookup_page_cgroup(struct page *page);
35
36enum {
37 /* flags for mem_cgroup */
38 PCG_LOCK, /* page cgroup is locked */
39 PCG_CACHE, /* charged as cache */
40 PCG_USED, /* this object is in use. */
Balbir Singh4b3bde42009-09-23 15:56:32 -070041 PCG_ACCT_LRU, /* page has been accounted for */
KAMEZAWA Hiroyuki8725d542010-04-06 14:35:05 -070042 PCG_FILE_MAPPED, /* page is accounted as "mapped" */
akpm@linux-foundation.orgac39cf82010-05-26 14:42:46 -070043 PCG_MIGRATION, /* under page migration */
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070044};
45
46#define TESTPCGFLAG(uname, lname) \
47static inline int PageCgroup##uname(struct page_cgroup *pc) \
48 { return test_bit(PCG_##lname, &pc->flags); }
49
50#define SETPCGFLAG(uname, lname) \
51static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
52 { set_bit(PCG_##lname, &pc->flags); }
53
54#define CLEARPCGFLAG(uname, lname) \
55static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
56 { clear_bit(PCG_##lname, &pc->flags); }
57
Balbir Singh4b3bde42009-09-23 15:56:32 -070058#define TESTCLEARPCGFLAG(uname, lname) \
59static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
60 { return test_and_clear_bit(PCG_##lname, &pc->flags); }
61
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070062/* Cache flag is set only once (at allocation) */
63TESTPCGFLAG(Cache, CACHE)
Balbir Singh4b3bde42009-09-23 15:56:32 -070064CLEARPCGFLAG(Cache, CACHE)
65SETPCGFLAG(Cache, CACHE)
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070066
67TESTPCGFLAG(Used, USED)
68CLEARPCGFLAG(Used, USED)
Balbir Singh4b3bde42009-09-23 15:56:32 -070069SETPCGFLAG(Used, USED)
70
71SETPCGFLAG(AcctLRU, ACCT_LRU)
72CLEARPCGFLAG(AcctLRU, ACCT_LRU)
73TESTPCGFLAG(AcctLRU, ACCT_LRU)
74TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU)
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070075
KAMEZAWA Hiroyuki8725d542010-04-06 14:35:05 -070076
77SETPCGFLAG(FileMapped, FILE_MAPPED)
78CLEARPCGFLAG(FileMapped, FILE_MAPPED)
79TESTPCGFLAG(FileMapped, FILE_MAPPED)
80
akpm@linux-foundation.orgac39cf82010-05-26 14:42:46 -070081SETPCGFLAG(Migration, MIGRATION)
82CLEARPCGFLAG(Migration, MIGRATION)
83TESTPCGFLAG(Migration, MIGRATION)
84
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070085static inline int page_cgroup_nid(struct page_cgroup *pc)
86{
87 return page_to_nid(pc->page);
88}
89
90static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
91{
92 return page_zonenum(pc->page);
93}
94
95static inline void lock_page_cgroup(struct page_cgroup *pc)
96{
97 bit_spin_lock(PCG_LOCK, &pc->flags);
98}
99
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700100static inline void unlock_page_cgroup(struct page_cgroup *pc)
101{
102 bit_spin_unlock(PCG_LOCK, &pc->flags);
103}
104
Kirill A. Shutemov112bc2e2010-11-24 12:56:58 -0800105static inline int page_is_cgroup_locked(struct page_cgroup *pc)
106{
107 return bit_spin_is_locked(PCG_LOCK, &pc->flags);
108}
109
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700110#else /* CONFIG_CGROUP_MEM_RES_CTLR */
111struct page_cgroup;
112
Al Viro31168482008-11-22 17:33:24 +0000113static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700114{
115}
116
117static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
118{
119 return NULL;
120}
KAMEZAWA Hiroyuki94b6da52008-10-22 14:15:05 -0700121
122static inline void page_cgroup_init(void)
123{
124}
125
KAMEZAWA Hiroyukica371c02009-06-12 10:33:53 +0300126static inline void __init page_cgroup_init_flatmem(void)
127{
128}
129
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700130#endif
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800131
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800132#include <linux/swap.h>
Jaswinder Singh Rajput97572752009-09-20 16:20:44 +0530133
134#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
Daisuke Nishimura02491442010-03-10 15:22:17 -0800135extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
136 unsigned short old, unsigned short new);
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700137extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
138extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800139extern int swap_cgroup_swapon(int type, unsigned long max_pages);
140extern void swap_cgroup_swapoff(int type);
141#else
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800142
143static inline
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700144unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800145{
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700146 return 0;
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800147}
148
149static inline
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700150unsigned short lookup_swap_cgroup(swp_entry_t ent)
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800151{
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700152 return 0;
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800153}
154
155static inline int
156swap_cgroup_swapon(int type, unsigned long max_pages)
157{
158 return 0;
159}
160
161static inline void swap_cgroup_swapoff(int type)
162{
163 return;
164}
165
166#endif
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700167#endif