blob: 4b938d4f3ac2eff57736a6b8ced5a32f0c260d6a [file] [log] [blame]
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -07001#ifndef __LINUX_PAGE_CGROUP_H
2#define __LINUX_PAGE_CGROUP_H
3
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.
12 */
13struct 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 */
18};
19
Al Viro31168482008-11-22 17:33:24 +000020void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
KAMEZAWA Hiroyukica371c02009-06-12 10:33:53 +030021
22#ifdef CONFIG_SPARSEMEM
23static inline void __init page_cgroup_init_flatmem(void)
24{
25}
26extern void __init page_cgroup_init(void);
27#else
28void __init page_cgroup_init_flatmem(void);
29static inline void __init page_cgroup_init(void)
30{
31}
32#endif
33
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070034struct page_cgroup *lookup_page_cgroup(struct page *page);
35
36enum {
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. */
Balbir Singh4b3bde42009-09-23 15:56:32 -070041 PCG_ACCT_LRU, /* page has been accounted for */
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070042};
43
44#define TESTPCGFLAG(uname, lname) \
45static inline int PageCgroup##uname(struct page_cgroup *pc) \
46 { return test_bit(PCG_##lname, &pc->flags); }
47
48#define SETPCGFLAG(uname, lname) \
49static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
50 { set_bit(PCG_##lname, &pc->flags); }
51
52#define CLEARPCGFLAG(uname, lname) \
53static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
54 { clear_bit(PCG_##lname, &pc->flags); }
55
Balbir Singh4b3bde42009-09-23 15:56:32 -070056#define TESTCLEARPCGFLAG(uname, lname) \
57static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
58 { return test_and_clear_bit(PCG_##lname, &pc->flags); }
59
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070060/* Cache flag is set only once (at allocation) */
61TESTPCGFLAG(Cache, CACHE)
Balbir Singh4b3bde42009-09-23 15:56:32 -070062CLEARPCGFLAG(Cache, CACHE)
63SETPCGFLAG(Cache, CACHE)
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070064
65TESTPCGFLAG(Used, USED)
66CLEARPCGFLAG(Used, USED)
Balbir Singh4b3bde42009-09-23 15:56:32 -070067SETPCGFLAG(Used, USED)
68
69SETPCGFLAG(AcctLRU, ACCT_LRU)
70CLEARPCGFLAG(AcctLRU, ACCT_LRU)
71TESTPCGFLAG(AcctLRU, ACCT_LRU)
72TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU)
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070073
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -070074static inline int page_cgroup_nid(struct page_cgroup *pc)
75{
76 return page_to_nid(pc->page);
77}
78
79static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
80{
81 return page_zonenum(pc->page);
82}
83
84static inline void lock_page_cgroup(struct page_cgroup *pc)
85{
86 bit_spin_lock(PCG_LOCK, &pc->flags);
87}
88
89static inline int trylock_page_cgroup(struct page_cgroup *pc)
90{
91 return bit_spin_trylock(PCG_LOCK, &pc->flags);
92}
93
94static inline void unlock_page_cgroup(struct page_cgroup *pc)
95{
96 bit_spin_unlock(PCG_LOCK, &pc->flags);
97}
98
99#else /* CONFIG_CGROUP_MEM_RES_CTLR */
100struct page_cgroup;
101
Al Viro31168482008-11-22 17:33:24 +0000102static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700103{
104}
105
106static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
107{
108 return NULL;
109}
KAMEZAWA Hiroyuki94b6da52008-10-22 14:15:05 -0700110
111static inline void page_cgroup_init(void)
112{
113}
114
KAMEZAWA Hiroyukica371c02009-06-12 10:33:53 +0300115static inline void __init page_cgroup_init_flatmem(void)
116{
117}
118
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700119#endif
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800120
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800121#include <linux/swap.h>
Jaswinder Singh Rajput97572752009-09-20 16:20:44 +0530122
123#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700124extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
125extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800126extern int swap_cgroup_swapon(int type, unsigned long max_pages);
127extern void swap_cgroup_swapoff(int type);
128#else
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800129
130static inline
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700131unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800132{
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700133 return 0;
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800134}
135
136static inline
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700137unsigned short lookup_swap_cgroup(swp_entry_t ent)
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800138{
KAMEZAWA Hiroyukia3b2d692009-04-02 16:57:45 -0700139 return 0;
KAMEZAWA Hiroyuki27a7faa2009-01-07 18:07:58 -0800140}
141
142static inline int
143swap_cgroup_swapon(int type, unsigned long max_pages)
144{
145 return 0;
146}
147
148static inline void swap_cgroup_swapoff(int type)
149{
150 return;
151}
152
153#endif
KAMEZAWA Hiroyuki52d4b9a2008-10-18 20:28:16 -0700154#endif