Merge tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[linux-2.6.git] / include / linux / page_cgroup.h
blob777a524716db9364d3f9a06f9357cacf36b2b418
1 #ifndef __LINUX_PAGE_CGROUP_H
2 #define __LINUX_PAGE_CGROUP_H
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 */
9 __NR_PCG_FLAGS,
12 #ifndef __GENERATING_BOUNDS_H
13 #include <generated/bounds.h>
15 #ifdef CONFIG_MEMCG
16 #include <linux/bit_spinlock.h>
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.
25 struct page_cgroup {
26 unsigned long flags;
27 struct mem_cgroup *mem_cgroup;
30 void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
32 #ifdef CONFIG_SPARSEMEM
33 static inline void __init page_cgroup_init_flatmem(void)
36 extern void __init page_cgroup_init(void);
37 #else
38 void __init page_cgroup_init_flatmem(void);
39 static inline void __init page_cgroup_init(void)
42 #endif
44 struct page_cgroup *lookup_page_cgroup(struct page *page);
45 struct page *lookup_cgroup_page(struct page_cgroup *pc);
47 #define TESTPCGFLAG(uname, lname) \
48 static inline int PageCgroup##uname(struct page_cgroup *pc) \
49 { return test_bit(PCG_##lname, &pc->flags); }
51 #define SETPCGFLAG(uname, lname) \
52 static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
53 { set_bit(PCG_##lname, &pc->flags); }
55 #define CLEARPCGFLAG(uname, lname) \
56 static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
57 { clear_bit(PCG_##lname, &pc->flags); }
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); }
63 TESTPCGFLAG(Used, USED)
64 CLEARPCGFLAG(Used, USED)
65 SETPCGFLAG(Used, USED)
67 SETPCGFLAG(Migration, MIGRATION)
68 CLEARPCGFLAG(Migration, MIGRATION)
69 TESTPCGFLAG(Migration, MIGRATION)
71 static inline void lock_page_cgroup(struct page_cgroup *pc)
74 * Don't take this lock in IRQ context.
75 * This lock is for pc->mem_cgroup, USED, MIGRATION
77 bit_spin_lock(PCG_LOCK, &pc->flags);
80 static inline void unlock_page_cgroup(struct page_cgroup *pc)
82 bit_spin_unlock(PCG_LOCK, &pc->flags);
85 #else /* CONFIG_MEMCG */
86 struct page_cgroup;
88 static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
92 static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
94 return NULL;
97 static inline void page_cgroup_init(void)
101 static inline void __init page_cgroup_init_flatmem(void)
105 #endif /* CONFIG_MEMCG */
107 #include <linux/swap.h>
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
118 static inline
119 unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
121 return 0;
124 static inline
125 unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
127 return 0;
130 static inline int
131 swap_cgroup_swapon(int type, unsigned long max_pages)
133 return 0;
136 static inline void swap_cgroup_swapoff(int type)
138 return;
141 #endif /* CONFIG_MEMCG_SWAP */
143 #endif /* !__GENERATING_BOUNDS_H */
145 #endif /* __LINUX_PAGE_CGROUP_H */