Commit | Line | Data |
---|---|---|
2bc64a20 AK |
1 | /* |
2 | * Copyright IBM Corporation, 2012 | |
3 | * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of version 2.1 of the GNU Lesser General Public License | |
7 | * as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it would be useful, but | |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef _LINUX_HUGETLB_CGROUP_H | |
16 | #define _LINUX_HUGETLB_CGROUP_H | |
17 | ||
309381fe | 18 | #include <linux/mmdebug.h> |
2bc64a20 AK |
19 | |
20 | struct hugetlb_cgroup; | |
e9fe92ae | 21 | struct resv_map; |
075a61d0 | 22 | struct file_region; |
e9fe92ae | 23 | |
cd39d4e9 | 24 | #ifdef CONFIG_CGROUP_HUGETLB |
e9fe92ae MA |
25 | enum hugetlb_memory_event { |
26 | HUGETLB_MAX, | |
27 | HUGETLB_NR_MEMORY_EVENTS, | |
28 | }; | |
29 | ||
f4776199 MA |
30 | struct hugetlb_cgroup_per_node { |
31 | /* hugetlb usage in pages over all hstates. */ | |
32 | unsigned long usage[HUGE_MAX_HSTATE]; | |
33 | }; | |
34 | ||
e9fe92ae MA |
35 | struct hugetlb_cgroup { |
36 | struct cgroup_subsys_state css; | |
37 | ||
38 | /* | |
39 | * the counter to account for hugepages from hugetlb. | |
40 | */ | |
41 | struct page_counter hugepage[HUGE_MAX_HSTATE]; | |
42 | ||
43 | /* | |
44 | * the counter to account for hugepage reservations from hugetlb. | |
45 | */ | |
46 | struct page_counter rsvd_hugepage[HUGE_MAX_HSTATE]; | |
47 | ||
48 | atomic_long_t events[HUGE_MAX_HSTATE][HUGETLB_NR_MEMORY_EVENTS]; | |
49 | atomic_long_t events_local[HUGE_MAX_HSTATE][HUGETLB_NR_MEMORY_EVENTS]; | |
50 | ||
51 | /* Handle for "hugetlb.events" */ | |
52 | struct cgroup_file events_file[HUGE_MAX_HSTATE]; | |
53 | ||
54 | /* Handle for "hugetlb.events.local" */ | |
55 | struct cgroup_file events_local_file[HUGE_MAX_HSTATE]; | |
f4776199 MA |
56 | |
57 | struct hugetlb_cgroup_per_node *nodeinfo[]; | |
e9fe92ae | 58 | }; |
9dd540e2 | 59 | |
1adc4d41 | 60 | static inline struct hugetlb_cgroup * |
f074732d | 61 | __hugetlb_cgroup_from_folio(struct folio *folio, bool rsvd) |
9dd540e2 | 62 | { |
f074732d | 63 | VM_BUG_ON_FOLIO(!folio_test_hugetlb(folio), folio); |
dad6a5eb HD |
64 | if (rsvd) |
65 | return folio->_hugetlb_cgroup_rsvd; | |
66 | else | |
67 | return folio->_hugetlb_cgroup; | |
1adc4d41 MA |
68 | } |
69 | ||
f074732d | 70 | static inline struct hugetlb_cgroup *hugetlb_cgroup_from_folio(struct folio *folio) |
1adc4d41 | 71 | { |
f074732d | 72 | return __hugetlb_cgroup_from_folio(folio, false); |
9dd540e2 AK |
73 | } |
74 | ||
1adc4d41 | 75 | static inline struct hugetlb_cgroup * |
f074732d | 76 | hugetlb_cgroup_from_folio_rsvd(struct folio *folio) |
1adc4d41 | 77 | { |
f074732d | 78 | return __hugetlb_cgroup_from_folio(folio, true); |
1adc4d41 MA |
79 | } |
80 | ||
a098c977 | 81 | static inline void __set_hugetlb_cgroup(struct folio *folio, |
1adc4d41 | 82 | struct hugetlb_cgroup *h_cg, bool rsvd) |
9dd540e2 | 83 | { |
a098c977 | 84 | VM_BUG_ON_FOLIO(!folio_test_hugetlb(folio), folio); |
1adc4d41 | 85 | if (rsvd) |
dad6a5eb | 86 | folio->_hugetlb_cgroup_rsvd = h_cg; |
1adc4d41 | 87 | else |
dad6a5eb | 88 | folio->_hugetlb_cgroup = h_cg; |
9dd540e2 AK |
89 | } |
90 | ||
de656ed3 | 91 | static inline void set_hugetlb_cgroup(struct folio *folio, |
1adc4d41 MA |
92 | struct hugetlb_cgroup *h_cg) |
93 | { | |
de656ed3 | 94 | __set_hugetlb_cgroup(folio, h_cg, false); |
1adc4d41 MA |
95 | } |
96 | ||
de656ed3 | 97 | static inline void set_hugetlb_cgroup_rsvd(struct folio *folio, |
1adc4d41 MA |
98 | struct hugetlb_cgroup *h_cg) |
99 | { | |
de656ed3 | 100 | __set_hugetlb_cgroup(folio, h_cg, true); |
1adc4d41 MA |
101 | } |
102 | ||
2bc64a20 AK |
103 | static inline bool hugetlb_cgroup_disabled(void) |
104 | { | |
fc5ed1e9 | 105 | return !cgroup_subsys_enabled(hugetlb_cgrp_subsys); |
2bc64a20 AK |
106 | } |
107 | ||
d85aecf2 ML |
108 | static inline void hugetlb_cgroup_put_rsvd_cgroup(struct hugetlb_cgroup *h_cg) |
109 | { | |
110 | css_put(&h_cg->css); | |
111 | } | |
112 | ||
09a26e83 MK |
113 | static inline void resv_map_dup_hugetlb_cgroup_uncharge_info( |
114 | struct resv_map *resv_map) | |
115 | { | |
116 | if (resv_map->css) | |
117 | css_get(resv_map->css); | |
118 | } | |
119 | ||
afe041c2 BQM |
120 | static inline void resv_map_put_hugetlb_cgroup_uncharge_info( |
121 | struct resv_map *resv_map) | |
122 | { | |
123 | if (resv_map->css) | |
124 | css_put(resv_map->css); | |
125 | } | |
126 | ||
6d76dcf4 AK |
127 | extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, |
128 | struct hugetlb_cgroup **ptr); | |
1adc4d41 MA |
129 | extern int hugetlb_cgroup_charge_cgroup_rsvd(int idx, unsigned long nr_pages, |
130 | struct hugetlb_cgroup **ptr); | |
6d76dcf4 AK |
131 | extern void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages, |
132 | struct hugetlb_cgroup *h_cg, | |
ff7d853b | 133 | struct folio *folio); |
1adc4d41 MA |
134 | extern void hugetlb_cgroup_commit_charge_rsvd(int idx, unsigned long nr_pages, |
135 | struct hugetlb_cgroup *h_cg, | |
ff7d853b | 136 | struct folio *folio); |
d4ab0316 SK |
137 | extern void hugetlb_cgroup_uncharge_folio(int idx, unsigned long nr_pages, |
138 | struct folio *folio); | |
139 | extern void hugetlb_cgroup_uncharge_folio_rsvd(int idx, unsigned long nr_pages, | |
140 | struct folio *folio); | |
1adc4d41 | 141 | |
6d76dcf4 AK |
142 | extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages, |
143 | struct hugetlb_cgroup *h_cg); | |
1adc4d41 MA |
144 | extern void hugetlb_cgroup_uncharge_cgroup_rsvd(int idx, unsigned long nr_pages, |
145 | struct hugetlb_cgroup *h_cg); | |
e9fe92ae MA |
146 | extern void hugetlb_cgroup_uncharge_counter(struct resv_map *resv, |
147 | unsigned long start, | |
148 | unsigned long end); | |
1adc4d41 | 149 | |
075a61d0 MA |
150 | extern void hugetlb_cgroup_uncharge_file_region(struct resv_map *resv, |
151 | struct file_region *rg, | |
d85aecf2 ML |
152 | unsigned long nr_pages, |
153 | bool region_del); | |
075a61d0 | 154 | |
7179e7bf | 155 | extern void hugetlb_cgroup_file_init(void) __init; |
29f39430 SK |
156 | extern void hugetlb_cgroup_migrate(struct folio *old_folio, |
157 | struct folio *new_folio); | |
6d76dcf4 | 158 | |
2bc64a20 | 159 | #else |
075a61d0 MA |
160 | static inline void hugetlb_cgroup_uncharge_file_region(struct resv_map *resv, |
161 | struct file_region *rg, | |
d85aecf2 ML |
162 | unsigned long nr_pages, |
163 | bool region_del) | |
075a61d0 MA |
164 | { |
165 | } | |
166 | ||
f074732d | 167 | static inline struct hugetlb_cgroup *hugetlb_cgroup_from_folio(struct folio *folio) |
1adc4d41 MA |
168 | { |
169 | return NULL; | |
170 | } | |
171 | ||
172 | static inline struct hugetlb_cgroup * | |
f074732d | 173 | hugetlb_cgroup_from_folio_rsvd(struct folio *folio) |
1adc4d41 MA |
174 | { |
175 | return NULL; | |
176 | } | |
177 | ||
de656ed3 | 178 | static inline void set_hugetlb_cgroup(struct folio *folio, |
1adc4d41 MA |
179 | struct hugetlb_cgroup *h_cg) |
180 | { | |
1adc4d41 MA |
181 | } |
182 | ||
de656ed3 | 183 | static inline void set_hugetlb_cgroup_rsvd(struct folio *folio, |
1adc4d41 | 184 | struct hugetlb_cgroup *h_cg) |
9dd540e2 | 185 | { |
9dd540e2 AK |
186 | } |
187 | ||
2bc64a20 AK |
188 | static inline bool hugetlb_cgroup_disabled(void) |
189 | { | |
190 | return true; | |
191 | } | |
192 | ||
d85aecf2 ML |
193 | static inline void hugetlb_cgroup_put_rsvd_cgroup(struct hugetlb_cgroup *h_cg) |
194 | { | |
195 | } | |
196 | ||
09a26e83 MK |
197 | static inline void resv_map_dup_hugetlb_cgroup_uncharge_info( |
198 | struct resv_map *resv_map) | |
199 | { | |
200 | } | |
201 | ||
afe041c2 BQM |
202 | static inline void resv_map_put_hugetlb_cgroup_uncharge_info( |
203 | struct resv_map *resv_map) | |
204 | { | |
205 | } | |
206 | ||
1adc4d41 MA |
207 | static inline int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, |
208 | struct hugetlb_cgroup **ptr) | |
6d76dcf4 AK |
209 | { |
210 | return 0; | |
211 | } | |
212 | ||
1adc4d41 MA |
213 | static inline int hugetlb_cgroup_charge_cgroup_rsvd(int idx, |
214 | unsigned long nr_pages, | |
215 | struct hugetlb_cgroup **ptr) | |
216 | { | |
217 | return 0; | |
218 | } | |
219 | ||
220 | static inline void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages, | |
221 | struct hugetlb_cgroup *h_cg, | |
ff7d853b | 222 | struct folio *folio) |
6d76dcf4 | 223 | { |
6d76dcf4 AK |
224 | } |
225 | ||
226 | static inline void | |
1adc4d41 MA |
227 | hugetlb_cgroup_commit_charge_rsvd(int idx, unsigned long nr_pages, |
228 | struct hugetlb_cgroup *h_cg, | |
ff7d853b | 229 | struct folio *folio) |
1adc4d41 MA |
230 | { |
231 | } | |
232 | ||
d4ab0316 SK |
233 | static inline void hugetlb_cgroup_uncharge_folio(int idx, unsigned long nr_pages, |
234 | struct folio *folio) | |
1adc4d41 MA |
235 | { |
236 | } | |
237 | ||
d4ab0316 | 238 | static inline void hugetlb_cgroup_uncharge_folio_rsvd(int idx, |
1adc4d41 | 239 | unsigned long nr_pages, |
d4ab0316 | 240 | struct folio *folio) |
1adc4d41 MA |
241 | { |
242 | } | |
243 | static inline void hugetlb_cgroup_uncharge_cgroup(int idx, | |
244 | unsigned long nr_pages, | |
245 | struct hugetlb_cgroup *h_cg) | |
6d76dcf4 | 246 | { |
6d76dcf4 AK |
247 | } |
248 | ||
249 | static inline void | |
1adc4d41 MA |
250 | hugetlb_cgroup_uncharge_cgroup_rsvd(int idx, unsigned long nr_pages, |
251 | struct hugetlb_cgroup *h_cg) | |
6d76dcf4 | 252 | { |
6d76dcf4 AK |
253 | } |
254 | ||
e9fe92ae MA |
255 | static inline void hugetlb_cgroup_uncharge_counter(struct resv_map *resv, |
256 | unsigned long start, | |
257 | unsigned long end) | |
258 | { | |
259 | } | |
260 | ||
7179e7bf | 261 | static inline void hugetlb_cgroup_file_init(void) |
abb8206c | 262 | { |
abb8206c AK |
263 | } |
264 | ||
29f39430 SK |
265 | static inline void hugetlb_cgroup_migrate(struct folio *old_folio, |
266 | struct folio *new_folio) | |
8e6ac7fa | 267 | { |
8e6ac7fa AK |
268 | } |
269 | ||
2bc64a20 AK |
270 | #endif /* CONFIG_MEM_RES_CTLR_HUGETLB */ |
271 | #endif |