1 #ifndef __LINUX_PAGE_CGROUP_H
2 #define __LINUX_PAGE_CGROUP_H
5 /* flags for mem_cgroup */
6 PCG_LOCK, /* Lock for pc->mem_cgroup and following bits. */
7 PCG_CACHE, /* charged as cache */
8 PCG_USED, /* this object is in use. */
9 PCG_MIGRATION, /* under page migration */
10 /* flags for mem_cgroup and file and I/O status */
11 PCG_MOVE_LOCK, /* For race between move_account v.s. following bits */
12 PCG_FILE_MAPPED, /* page is accounted as "mapped" */
13 /* No lock in page_cgroup */
14 PCG_ACCT_LRU, /* page has been accounted for (under lru_lock) */
18 #ifndef __GENERATING_BOUNDS_H
19 #include <generated/bounds.h>
21 #ifdef CONFIG_CGROUP_MEM_RES_CTLR
22 #include <linux/bit_spinlock.h>
25 * Page Cgroup can be considered as an extended mem_map.
26 * A page_cgroup page is associated with every page descriptor. The
27 * page_cgroup helps us identify information about the cgroup
28 * All page cgroups are allocated at boot or memory hotplug event,
29 * then the page cgroup for pfn always exists.
33 struct mem_cgroup *mem_cgroup;
36 void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
38 #ifdef CONFIG_SPARSEMEM
39 static inline void __init page_cgroup_init_flatmem(void)
42 extern void __init page_cgroup_init(void);
44 void __init page_cgroup_init_flatmem(void);
45 static inline void __init page_cgroup_init(void)
50 struct page_cgroup *lookup_page_cgroup(struct page *page);
51 struct page *lookup_cgroup_page(struct page_cgroup *pc);
53 #define TESTPCGFLAG(uname, lname) \
54 static inline int PageCgroup##uname(struct page_cgroup *pc) \
55 { return test_bit(PCG_##lname, &pc->flags); }
57 #define SETPCGFLAG(uname, lname) \
58 static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
59 { set_bit(PCG_##lname, &pc->flags); }
61 #define CLEARPCGFLAG(uname, lname) \
62 static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
63 { clear_bit(PCG_##lname, &pc->flags); }
65 #define TESTCLEARPCGFLAG(uname, lname) \
66 static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
67 { return test_and_clear_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(Migration, MIGRATION)
89 CLEARPCGFLAG(Migration, MIGRATION)
90 TESTPCGFLAG(Migration, MIGRATION)
92 static inline void lock_page_cgroup(struct page_cgroup *pc)
95 * Don't take this lock in IRQ context.
96 * This lock is for pc->mem_cgroup, USED, CACHE, MIGRATION
98 bit_spin_lock(PCG_LOCK, &pc->flags);
101 static inline void unlock_page_cgroup(struct page_cgroup *pc)
103 bit_spin_unlock(PCG_LOCK, &pc->flags);
106 static inline void move_lock_page_cgroup(struct page_cgroup *pc,
107 unsigned long *flags)
110 * We know updates to pc->flags of page cache's stats are from both of
111 * usual context or IRQ context. Disable IRQ to avoid deadlock.
113 local_irq_save(*flags);
114 bit_spin_lock(PCG_MOVE_LOCK, &pc->flags);
117 static inline void move_unlock_page_cgroup(struct page_cgroup *pc,
118 unsigned long *flags)
120 bit_spin_unlock(PCG_MOVE_LOCK, &pc->flags);
121 local_irq_restore(*flags);
124 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
127 static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
131 static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
136 static inline void page_cgroup_init(void)
140 static inline void __init page_cgroup_init_flatmem(void)
144 #endif /* CONFIG_CGROUP_MEM_RES_CTLR */
146 #include <linux/swap.h>
148 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
149 extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
150 unsigned short old, unsigned short new);
151 extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
152 extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
153 extern int swap_cgroup_swapon(int type, unsigned long max_pages);
154 extern void swap_cgroup_swapoff(int type);
158 unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
164 unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
170 swap_cgroup_swapon(int type, unsigned long max_pages)
175 static inline void swap_cgroup_swapoff(int type)
180 #endif /* CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
182 #endif /* !__GENERATING_BOUNDS_H */
184 #endif /* __LINUX_PAGE_CGROUP_H */