]> asedeno.scripts.mit.edu Git - linux.git/blob - include/linux/page_cgroup.h
mm: memcontrol: rewrite uncharge API
[linux.git] / include / linux / page_cgroup.h
1 #ifndef __LINUX_PAGE_CGROUP_H
2 #define __LINUX_PAGE_CGROUP_H
3
4 enum {
5         /* flags for mem_cgroup */
6         PCG_USED = 0x01,        /* This page is charged to a memcg */
7         PCG_MEM = 0x02,         /* This page holds a memory charge */
8         PCG_MEMSW = 0x04,       /* This page holds a memory+swap charge */
9         __NR_PCG_FLAGS,
10 };
11
12 #ifndef __GENERATING_BOUNDS_H
13 #include <generated/bounds.h>
14
15 #ifdef CONFIG_MEMCG
16 #include <linux/bit_spinlock.h>
17
18 /*
19  * Page Cgroup can be considered as an extended mem_map.
20  * A page_cgroup page is associated with every page descriptor. The
21  * page_cgroup helps us identify information about the cgroup
22  * All page cgroups are allocated at boot or memory hotplug event,
23  * then the page cgroup for pfn always exists.
24  */
25 struct page_cgroup {
26         unsigned long flags;
27         struct mem_cgroup *mem_cgroup;
28 };
29
30 void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
31
32 #ifdef CONFIG_SPARSEMEM
33 static inline void __init page_cgroup_init_flatmem(void)
34 {
35 }
36 extern void __init page_cgroup_init(void);
37 #else
38 void __init page_cgroup_init_flatmem(void);
39 static inline void __init page_cgroup_init(void)
40 {
41 }
42 #endif
43
44 struct page_cgroup *lookup_page_cgroup(struct page *page);
45 struct page *lookup_cgroup_page(struct page_cgroup *pc);
46
47 static inline int PageCgroupUsed(struct page_cgroup *pc)
48 {
49         return !!(pc->flags & PCG_USED);
50 }
51
52 #else /* CONFIG_MEMCG */
53 struct page_cgroup;
54
55 static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat)
56 {
57 }
58
59 static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
60 {
61         return NULL;
62 }
63
64 static inline void page_cgroup_init(void)
65 {
66 }
67
68 static inline void __init page_cgroup_init_flatmem(void)
69 {
70 }
71
72 #endif /* CONFIG_MEMCG */
73
74 #include <linux/swap.h>
75
76 #ifdef CONFIG_MEMCG_SWAP
77 extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
78                                         unsigned short old, unsigned short new);
79 extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
80 extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
81 extern int swap_cgroup_swapon(int type, unsigned long max_pages);
82 extern void swap_cgroup_swapoff(int type);
83 #else
84
85 static inline
86 unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
87 {
88         return 0;
89 }
90
91 static inline
92 unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
93 {
94         return 0;
95 }
96
97 static inline int
98 swap_cgroup_swapon(int type, unsigned long max_pages)
99 {
100         return 0;
101 }
102
103 static inline void swap_cgroup_swapoff(int type)
104 {
105         return;
106 }
107
108 #endif /* CONFIG_MEMCG_SWAP */
109
110 #endif /* !__GENERATING_BOUNDS_H */
111
112 #endif /* __LINUX_PAGE_CGROUP_H */