mm: memcg: remove unused node/section info from pc->flags
[platform/adaptation/renesas_rcar/renesas_kernel.git] / include / linux / page_cgroup.h
1 #ifndef __LINUX_PAGE_CGROUP_H
2 #define __LINUX_PAGE_CGROUP_H
3
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
21 #ifdef CONFIG_CGROUP_MEM_RES_CTLR
22 #include <linux/bit_spinlock.h>
23
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;
34 };
35
36 void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
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
50 struct page_cgroup *lookup_page_cgroup(struct page *page);
51 struct page *lookup_cgroup_page(struct page_cgroup *pc);
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
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
69 /* Cache flag is set only once (at allocation) */
70 TESTPCGFLAG(Cache, CACHE)
71 CLEARPCGFLAG(Cache, CACHE)
72 SETPCGFLAG(Cache, CACHE)
73
74 TESTPCGFLAG(Used, USED)
75 CLEARPCGFLAG(Used, USED)
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)
82
83
84 SETPCGFLAG(FileMapped, FILE_MAPPED)
85 CLEARPCGFLAG(FileMapped, FILE_MAPPED)
86 TESTPCGFLAG(FileMapped, FILE_MAPPED)
87
88 SETPCGFLAG(Migration, MIGRATION)
89 CLEARPCGFLAG(Migration, MIGRATION)
90 TESTPCGFLAG(Migration, MIGRATION)
91
92 static inline void lock_page_cgroup(struct page_cgroup *pc)
93 {
94         /*
95          * Don't take this lock in IRQ context.
96          * This lock is for pc->mem_cgroup, USED, CACHE, MIGRATION
97          */
98         bit_spin_lock(PCG_LOCK, &pc->flags);
99 }
100
101 static inline void unlock_page_cgroup(struct page_cgroup *pc)
102 {
103         bit_spin_unlock(PCG_LOCK, &pc->flags);
104 }
105
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
124 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
125 struct page_cgroup;
126
127 static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
128 {
129 }
130
131 static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
132 {
133         return NULL;
134 }
135
136 static inline void page_cgroup_init(void)
137 {
138 }
139
140 static inline void __init page_cgroup_init_flatmem(void)
141 {
142 }
143
144 #endif /* CONFIG_CGROUP_MEM_RES_CTLR */
145
146 #include <linux/swap.h>
147
148 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
149 extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
150                                         unsigned short old, unsigned short new);
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);
153 extern int swap_cgroup_swapon(int type, unsigned long max_pages);
154 extern void swap_cgroup_swapoff(int type);
155 #else
156
157 static inline
158 unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
159 {
160         return 0;
161 }
162
163 static inline
164 unsigned short lookup_swap_cgroup(swp_entry_t ent)
165 {
166         return 0;
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
180 #endif /* CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
181
182 #endif /* !__GENERATING_BOUNDS_H */
183
184 #endif /* __LINUX_PAGE_CGROUP_H */