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