]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/page_cgroup.h
be2net: Bug fix to avoid disabling bottom half during firmware upgrade.
[net-next-2.6.git] / include / linux / page_cgroup.h
CommitLineData
52d4b9ac
KH
1#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
31168481 20void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
ca371c0d
KH
21
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
52d4b9ac
KH
34struct 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. */
4b3bde4c 41 PCG_ACCT_LRU, /* page has been accounted for */
8725d541 42 PCG_FILE_MAPPED, /* page is accounted as "mapped" */
52d4b9ac
KH
43};
44
45#define TESTPCGFLAG(uname, lname) \
46static inline int PageCgroup##uname(struct page_cgroup *pc) \
47 { return test_bit(PCG_##lname, &pc->flags); }
48
49#define SETPCGFLAG(uname, lname) \
50static inline void SetPageCgroup##uname(struct page_cgroup *pc)\
51 { set_bit(PCG_##lname, &pc->flags); }
52
53#define CLEARPCGFLAG(uname, lname) \
54static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \
55 { clear_bit(PCG_##lname, &pc->flags); }
56
4b3bde4c
BS
57#define TESTCLEARPCGFLAG(uname, lname) \
58static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \
59 { return test_and_clear_bit(PCG_##lname, &pc->flags); }
60
57f9fd7d
DN
61TESTPCGFLAG(Locked, LOCK)
62
52d4b9ac
KH
63/* Cache flag is set only once (at allocation) */
64TESTPCGFLAG(Cache, CACHE)
4b3bde4c
BS
65CLEARPCGFLAG(Cache, CACHE)
66SETPCGFLAG(Cache, CACHE)
52d4b9ac
KH
67
68TESTPCGFLAG(Used, USED)
69CLEARPCGFLAG(Used, USED)
4b3bde4c
BS
70SETPCGFLAG(Used, USED)
71
72SETPCGFLAG(AcctLRU, ACCT_LRU)
73CLEARPCGFLAG(AcctLRU, ACCT_LRU)
74TESTPCGFLAG(AcctLRU, ACCT_LRU)
75TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU)
52d4b9ac 76
8725d541
KH
77
78SETPCGFLAG(FileMapped, FILE_MAPPED)
79CLEARPCGFLAG(FileMapped, FILE_MAPPED)
80TESTPCGFLAG(FileMapped, FILE_MAPPED)
81
52d4b9ac
KH
82static inline int page_cgroup_nid(struct page_cgroup *pc)
83{
84 return page_to_nid(pc->page);
85}
86
87static inline enum zone_type page_cgroup_zid(struct page_cgroup *pc)
88{
89 return page_zonenum(pc->page);
90}
91
92static inline void lock_page_cgroup(struct page_cgroup *pc)
93{
94 bit_spin_lock(PCG_LOCK, &pc->flags);
95}
96
52d4b9ac
KH
97static inline void unlock_page_cgroup(struct page_cgroup *pc)
98{
99 bit_spin_unlock(PCG_LOCK, &pc->flags);
100}
101
102#else /* CONFIG_CGROUP_MEM_RES_CTLR */
103struct page_cgroup;
104
31168481 105static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
52d4b9ac
KH
106{
107}
108
109static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
110{
111 return NULL;
112}
94b6da5a
KH
113
114static inline void page_cgroup_init(void)
115{
116}
117
ca371c0d
KH
118static inline void __init page_cgroup_init_flatmem(void)
119{
120}
121
27a7faa0
KH
122#endif
123
27a7faa0 124#include <linux/swap.h>
97572751
JSR
125
126#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
02491447
DN
127extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
128 unsigned short old, unsigned short new);
a3b2d692
KH
129extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
130extern unsigned short lookup_swap_cgroup(swp_entry_t ent);
27a7faa0
KH
131extern int swap_cgroup_swapon(int type, unsigned long max_pages);
132extern void swap_cgroup_swapoff(int type);
133#else
27a7faa0
KH
134
135static inline
a3b2d692 136unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
27a7faa0 137{
a3b2d692 138 return 0;
27a7faa0
KH
139}
140
141static inline
a3b2d692 142unsigned short lookup_swap_cgroup(swp_entry_t ent)
27a7faa0 143{
a3b2d692 144 return 0;
27a7faa0
KH
145}
146
147static inline int
148swap_cgroup_swapon(int type, unsigned long max_pages)
149{
150 return 0;
151}
152
153static inline void swap_cgroup_swapoff(int type)
154{
155 return;
156}
157
52d4b9ac
KH
158#endif
159#endif