Commit | Line | Data |
---|---|---|
52d4b9ac KH |
1 | #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 | */ | |
13 | struct 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 | ||
31168481 | 20 | void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat); |
ca371c0d KH |
21 | |
22 | #ifdef CONFIG_SPARSEMEM | |
23 | static inline void __init page_cgroup_init_flatmem(void) | |
24 | { | |
25 | } | |
26 | extern void __init page_cgroup_init(void); | |
27 | #else | |
28 | void __init page_cgroup_init_flatmem(void); | |
29 | static inline void __init page_cgroup_init(void) | |
30 | { | |
31 | } | |
32 | #endif | |
33 | ||
52d4b9ac KH |
34 | struct page_cgroup *lookup_page_cgroup(struct page *page); |
35 | ||
36 | enum { | |
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. */ | |
4b3bde4c | 41 | PCG_ACCT_LRU, /* page has been accounted for */ |
8725d541 | 42 | PCG_FILE_MAPPED, /* page is accounted as "mapped" */ |
ac39cf8c | 43 | PCG_MIGRATION, /* under page migration */ |
52d4b9ac KH |
44 | }; |
45 | ||
46 | #define TESTPCGFLAG(uname, lname) \ | |
47 | static inline int PageCgroup##uname(struct page_cgroup *pc) \ | |
48 | { return test_bit(PCG_##lname, &pc->flags); } | |
49 | ||
50 | #define SETPCGFLAG(uname, lname) \ | |
51 | static inline void SetPageCgroup##uname(struct page_cgroup *pc)\ | |
52 | { set_bit(PCG_##lname, &pc->flags); } | |
53 | ||
54 | #define CLEARPCGFLAG(uname, lname) \ | |
55 | static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \ | |
56 | { clear_bit(PCG_##lname, &pc->flags); } | |
57 | ||
4b3bde4c BS |
58 | #define TESTCLEARPCGFLAG(uname, lname) \ |
59 | static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \ | |
60 | { return test_and_clear_bit(PCG_##lname, &pc->flags); } | |
61 | ||
52d4b9ac KH |
62 | /* Cache flag is set only once (at allocation) */ |
63 | TESTPCGFLAG(Cache, CACHE) | |
4b3bde4c BS |
64 | CLEARPCGFLAG(Cache, CACHE) |
65 | SETPCGFLAG(Cache, CACHE) | |
52d4b9ac KH |
66 | |
67 | TESTPCGFLAG(Used, USED) | |
68 | CLEARPCGFLAG(Used, USED) | |
4b3bde4c BS |
69 | SETPCGFLAG(Used, USED) |
70 | ||
71 | SETPCGFLAG(AcctLRU, ACCT_LRU) | |
72 | CLEARPCGFLAG(AcctLRU, ACCT_LRU) | |
73 | TESTPCGFLAG(AcctLRU, ACCT_LRU) | |
74 | TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU) | |
52d4b9ac | 75 | |
8725d541 KH |
76 | |
77 | SETPCGFLAG(FileMapped, FILE_MAPPED) | |
78 | CLEARPCGFLAG(FileMapped, FILE_MAPPED) | |
79 | TESTPCGFLAG(FileMapped, FILE_MAPPED) | |
80 | ||
ac39cf8c | 81 | SETPCGFLAG(Migration, MIGRATION) |
82 | CLEARPCGFLAG(Migration, MIGRATION) | |
83 | TESTPCGFLAG(Migration, MIGRATION) | |
84 | ||
52d4b9ac KH |
85 | static inline int page_cgroup_nid(struct page_cgroup *pc) |
86 | { | |
87 | return page_to_nid(pc->page); | |
88 | } | |
89 | ||
90 | static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc) | |
91 | { | |
92 | return page_zonenum(pc->page); | |
93 | } | |
94 | ||
95 | static inline void lock_page_cgroup(struct page_cgroup *pc) | |
96 | { | |
97 | bit_spin_lock(PCG_LOCK, &pc->flags); | |
98 | } | |
99 | ||
52d4b9ac KH |
100 | static inline void unlock_page_cgroup(struct page_cgroup *pc) |
101 | { | |
102 | bit_spin_unlock(PCG_LOCK, &pc->flags); | |
103 | } | |
104 | ||
112bc2e1 KS |
105 | static inline int page_is_cgroup_locked(struct page_cgroup *pc) |
106 | { | |
107 | return bit_spin_is_locked(PCG_LOCK, &pc->flags); | |
108 | } | |
109 | ||
52d4b9ac KH |
110 | #else /* CONFIG_CGROUP_MEM_RES_CTLR */ |
111 | struct page_cgroup; | |
112 | ||
31168481 | 113 | static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat) |
52d4b9ac KH |
114 | { |
115 | } | |
116 | ||
117 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) | |
118 | { | |
119 | return NULL; | |
120 | } | |
94b6da5a KH |
121 | |
122 | static inline void page_cgroup_init(void) | |
123 | { | |
124 | } | |
125 | ||
ca371c0d KH |
126 | static inline void __init page_cgroup_init_flatmem(void) |
127 | { | |
128 | } | |
129 | ||
27a7faa0 KH |
130 | #endif |
131 | ||
27a7faa0 | 132 | #include <linux/swap.h> |
97572751 JSR |
133 | |
134 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP | |
02491447 DN |
135 | extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
136 | unsigned short old, unsigned short new); | |
a3b2d692 KH |
137 | extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id); |
138 | extern unsigned short lookup_swap_cgroup(swp_entry_t ent); | |
27a7faa0 KH |
139 | extern int swap_cgroup_swapon(int type, unsigned long max_pages); |
140 | extern void swap_cgroup_swapoff(int type); | |
141 | #else | |
27a7faa0 KH |
142 | |
143 | static inline | |
a3b2d692 | 144 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
27a7faa0 | 145 | { |
a3b2d692 | 146 | return 0; |
27a7faa0 KH |
147 | } |
148 | ||
149 | static inline | |
a3b2d692 | 150 | unsigned short lookup_swap_cgroup(swp_entry_t ent) |
27a7faa0 | 151 | { |
a3b2d692 | 152 | return 0; |
27a7faa0 KH |
153 | } |
154 | ||
155 | static inline int | |
156 | swap_cgroup_swapon(int type, unsigned long max_pages) | |
157 | { | |
158 | return 0; | |
159 | } | |
160 | ||
161 | static inline void swap_cgroup_swapoff(int type) | |
162 | { | |
163 | return; | |
164 | } | |
165 | ||
52d4b9ac KH |
166 | #endif |
167 | #endif |