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>
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.
15 struct mem_cgroup
*mem_cgroup
;
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);
28 void __init
page_cgroup_init_flatmem(void);
29 static inline void __init
page_cgroup_init(void)
34 struct page_cgroup
*lookup_page_cgroup(struct page
*page
);
37 /* flags for mem_cgroup */
38 PCG_LOCK
, /* Lock for pc->mem_cgroup and following bits. */
39 PCG_CACHE
, /* charged as cache */
40 PCG_USED
, /* this object is in use. */
41 PCG_MIGRATION
, /* under page migration */
42 /* flags for mem_cgroup and file and I/O status */
43 PCG_MOVE_LOCK
, /* For race between move_account v.s. following bits */
44 PCG_FILE_MAPPED
, /* page is accounted as "mapped" */
45 PCG_FILE_DIRTY
, /* page is dirty */
46 PCG_FILE_WRITEBACK
, /* page is under writeback */
47 PCG_FILE_UNSTABLE_NFS
, /* page is NFS unstable */
48 /* No lock in page_cgroup */
49 PCG_ACCT_LRU
, /* page has been accounted for (under lru_lock) */
52 #define TESTPCGFLAG(uname, lname) \
53 static inline int PageCgroup##uname(struct page_cgroup *pc) \
54 { return test_bit(PCG_##lname, &pc->flags); }
56 #define SETPCGFLAG(uname, lname) \
57 static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
58 { set_bit(PCG_##lname, &pc->flags); }
60 #define CLEARPCGFLAG(uname, lname) \
61 static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
62 { clear_bit(PCG_##lname, &pc->flags); }
64 #define TESTCLEARPCGFLAG(uname, lname) \
65 static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
66 { return test_and_clear_bit(PCG_##lname, &pc->flags); }
68 #define TESTSETPCGFLAG(uname, lname) \
69 static inline int TestSetPageCgroup##uname(struct page_cgroup *pc) \
70 { return test_and_set_bit(PCG_##lname, &pc->flags); }
72 /* Cache flag is set only once (at allocation) */
73 TESTPCGFLAG(Cache
, CACHE
)
74 CLEARPCGFLAG(Cache
, CACHE
)
75 SETPCGFLAG(Cache
, CACHE
)
77 TESTPCGFLAG(Used
, USED
)
78 CLEARPCGFLAG(Used
, USED
)
79 SETPCGFLAG(Used
, USED
)
81 SETPCGFLAG(AcctLRU
, ACCT_LRU
)
82 CLEARPCGFLAG(AcctLRU
, ACCT_LRU
)
83 TESTPCGFLAG(AcctLRU
, ACCT_LRU
)
84 TESTCLEARPCGFLAG(AcctLRU
, ACCT_LRU
)
87 SETPCGFLAG(FileMapped
, FILE_MAPPED
)
88 CLEARPCGFLAG(FileMapped
, FILE_MAPPED
)
89 TESTPCGFLAG(FileMapped
, FILE_MAPPED
)
91 SETPCGFLAG(FileDirty
, FILE_DIRTY
)
92 CLEARPCGFLAG(FileDirty
, FILE_DIRTY
)
93 TESTPCGFLAG(FileDirty
, FILE_DIRTY
)
94 TESTCLEARPCGFLAG(FileDirty
, FILE_DIRTY
)
95 TESTSETPCGFLAG(FileDirty
, FILE_DIRTY
)
97 SETPCGFLAG(FileWriteback
, FILE_WRITEBACK
)
98 CLEARPCGFLAG(FileWriteback
, FILE_WRITEBACK
)
99 TESTPCGFLAG(FileWriteback
, FILE_WRITEBACK
)
101 SETPCGFLAG(FileUnstableNFS
, FILE_UNSTABLE_NFS
)
102 CLEARPCGFLAG(FileUnstableNFS
, FILE_UNSTABLE_NFS
)
103 TESTPCGFLAG(FileUnstableNFS
, FILE_UNSTABLE_NFS
)
104 TESTCLEARPCGFLAG(FileUnstableNFS
, FILE_UNSTABLE_NFS
)
105 TESTSETPCGFLAG(FileUnstableNFS
, FILE_UNSTABLE_NFS
)
107 SETPCGFLAG(Migration
, MIGRATION
)
108 CLEARPCGFLAG(Migration
, MIGRATION
)
109 TESTPCGFLAG(Migration
, MIGRATION
)
111 static inline int page_cgroup_nid(struct page_cgroup
*pc
)
113 return page_to_nid(pc
->page
);
116 static inline enum zone_type
page_cgroup_zid(struct page_cgroup
*pc
)
118 return page_zonenum(pc
->page
);
121 static inline void lock_page_cgroup(struct page_cgroup
*pc
)
124 * Don't take this lock in IRQ context.
125 * This lock is for pc->mem_cgroup, USED, CACHE, MIGRATION
127 bit_spin_lock(PCG_LOCK
, &pc
->flags
);
130 static inline void unlock_page_cgroup(struct page_cgroup
*pc
)
132 bit_spin_unlock(PCG_LOCK
, &pc
->flags
);
135 static inline int page_is_cgroup_locked(struct page_cgroup
*pc
)
137 return bit_spin_is_locked(PCG_LOCK
, &pc
->flags
);
140 static inline void move_lock_page_cgroup(struct page_cgroup
*pc
,
141 unsigned long *flags
)
144 * We know updates to pc->flags of page cache's stats are from both of
145 * usual context or IRQ context. Disable IRQ to avoid deadlock.
147 local_irq_save(*flags
);
148 bit_spin_lock(PCG_MOVE_LOCK
, &pc
->flags
);
151 static inline void move_unlock_page_cgroup(struct page_cgroup
*pc
,
152 unsigned long *flags
)
154 bit_spin_unlock(PCG_MOVE_LOCK
, &pc
->flags
);
155 local_irq_restore(*flags
);
158 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
161 static inline void __meminit
pgdat_page_cgroup_init(struct pglist_data
*pgdat
)
165 static inline struct page_cgroup
*lookup_page_cgroup(struct page
*page
)
170 static inline void page_cgroup_init(void)
174 static inline void __init
page_cgroup_init_flatmem(void)
180 #include <linux/swap.h>
182 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
183 extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent
,
184 unsigned short old
, unsigned short new);
185 extern unsigned short swap_cgroup_record(swp_entry_t ent
, unsigned short id
);
186 extern unsigned short lookup_swap_cgroup(swp_entry_t ent
);
187 extern int swap_cgroup_swapon(int type
, unsigned long max_pages
);
188 extern void swap_cgroup_swapoff(int type
);
192 unsigned short swap_cgroup_record(swp_entry_t ent
, unsigned short id
)
198 unsigned short lookup_swap_cgroup(swp_entry_t ent
)
204 swap_cgroup_swapon(int type
, unsigned long max_pages
)
209 static inline void swap_cgroup_swapoff(int type
)