]>
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 | __NR_PCG_FLAGS, |
10 | }; | |
11 | ||
12 | #ifndef __GENERATING_BOUNDS_H | |
13 | #include <generated/bounds.h> | |
14 | ||
c255a458 | 15 | #ifdef CONFIG_MEMCG |
52d4b9ac | 16 | #include <linux/bit_spinlock.h> |
6b3ae58e | 17 | |
52d4b9ac KH |
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; | |
52d4b9ac KH |
28 | }; |
29 | ||
31168481 | 30 | void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat); |
ca371c0d KH |
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 | ||
52d4b9ac | 44 | struct page_cgroup *lookup_page_cgroup(struct page *page); |
6b3ae58e | 45 | struct page *lookup_cgroup_page(struct page_cgroup *pc); |
52d4b9ac | 46 | |
0a31bc97 | 47 | static inline int PageCgroupUsed(struct page_cgroup *pc) |
52d4b9ac | 48 | { |
0a31bc97 | 49 | return !!(pc->flags & PCG_USED); |
52d4b9ac KH |
50 | } |
51 | ||
c255a458 | 52 | #else /* CONFIG_MEMCG */ |
52d4b9ac KH |
53 | struct page_cgroup; |
54 | ||
31168481 | 55 | static inline void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat) |
52d4b9ac KH |
56 | { |
57 | } | |
58 | ||
59 | static inline struct page_cgroup *lookup_page_cgroup(struct page *page) | |
60 | { | |
61 | return NULL; | |
62 | } | |
94b6da5a KH |
63 | |
64 | static inline void page_cgroup_init(void) | |
65 | { | |
66 | } | |
67 | ||
ca371c0d KH |
68 | static inline void __init page_cgroup_init_flatmem(void) |
69 | { | |
70 | } | |
71 | ||
c255a458 | 72 | #endif /* CONFIG_MEMCG */ |
27a7faa0 | 73 | |
27a7faa0 | 74 | #include <linux/swap.h> |
97572751 | 75 | |
c255a458 | 76 | #ifdef CONFIG_MEMCG_SWAP |
02491447 DN |
77 | extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
78 | unsigned short old, unsigned short new); | |
a3b2d692 | 79 | extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id); |
9fb4b7cc | 80 | extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent); |
27a7faa0 KH |
81 | extern int swap_cgroup_swapon(int type, unsigned long max_pages); |
82 | extern void swap_cgroup_swapoff(int type); | |
83 | #else | |
27a7faa0 KH |
84 | |
85 | static inline | |
a3b2d692 | 86 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
27a7faa0 | 87 | { |
a3b2d692 | 88 | return 0; |
27a7faa0 KH |
89 | } |
90 | ||
91 | static inline | |
9fb4b7cc | 92 | unsigned short lookup_swap_cgroup_id(swp_entry_t ent) |
27a7faa0 | 93 | { |
a3b2d692 | 94 | return 0; |
27a7faa0 KH |
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 | ||
c255a458 | 108 | #endif /* CONFIG_MEMCG_SWAP */ |
6b3ae58e JW |
109 | |
110 | #endif /* !__GENERATING_BOUNDS_H */ | |
111 | ||
112 | #endif /* __LINUX_PAGE_CGROUP_H */ |