memcg: move charges of anonymous swap
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / page_cgroup.h
CommitLineData
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 */
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
31168481 20void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
ca371c0d
KH
21
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
52d4b9ac
KH
34struct 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. */
4b3bde4c 41 PCG_ACCT_LRU, /* page has been accounted for */
52d4b9ac
KH
42};
43
44#define TESTPCGFLAG(uname, lname) \
45static inline int PageCgroup##uname(struct page_cgroup *pc) \
46 { return test_bit(PCG_##lname, &pc->flags); }
47
48#define SETPCGFLAG(uname, lname) \
49static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
50 { set_bit(PCG_##lname, &pc->flags); }
51
52#define CLEARPCGFLAG(uname, lname) \
53static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
54 { clear_bit(PCG_##lname, &pc->flags); }
55
4b3bde4c
BS
56#define TESTCLEARPCGFLAG(uname, lname) \
57static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
58 { return test_and_clear_bit(PCG_##lname, &pc->flags); }
59
57f9fd7d
DN
60TESTPCGFLAG(Locked, LOCK)
61
52d4b9ac
KH
62/* Cache flag is set only once (at allocation) */
63TESTPCGFLAG(Cache, CACHE)
4b3bde4c
BS
64CLEARPCGFLAG(Cache, CACHE)
65SETPCGFLAG(Cache, CACHE)
52d4b9ac
KH
66
67TESTPCGFLAG(Used, USED)
68CLEARPCGFLAG(Used, USED)
4b3bde4c
BS
69SETPCGFLAG(Used, USED)
70
71SETPCGFLAG(AcctLRU, ACCT_LRU)
72CLEARPCGFLAG(AcctLRU, ACCT_LRU)
73TESTPCGFLAG(AcctLRU, ACCT_LRU)
74TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU)
52d4b9ac 75
52d4b9ac
KH
76static inline int page_cgroup_nid(struct page_cgroup *pc)
77{
78 return page_to_nid(pc->page);
79}
80
81static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
82{
83 return page_zonenum(pc->page);
84}
85
86static inline void lock_page_cgroup(struct page_cgroup *pc)
87{
88 bit_spin_lock(PCG_LOCK, &pc->flags);
89}
90
52d4b9ac
KH
91static inline void unlock_page_cgroup(struct page_cgroup *pc)
92{
93 bit_spin_unlock(PCG_LOCK, &pc->flags);
94}
95
96#else /* CONFIG_CGROUP_MEM_RES_CTLR */
97struct page_cgroup;
98
31168481 99static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
52d4b9ac
KH
100{
101}
102
103static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
104{
105 return NULL;
106}
94b6da5a
KH
107
108static inline void page_cgroup_init(void)
109{
110}
111
ca371c0d
KH
112static inline void __init page_cgroup_init_flatmem(void)
113{
114}
115
27a7faa0
KH
116#endif
117
27a7faa0 118#include <linux/swap.h>
97572751
JSR
119
120#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
02491447
DN
121extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
122 unsigned short old, unsigned short new);
a3b2d692
KH
123extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
124extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
27a7faa0
KH
125extern int swap_cgroup_swapon(int type, unsigned long max_pages);
126extern void swap_cgroup_swapoff(int type);
127#else
27a7faa0
KH
128
129static inline
a3b2d692 130unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
27a7faa0 131{
a3b2d692 132 return 0;
27a7faa0
KH
133}
134
135static inline
a3b2d692 136unsigned short lookup_swap_cgroup(swp_entry_t ent)
27a7faa0 137{
a3b2d692 138 return 0;
27a7faa0
KH
139}
140
141static inline int
142swap_cgroup_swapon(int type, unsigned long max_pages)
143{
144 return 0;
145}
146
147static inline void swap_cgroup_swapoff(int type)
148{
149 return;
150}
151
52d4b9ac
KH
152#endif
153#endif