Commit | Line | Data |
---|---|---|
52d4b9ac KH |
1 | #ifndef __LINUX_PAGE_CGROUP_H |
2 | #define __LINUX_PAGE_CGROUP_H | |
3 | ||
6b3ae58e JW |
4 | enum { |
5 | /* flags for mem_cgroup */ | |
0a31bc97 JW |
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 */ | |
6b3ae58e JW |
9 | }; |
10 | ||
434584fe VD |
11 | struct pglist_data; |
12 | ||
c255a458 | 13 | #ifdef CONFIG_MEMCG |
434584fe | 14 | struct mem_cgroup; |
6b3ae58e | 15 | |
52d4b9ac KH |
16 | /* |
17 | * Page Cgroup can be considered as an extended mem_map. | |
18 | * A page_cgroup page is associated with every page descriptor. The | |
19 | * page_cgroup helps us identify information about the cgroup | |
20 | * All page cgroups are allocated at boot or memory hotplug event, | |
21 | * then the page cgroup for pfn always exists. | |
22 | */ | |
23 | struct page_cgroup { | |
24 | unsigned long flags; | |
25 | struct mem_cgroup *mem_cgroup; | |
52d4b9ac KH |
26 | }; |
27 | ||
434584fe | 28 | extern void pgdat_page_cgroup_init(struct pglist_data *pgdat); |
ca371c0d KH |
29 | |
30 | #ifdef CONFIG_SPARSEMEM | |
434584fe | 31 | static inline void page_cgroup_init_flatmem(void) |
ca371c0d KH |
32 | { |
33 | } | |
434584fe | 34 | extern void page_cgroup_init(void); |
ca371c0d | 35 | #else |
434584fe VD |
36 | extern void page_cgroup_init_flatmem(void); |
37 | static inline void page_cgroup_init(void) | |
ca371c0d KH |
38 | { |
39 | } | |
40 | #endif | |
41 | ||
52d4b9ac | 42 | struct page_cgroup *lookup_page_cgroup(struct page *page); |
52d4b9ac | 43 | |
0a31bc97 | 44 | static inline int PageCgroupUsed(struct page_cgroup *pc) |
52d4b9ac | 45 | { |
0a31bc97 | 46 | return !!(pc->flags & PCG_USED); |
52d4b9ac | 47 | } |
434584fe | 48 | #else /* !CONFIG_MEMCG */ |
52d4b9ac KH |
49 | struct page_cgroup; |
50 | ||
434584fe | 51 | static inline void pgdat_page_cgroup_init(struct pglist_data *pgdat) |
52d4b9ac KH |
52 | { |
53 | } | |
54 | ||
55 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) | |
56 | { | |
57 | return NULL; | |
58 | } | |
94b6da5a KH |
59 | |
60 | static inline void page_cgroup_init(void) | |
61 | { | |
62 | } | |
63 | ||
434584fe | 64 | static inline void page_cgroup_init_flatmem(void) |
ca371c0d KH |
65 | { |
66 | } | |
c255a458 | 67 | #endif /* CONFIG_MEMCG */ |
27a7faa0 | 68 | |
27a7faa0 | 69 | #include <linux/swap.h> |
97572751 | 70 | |
c255a458 | 71 | #ifdef CONFIG_MEMCG_SWAP |
02491447 DN |
72 | extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
73 | unsigned short old, unsigned short new); | |
a3b2d692 | 74 | extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id); |
9fb4b7cc | 75 | extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent); |
27a7faa0 KH |
76 | extern int swap_cgroup_swapon(int type, unsigned long max_pages); |
77 | extern void swap_cgroup_swapoff(int type); | |
78 | #else | |
27a7faa0 KH |
79 | |
80 | static inline | |
a3b2d692 | 81 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
27a7faa0 | 82 | { |
a3b2d692 | 83 | return 0; |
27a7faa0 KH |
84 | } |
85 | ||
86 | static inline | |
9fb4b7cc | 87 | unsigned short lookup_swap_cgroup_id(swp_entry_t ent) |
27a7faa0 | 88 | { |
a3b2d692 | 89 | return 0; |
27a7faa0 KH |
90 | } |
91 | ||
92 | static inline int | |
93 | swap_cgroup_swapon(int type, unsigned long max_pages) | |
94 | { | |
95 | return 0; | |
96 | } | |
97 | ||
98 | static inline void swap_cgroup_swapoff(int type) | |
99 | { | |
100 | return; | |
101 | } | |
102 | ||
c255a458 | 103 | #endif /* CONFIG_MEMCG_SWAP */ |
6b3ae58e | 104 | |
6b3ae58e | 105 | #endif /* __LINUX_PAGE_CGROUP_H */ |