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 */ | |
dbd4ea78 | 38 | PCG_LOCK, /* Lock for pc->mem_cgroup and following bits. */ |
52d4b9ac KH |
39 | PCG_CACHE, /* charged as cache */ |
40 | PCG_USED, /* this object is in use. */ | |
dbd4ea78 KH |
41 | PCG_MIGRATION, /* under page migration */ |
42 | /* flags for mem_cgroup and file and I/O status */ | |
43 | PCG_MOVE_LOCK, /* For race between move_account v.s. following bits */ | |
8725d541 | 44 | PCG_FILE_MAPPED, /* page is accounted as "mapped" */ |
dbd4ea78 KH |
45 | /* No lock in page_cgroup */ |
46 | PCG_ACCT_LRU, /* page has been accounted for (under lru_lock) */ | |
52d4b9ac KH |
47 | }; |
48 | ||
49 | #define TESTPCGFLAG(uname, lname) \ | |
50 | static inline int PageCgroup##uname(struct page_cgroup *pc) \ | |
51 | { return test_bit(PCG_##lname, &pc->flags); } | |
52 | ||
53 | #define SETPCGFLAG(uname, lname) \ | |
54 | static inline void SetPageCgroup##uname(struct page_cgroup *pc)\ | |
55 | { set_bit(PCG_##lname, &pc->flags); } | |
56 | ||
57 | #define CLEARPCGFLAG(uname, lname) \ | |
58 | static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \ | |
59 | { clear_bit(PCG_##lname, &pc->flags); } | |
60 | ||
4b3bde4c BS |
61 | #define TESTCLEARPCGFLAG(uname, lname) \ |
62 | static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \ | |
63 | { return test_and_clear_bit(PCG_##lname, &pc->flags); } | |
64 | ||
52d4b9ac KH |
65 | /* Cache flag is set only once (at allocation) */ |
66 | TESTPCGFLAG(Cache, CACHE) | |
4b3bde4c BS |
67 | CLEARPCGFLAG(Cache, CACHE) |
68 | SETPCGFLAG(Cache, CACHE) | |
52d4b9ac KH |
69 | |
70 | TESTPCGFLAG(Used, USED) | |
71 | CLEARPCGFLAG(Used, USED) | |
4b3bde4c BS |
72 | SETPCGFLAG(Used, USED) |
73 | ||
74 | SETPCGFLAG(AcctLRU, ACCT_LRU) | |
75 | CLEARPCGFLAG(AcctLRU, ACCT_LRU) | |
76 | TESTPCGFLAG(AcctLRU, ACCT_LRU) | |
77 | TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU) | |
52d4b9ac | 78 | |
8725d541 KH |
79 | |
80 | SETPCGFLAG(FileMapped, FILE_MAPPED) | |
81 | CLEARPCGFLAG(FileMapped, FILE_MAPPED) | |
82 | TESTPCGFLAG(FileMapped, FILE_MAPPED) | |
83 | ||
ac39cf8c | 84 | SETPCGFLAG(Migration, MIGRATION) |
85 | CLEARPCGFLAG(Migration, MIGRATION) | |
86 | TESTPCGFLAG(Migration, MIGRATION) | |
87 | ||
52d4b9ac KH |
88 | static inline void lock_page_cgroup(struct page_cgroup *pc) |
89 | { | |
dbd4ea78 KH |
90 | /* |
91 | * Don't take this lock in IRQ context. | |
92 | * This lock is for pc->mem_cgroup, USED, CACHE, MIGRATION | |
93 | */ | |
52d4b9ac KH |
94 | bit_spin_lock(PCG_LOCK, &pc->flags); |
95 | } | |
96 | ||
52d4b9ac KH |
97 | static inline void unlock_page_cgroup(struct page_cgroup *pc) |
98 | { | |
99 | bit_spin_unlock(PCG_LOCK, &pc->flags); | |
100 | } | |
101 | ||
dbd4ea78 KH |
102 | static inline void move_lock_page_cgroup(struct page_cgroup *pc, |
103 | unsigned long *flags) | |
104 | { | |
105 | /* | |
106 | * We know updates to pc->flags of page cache's stats are from both of | |
107 | * usual context or IRQ context. Disable IRQ to avoid deadlock. | |
108 | */ | |
109 | local_irq_save(*flags); | |
110 | bit_spin_lock(PCG_MOVE_LOCK, &pc->flags); | |
111 | } | |
112 | ||
113 | static inline void move_unlock_page_cgroup(struct page_cgroup *pc, | |
114 | unsigned long *flags) | |
115 | { | |
116 | bit_spin_unlock(PCG_MOVE_LOCK, &pc->flags); | |
117 | local_irq_restore(*flags); | |
118 | } | |
119 | ||
52d4b9ac KH |
120 | #else /* CONFIG_CGROUP_MEM_RES_CTLR */ |
121 | struct page_cgroup; | |
122 | ||
31168481 | 123 | static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat) |
52d4b9ac KH |
124 | { |
125 | } | |
126 | ||
127 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) | |
128 | { | |
129 | return NULL; | |
130 | } | |
94b6da5a KH |
131 | |
132 | static inline void page_cgroup_init(void) | |
133 | { | |
134 | } | |
135 | ||
ca371c0d KH |
136 | static inline void __init page_cgroup_init_flatmem(void) |
137 | { | |
138 | } | |
139 | ||
27a7faa0 KH |
140 | #endif |
141 | ||
27a7faa0 | 142 | #include <linux/swap.h> |
97572751 JSR |
143 | |
144 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP | |
02491447 DN |
145 | extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
146 | unsigned short old, unsigned short new); | |
a3b2d692 KH |
147 | extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id); |
148 | extern unsigned short lookup_swap_cgroup(swp_entry_t ent); | |
27a7faa0 KH |
149 | extern int swap_cgroup_swapon(int type, unsigned long max_pages); |
150 | extern void swap_cgroup_swapoff(int type); | |
151 | #else | |
27a7faa0 KH |
152 | |
153 | static inline | |
a3b2d692 | 154 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
27a7faa0 | 155 | { |
a3b2d692 | 156 | return 0; |
27a7faa0 KH |
157 | } |
158 | ||
159 | static inline | |
a3b2d692 | 160 | unsigned short lookup_swap_cgroup(swp_entry_t ent) |
27a7faa0 | 161 | { |
a3b2d692 | 162 | return 0; |
27a7faa0 KH |
163 | } |
164 | ||
165 | static inline int | |
166 | swap_cgroup_swapon(int type, unsigned long max_pages) | |
167 | { | |
168 | return 0; | |
169 | } | |
170 | ||
171 | static inline void swap_cgroup_swapoff(int type) | |
172 | { | |
173 | return; | |
174 | } | |
175 | ||
52d4b9ac KH |
176 | #endif |
177 | #endif |