Commit | Line | Data |
---|---|---|
52d4b9ac KH |
1 | #ifndef __LINUX_PAGE_CGROUP_H |
2 | #define __LINUX_PAGE_CGROUP_H | |
3 | ||
6b3ae58e JW |
4 | enum { |
5 | /* flags for mem_cgroup */ | |
6 | PCG_LOCK, /* Lock for pc->mem_cgroup and following bits. */ | |
7 | PCG_CACHE, /* charged as cache */ | |
8 | PCG_USED, /* this object is in use. */ | |
9 | PCG_MIGRATION, /* under page migration */ | |
10 | /* flags for mem_cgroup and file and I/O status */ | |
11 | PCG_MOVE_LOCK, /* For race between move_account v.s. following bits */ | |
12 | PCG_FILE_MAPPED, /* page is accounted as "mapped" */ | |
13 | /* No lock in page_cgroup */ | |
14 | PCG_ACCT_LRU, /* page has been accounted for (under lru_lock) */ | |
15 | __NR_PCG_FLAGS, | |
16 | }; | |
17 | ||
18 | #ifndef __GENERATING_BOUNDS_H | |
19 | #include <generated/bounds.h> | |
20 | ||
52d4b9ac KH |
21 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR |
22 | #include <linux/bit_spinlock.h> | |
6b3ae58e | 23 | |
52d4b9ac KH |
24 | /* |
25 | * Page Cgroup can be considered as an extended mem_map. | |
26 | * A page_cgroup page is associated with every page descriptor. The | |
27 | * page_cgroup helps us identify information about the cgroup | |
28 | * All page cgroups are allocated at boot or memory hotplug event, | |
29 | * then the page cgroup for pfn always exists. | |
30 | */ | |
31 | struct page_cgroup { | |
32 | unsigned long flags; | |
33 | struct mem_cgroup *mem_cgroup; | |
52d4b9ac KH |
34 | }; |
35 | ||
31168481 | 36 | void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat); |
ca371c0d KH |
37 | |
38 | #ifdef CONFIG_SPARSEMEM | |
39 | static inline void __init page_cgroup_init_flatmem(void) | |
40 | { | |
41 | } | |
42 | extern void __init page_cgroup_init(void); | |
43 | #else | |
44 | void __init page_cgroup_init_flatmem(void); | |
45 | static inline void __init page_cgroup_init(void) | |
46 | { | |
47 | } | |
48 | #endif | |
49 | ||
52d4b9ac | 50 | struct page_cgroup *lookup_page_cgroup(struct page *page); |
6b3ae58e | 51 | struct page *lookup_cgroup_page(struct page_cgroup *pc); |
52d4b9ac KH |
52 | |
53 | #define TESTPCGFLAG(uname, lname) \ | |
54 | static inline int PageCgroup##uname(struct page_cgroup *pc) \ | |
55 | { return test_bit(PCG_##lname, &pc->flags); } | |
56 | ||
57 | #define SETPCGFLAG(uname, lname) \ | |
58 | static inline void SetPageCgroup##uname(struct page_cgroup *pc)\ | |
59 | { set_bit(PCG_##lname, &pc->flags); } | |
60 | ||
61 | #define CLEARPCGFLAG(uname, lname) \ | |
62 | static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \ | |
63 | { clear_bit(PCG_##lname, &pc->flags); } | |
64 | ||
4b3bde4c BS |
65 | #define TESTCLEARPCGFLAG(uname, lname) \ |
66 | static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \ | |
67 | { return test_and_clear_bit(PCG_##lname, &pc->flags); } | |
68 | ||
52d4b9ac KH |
69 | /* Cache flag is set only once (at allocation) */ |
70 | TESTPCGFLAG(Cache, CACHE) | |
4b3bde4c BS |
71 | CLEARPCGFLAG(Cache, CACHE) |
72 | SETPCGFLAG(Cache, CACHE) | |
52d4b9ac KH |
73 | |
74 | TESTPCGFLAG(Used, USED) | |
75 | CLEARPCGFLAG(Used, USED) | |
4b3bde4c BS |
76 | SETPCGFLAG(Used, USED) |
77 | ||
78 | SETPCGFLAG(AcctLRU, ACCT_LRU) | |
79 | CLEARPCGFLAG(AcctLRU, ACCT_LRU) | |
80 | TESTPCGFLAG(AcctLRU, ACCT_LRU) | |
81 | TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU) | |
52d4b9ac | 82 | |
8725d541 KH |
83 | |
84 | SETPCGFLAG(FileMapped, FILE_MAPPED) | |
85 | CLEARPCGFLAG(FileMapped, FILE_MAPPED) | |
86 | TESTPCGFLAG(FileMapped, FILE_MAPPED) | |
87 | ||
ac39cf8c | 88 | SETPCGFLAG(Migration, MIGRATION) |
89 | CLEARPCGFLAG(Migration, MIGRATION) | |
90 | TESTPCGFLAG(Migration, MIGRATION) | |
91 | ||
52d4b9ac KH |
92 | static inline void lock_page_cgroup(struct page_cgroup *pc) |
93 | { | |
dbd4ea78 KH |
94 | /* |
95 | * Don't take this lock in IRQ context. | |
96 | * This lock is for pc->mem_cgroup, USED, CACHE, MIGRATION | |
97 | */ | |
52d4b9ac KH |
98 | bit_spin_lock(PCG_LOCK, &pc->flags); |
99 | } | |
100 | ||
52d4b9ac KH |
101 | static inline void unlock_page_cgroup(struct page_cgroup *pc) |
102 | { | |
103 | bit_spin_unlock(PCG_LOCK, &pc->flags); | |
104 | } | |
105 | ||
dbd4ea78 KH |
106 | static inline void move_lock_page_cgroup(struct page_cgroup *pc, |
107 | unsigned long *flags) | |
108 | { | |
109 | /* | |
110 | * We know updates to pc->flags of page cache's stats are from both of | |
111 | * usual context or IRQ context. Disable IRQ to avoid deadlock. | |
112 | */ | |
113 | local_irq_save(*flags); | |
114 | bit_spin_lock(PCG_MOVE_LOCK, &pc->flags); | |
115 | } | |
116 | ||
117 | static inline void move_unlock_page_cgroup(struct page_cgroup *pc, | |
118 | unsigned long *flags) | |
119 | { | |
120 | bit_spin_unlock(PCG_MOVE_LOCK, &pc->flags); | |
121 | local_irq_restore(*flags); | |
122 | } | |
123 | ||
52d4b9ac KH |
124 | #else /* CONFIG_CGROUP_MEM_RES_CTLR */ |
125 | struct page_cgroup; | |
126 | ||
31168481 | 127 | static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat) |
52d4b9ac KH |
128 | { |
129 | } | |
130 | ||
131 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) | |
132 | { | |
133 | return NULL; | |
134 | } | |
94b6da5a KH |
135 | |
136 | static inline void page_cgroup_init(void) | |
137 | { | |
138 | } | |
139 | ||
ca371c0d KH |
140 | static inline void __init page_cgroup_init_flatmem(void) |
141 | { | |
142 | } | |
143 | ||
6b3ae58e | 144 | #endif /* CONFIG_CGROUP_MEM_RES_CTLR */ |
27a7faa0 | 145 | |
27a7faa0 | 146 | #include <linux/swap.h> |
97572751 JSR |
147 | |
148 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP | |
02491447 DN |
149 | extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
150 | unsigned short old, unsigned short new); | |
a3b2d692 KH |
151 | extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id); |
152 | extern unsigned short lookup_swap_cgroup(swp_entry_t ent); | |
27a7faa0 KH |
153 | extern int swap_cgroup_swapon(int type, unsigned long max_pages); |
154 | extern void swap_cgroup_swapoff(int type); | |
155 | #else | |
27a7faa0 KH |
156 | |
157 | static inline | |
a3b2d692 | 158 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
27a7faa0 | 159 | { |
a3b2d692 | 160 | return 0; |
27a7faa0 KH |
161 | } |
162 | ||
163 | static inline | |
a3b2d692 | 164 | unsigned short lookup_swap_cgroup(swp_entry_t ent) |
27a7faa0 | 165 | { |
a3b2d692 | 166 | return 0; |
27a7faa0 KH |
167 | } |
168 | ||
169 | static inline int | |
170 | swap_cgroup_swapon(int type, unsigned long max_pages) | |
171 | { | |
172 | return 0; | |
173 | } | |
174 | ||
175 | static inline void swap_cgroup_swapoff(int type) | |
176 | { | |
177 | return; | |
178 | } | |
179 | ||
6b3ae58e JW |
180 | #endif /* CONFIG_CGROUP_MEM_RES_CTLR_SWAP */ |
181 | ||
182 | #endif /* !__GENERATING_BOUNDS_H */ | |
183 | ||
184 | #endif /* __LINUX_PAGE_CGROUP_H */ |