Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
page_cgroup.h
Go to the documentation of this file.
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_USED, /* this object is in use. */
8  PCG_MIGRATION, /* under page migration */
10 };
11 
12 #ifndef __GENERATING_BOUNDS_H
13 #include <generated/bounds.h>
14 
15 #ifdef CONFIG_MEMCG
16 #include <linux/bit_spinlock.h>
17 
18 /*
19  * Page Cgroup can be considered as an extended mem_map.
20  * A page_cgroup page is associated with every page descriptor. The
21  * page_cgroup helps us identify information about the cgroup
22  * All page cgroups are allocated at boot or memory hotplug event,
23  * then the page cgroup for pfn always exists.
24  */
25 struct page_cgroup {
26  unsigned long flags;
27  struct mem_cgroup *mem_cgroup;
28 };
29 
30 void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
31 
32 #ifdef CONFIG_SPARSEMEM
33 static inline void __init page_cgroup_init_flatmem(void)
34 {
35 }
36 extern void __init page_cgroup_init(void);
37 #else
39 static inline void __init page_cgroup_init(void)
40 {
41 }
42 #endif
43 
44 struct page_cgroup *lookup_page_cgroup(struct page *page);
45 struct page *lookup_cgroup_page(struct page_cgroup *pc);
46 
47 #define TESTPCGFLAG(uname, lname) \
48 static inline int PageCgroup##uname(struct page_cgroup *pc) \
49  { return test_bit(PCG_##lname, &pc->flags); }
50 
51 #define SETPCGFLAG(uname, lname) \
52 static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
53  { set_bit(PCG_##lname, &pc->flags); }
54 
55 #define CLEARPCGFLAG(uname, lname) \
56 static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
57  { clear_bit(PCG_##lname, &pc->flags); }
58 
59 #define TESTCLEARPCGFLAG(uname, lname) \
60 static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
61  { return test_and_clear_bit(PCG_##lname, &pc->flags); }
62 
63 TESTPCGFLAG(Used, USED)
64 CLEARPCGFLAG(Used, USED)
65 SETPCGFLAG(Used, USED)
66 
67 SETPCGFLAG(Migration, MIGRATION)
68 CLEARPCGFLAG(Migration, MIGRATION)
69 TESTPCGFLAG(Migration, MIGRATION)
70 
71 static inline void lock_page_cgroup(struct page_cgroup *pc)
72 {
73  /*
74  * Don't take this lock in IRQ context.
75  * This lock is for pc->mem_cgroup, USED, MIGRATION
76  */
77  bit_spin_lock(PCG_LOCK, &pc->flags);
78 }
79 
80 static inline void unlock_page_cgroup(struct page_cgroup *pc)
81 {
82  bit_spin_unlock(PCG_LOCK, &pc->flags);
83 }
84 
85 #else /* CONFIG_MEMCG */
86 struct page_cgroup;
87 
88 static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
89 {
90 }
91 
92 static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
93 {
94  return NULL;
95 }
96 
97 static inline void page_cgroup_init(void)
98 {
99 }
100 
101 static inline void __init page_cgroup_init_flatmem(void)
102 {
103 }
104 
105 #endif /* CONFIG_MEMCG */
106 
107 #include <linux/swap.h>
108 
109 #ifdef CONFIG_MEMCG_SWAP
110 extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
111  unsigned short old, unsigned short new);
112 extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
113 extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
114 extern int swap_cgroup_swapon(int type, unsigned long max_pages);
115 extern void swap_cgroup_swapoff(int type);
116 #else
117 
118 static inline
119 unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
120 {
121  return 0;
122 }
123 
124 static inline
125 unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
126 {
127  return 0;
128 }
129 
130 static inline int
131 swap_cgroup_swapon(int type, unsigned long max_pages)
132 {
133  return 0;
134 }
135 
136 static inline void swap_cgroup_swapoff(int type)
137 {
138  return;
139 }
140 
141 #endif /* CONFIG_MEMCG_SWAP */
142 
143 #endif /* !__GENERATING_BOUNDS_H */
144 
145 #endif /* __LINUX_PAGE_CGROUP_H */