memcg: add page_cgroup flags for dirty page tracking
[linux-2.6/cjktty.git] / include / linux / page_cgroup.h
blobfdb5a92b5ac78fc56babf6875012d5edde38a151
1 #ifndef __LINUX_PAGE_CGROUP_H
2 #define __LINUX_PAGE_CGROUP_H
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.
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 */
20 void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
22 #ifdef CONFIG_SPARSEMEM
23 static inline void __init page_cgroup_init_flatmem(void)
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)
32 #endif
34 struct page_cgroup *lookup_page_cgroup(struct page *page);
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. */
41 PCG_ACCT_LRU, /* page has been accounted for */
42 PCG_FILE_MAPPED, /* page is accounted as "mapped" */
43 PCG_FILE_DIRTY, /* page is dirty */
44 PCG_FILE_WRITEBACK, /* page is under writeback */
45 PCG_FILE_UNSTABLE_NFS, /* page is NFS unstable */
46 PCG_MIGRATION, /* under page migration */
49 #define TESTPCGFLAG(uname, lname) \
50 static inline int PageCgroup##uname(struct page_cgroup *pc) \
51 { return test_bit(PCG_##lname, &pc->flags); }
53 #define SETPCGFLAG(uname, lname) \
54 static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
55 { set_bit(PCG_##lname, &pc->flags); }
57 #define CLEARPCGFLAG(uname, lname) \
58 static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
59 { clear_bit(PCG_##lname, &pc->flags); }
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); }
65 #define TESTSETPCGFLAG(uname, lname) \
66 static inline int TestSetPageCgroup##uname(struct page_cgroup *pc) \
67 { return test_and_set_bit(PCG_##lname, &pc->flags); }
69 /* Cache flag is set only once (at allocation) */
70 TESTPCGFLAG(Cache, CACHE)
71 CLEARPCGFLAG(Cache, CACHE)
72 SETPCGFLAG(Cache, CACHE)
74 TESTPCGFLAG(Used, USED)
75 CLEARPCGFLAG(Used, USED)
76 SETPCGFLAG(Used, USED)
78 SETPCGFLAG(AcctLRU, ACCT_LRU)
79 CLEARPCGFLAG(AcctLRU, ACCT_LRU)
80 TESTPCGFLAG(AcctLRU, ACCT_LRU)
81 TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU)
84 SETPCGFLAG(FileMapped, FILE_MAPPED)
85 CLEARPCGFLAG(FileMapped, FILE_MAPPED)
86 TESTPCGFLAG(FileMapped, FILE_MAPPED)
88 SETPCGFLAG(FileDirty, FILE_DIRTY)
89 CLEARPCGFLAG(FileDirty, FILE_DIRTY)
90 TESTPCGFLAG(FileDirty, FILE_DIRTY)
91 TESTCLEARPCGFLAG(FileDirty, FILE_DIRTY)
92 TESTSETPCGFLAG(FileDirty, FILE_DIRTY)
94 SETPCGFLAG(FileWriteback, FILE_WRITEBACK)
95 CLEARPCGFLAG(FileWriteback, FILE_WRITEBACK)
96 TESTPCGFLAG(FileWriteback, FILE_WRITEBACK)
98 SETPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS)
99 CLEARPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS)
100 TESTPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS)
101 TESTCLEARPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS)
102 TESTSETPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS)
104 SETPCGFLAG(Migration, MIGRATION)
105 CLEARPCGFLAG(Migration, MIGRATION)
106 TESTPCGFLAG(Migration, MIGRATION)
108 static inline int page_cgroup_nid(struct page_cgroup *pc)
110 return page_to_nid(pc->page);
113 static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
115 return page_zonenum(pc->page);
118 static inline void lock_page_cgroup(struct page_cgroup *pc)
120 bit_spin_lock(PCG_LOCK, &pc->flags);
123 static inline void unlock_page_cgroup(struct page_cgroup *pc)
125 bit_spin_unlock(PCG_LOCK, &pc->flags);
128 static inline int page_is_cgroup_locked(struct page_cgroup *pc)
130 return bit_spin_is_locked(PCG_LOCK, &pc->flags);
133 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
134 struct page_cgroup;
136 static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
140 static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
142 return NULL;
145 static inline void page_cgroup_init(void)
149 static inline void __init page_cgroup_init_flatmem(void)
153 #endif
155 #include <linux/swap.h>
157 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
158 extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
159 unsigned short old, unsigned short new);
160 extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
161 extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
162 extern int swap_cgroup_swapon(int type, unsigned long max_pages);
163 extern void swap_cgroup_swapoff(int type);
164 #else
166 static inline
167 unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
169 return 0;
172 static inline
173 unsigned short lookup_swap_cgroup(swp_entry_t ent)
175 return 0;
178 static inline int
179 swap_cgroup_swapon(int type, unsigned long max_pages)
181 return 0;
184 static inline void swap_cgroup_swapoff(int type)
186 return;
189 #endif
190 #endif