Linux 2.6.31.10
[linux-2.6/mini2440.git] / include / linux / page_cgroup.h
blob13f126c89ae8f1e5e35355eff8b94e1c9095906e
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. */
43 #define TESTPCGFLAG(uname, lname) \
44 static inline int PageCgroup##uname(struct page_cgroup *pc) \
45 { return test_bit(PCG_##lname, &pc->flags); }
47 #define SETPCGFLAG(uname, lname) \
48 static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
49 { set_bit(PCG_##lname, &pc->flags); }
51 #define CLEARPCGFLAG(uname, lname) \
52 static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
53 { clear_bit(PCG_##lname, &pc->flags); }
55 /* Cache flag is set only once (at allocation) */
56 TESTPCGFLAG(Cache, CACHE)
58 TESTPCGFLAG(Used, USED)
59 CLEARPCGFLAG(Used, USED)
61 static inline int page_cgroup_nid(struct page_cgroup *pc)
63 return page_to_nid(pc->page);
66 static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
68 return page_zonenum(pc->page);
71 static inline void lock_page_cgroup(struct page_cgroup *pc)
73 bit_spin_lock(PCG_LOCK, &pc->flags);
76 static inline int trylock_page_cgroup(struct page_cgroup *pc)
78 return bit_spin_trylock(PCG_LOCK, &pc->flags);
81 static inline void unlock_page_cgroup(struct page_cgroup *pc)
83 bit_spin_unlock(PCG_LOCK, &pc->flags);
86 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
87 struct page_cgroup;
89 static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
93 static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
95 return NULL;
98 static inline void page_cgroup_init(void)
102 static inline void __init page_cgroup_init_flatmem(void)
106 #endif
108 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
109 #include <linux/swap.h>
110 extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
111 extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
112 extern int swap_cgroup_swapon(int type, unsigned long max_pages);
113 extern void swap_cgroup_swapoff(int type);
114 #else
115 #include <linux/swap.h>
117 static inline
118 unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
120 return 0;
123 static inline
124 unsigned short lookup_swap_cgroup(swp_entry_t ent)
126 return 0;
129 static inline int
130 swap_cgroup_swapon(int type, unsigned long max_pages)
132 return 0;
135 static inline void swap_cgroup_swapoff(int type)
137 return;
140 #endif
141 #endif