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
, /* 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 */
44 #define TESTPCGFLAG(uname, lname) \
45 static inline int PageCgroup##uname(struct page_cgroup *pc) \
46 { return test_bit(PCG_##lname, &pc->flags); }
48 #define SETPCGFLAG(uname, lname) \
49 static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
50 { set_bit(PCG_##lname, &pc->flags); }
52 #define CLEARPCGFLAG(uname, lname) \
53 static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
54 { clear_bit(PCG_##lname, &pc->flags); }
56 #define TESTCLEARPCGFLAG(uname, lname) \
57 static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
58 { return test_and_clear_bit(PCG_##lname, &pc->flags); }
60 TESTPCGFLAG(Locked
, LOCK
)
62 /* Cache flag is set only once (at allocation) */
63 TESTPCGFLAG(Cache
, CACHE
)
64 CLEARPCGFLAG(Cache
, CACHE
)
65 SETPCGFLAG(Cache
, CACHE
)
67 TESTPCGFLAG(Used
, USED
)
68 CLEARPCGFLAG(Used
, USED
)
69 SETPCGFLAG(Used
, USED
)
71 SETPCGFLAG(AcctLRU
, ACCT_LRU
)
72 CLEARPCGFLAG(AcctLRU
, ACCT_LRU
)
73 TESTPCGFLAG(AcctLRU
, ACCT_LRU
)
74 TESTCLEARPCGFLAG(AcctLRU
, ACCT_LRU
)
76 static inline int page_cgroup_nid(struct page_cgroup
*pc
)
78 return page_to_nid(pc
->page
);
81 static inline enum zone_type
page_cgroup_zid(struct page_cgroup
*pc
)
83 return page_zonenum(pc
->page
);
86 static inline void lock_page_cgroup(struct page_cgroup
*pc
)
88 bit_spin_lock(PCG_LOCK
, &pc
->flags
);
91 static inline void unlock_page_cgroup(struct page_cgroup
*pc
)
93 bit_spin_unlock(PCG_LOCK
, &pc
->flags
);
96 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
99 static inline void __meminit
pgdat_page_cgroup_init(struct pglist_data
*pgdat
)
103 static inline struct page_cgroup
*lookup_page_cgroup(struct page
*page
)
108 static inline void page_cgroup_init(void)
112 static inline void __init
page_cgroup_init_flatmem(void)
118 #include <linux/swap.h>
120 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
121 extern unsigned short swap_cgroup_record(swp_entry_t ent
, unsigned short id
);
122 extern unsigned short lookup_swap_cgroup(swp_entry_t ent
);
123 extern int swap_cgroup_swapon(int type
, unsigned long max_pages
);
124 extern void swap_cgroup_swapoff(int type
);
128 unsigned short swap_cgroup_record(swp_entry_t ent
, unsigned short id
)
134 unsigned short lookup_swap_cgroup(swp_entry_t ent
)
140 swap_cgroup_swapon(int type
, unsigned long max_pages
)
145 static inline void swap_cgroup_swapoff(int type
)