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 */
42 PCG_FILE_MAPPED
, /* page is accounted as "mapped" */
43 PCG_MIGRATION
, /* under page migration */
46 #define TESTPCGFLAG(uname, lname) \
47 static inline int PageCgroup##uname(struct page_cgroup *pc) \
48 { return test_bit(PCG_##lname, &pc->flags); }
50 #define SETPCGFLAG(uname, lname) \
51 static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
52 { set_bit(PCG_##lname, &pc->flags); }
54 #define CLEARPCGFLAG(uname, lname) \
55 static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
56 { clear_bit(PCG_##lname, &pc->flags); }
58 #define TESTCLEARPCGFLAG(uname, lname) \
59 static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
60 { return test_and_clear_bit(PCG_##lname, &pc->flags); }
62 TESTPCGFLAG(Locked
, LOCK
)
64 /* Cache flag is set only once (at allocation) */
65 TESTPCGFLAG(Cache
, CACHE
)
66 CLEARPCGFLAG(Cache
, CACHE
)
67 SETPCGFLAG(Cache
, CACHE
)
69 TESTPCGFLAG(Used
, USED
)
70 CLEARPCGFLAG(Used
, USED
)
71 SETPCGFLAG(Used
, USED
)
73 SETPCGFLAG(AcctLRU
, ACCT_LRU
)
74 CLEARPCGFLAG(AcctLRU
, ACCT_LRU
)
75 TESTPCGFLAG(AcctLRU
, ACCT_LRU
)
76 TESTCLEARPCGFLAG(AcctLRU
, ACCT_LRU
)
79 SETPCGFLAG(FileMapped
, FILE_MAPPED
)
80 CLEARPCGFLAG(FileMapped
, FILE_MAPPED
)
81 TESTPCGFLAG(FileMapped
, FILE_MAPPED
)
83 SETPCGFLAG(Migration
, MIGRATION
)
84 CLEARPCGFLAG(Migration
, MIGRATION
)
85 TESTPCGFLAG(Migration
, MIGRATION
)
87 static inline int page_cgroup_nid(struct page_cgroup
*pc
)
89 return page_to_nid(pc
->page
);
92 static inline enum zone_type
page_cgroup_zid(struct page_cgroup
*pc
)
94 return page_zonenum(pc
->page
);
97 static inline void lock_page_cgroup(struct page_cgroup
*pc
)
99 bit_spin_lock(PCG_LOCK
, &pc
->flags
);
102 static inline void unlock_page_cgroup(struct page_cgroup
*pc
)
104 bit_spin_unlock(PCG_LOCK
, &pc
->flags
);
107 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
110 static inline void __meminit
pgdat_page_cgroup_init(struct pglist_data
*pgdat
)
114 static inline struct page_cgroup
*lookup_page_cgroup(struct page
*page
)
119 static inline void page_cgroup_init(void)
123 static inline void __init
page_cgroup_init_flatmem(void)
129 #include <linux/swap.h>
131 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
132 extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent
,
133 unsigned short old
, unsigned short new);
134 extern unsigned short swap_cgroup_record(swp_entry_t ent
, unsigned short id
);
135 extern unsigned short lookup_swap_cgroup(swp_entry_t ent
);
136 extern int swap_cgroup_swapon(int type
, unsigned long max_pages
);
137 extern void swap_cgroup_swapoff(int type
);
141 unsigned short swap_cgroup_record(swp_entry_t ent
, unsigned short id
)
147 unsigned short lookup_swap_cgroup(swp_entry_t ent
)
153 swap_cgroup_swapon(int type
, unsigned long max_pages
)
158 static inline void swap_cgroup_swapoff(int type
)