1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM compaction
4 
5 #if !defined(_TRACE_COMPACTION_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_COMPACTION_H
7 
8 #include <linux/types.h>
9 #include <linux/list.h>
10 #include <linux/tracepoint.h>
11 #include <trace/events/mmflags.h>
12 
13 
14 DECLARE_EVENT_CLASS(mm_compaction_isolate_template,
15 
16 	TP_PROTO(
17 		unsigned long start_pfn,
18 		unsigned long end_pfn,
19 		unsigned long nr_scanned,
20 		unsigned long nr_taken),
21 
22 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken),
23 
24 	TP_STRUCT__entry(
25 		__field(unsigned long, start_pfn)
26 		__field(unsigned long, end_pfn)
27 		__field(unsigned long, nr_scanned)
28 		__field(unsigned long, nr_taken)
29 	),
30 
31 	TP_fast_assign(
32 		__entry->start_pfn = start_pfn;
33 		__entry->end_pfn = end_pfn;
34 		__entry->nr_scanned = nr_scanned;
35 		__entry->nr_taken = nr_taken;
36 	),
37 
38 	TP_printk("range=(0x%lx ~ 0x%lx) nr_scanned=%lu nr_taken=%lu",
39 		__entry->start_pfn,
40 		__entry->end_pfn,
41 		__entry->nr_scanned,
42 		__entry->nr_taken)
43 );
44 
45 DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_isolate_migratepages,
46 
47 	TP_PROTO(
48 		unsigned long start_pfn,
49 		unsigned long end_pfn,
50 		unsigned long nr_scanned,
51 		unsigned long nr_taken),
52 
53 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken)
54 );
55 
56 DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_isolate_freepages,
57 
58 	TP_PROTO(
59 		unsigned long start_pfn,
60 		unsigned long end_pfn,
61 		unsigned long nr_scanned,
62 		unsigned long nr_taken),
63 
64 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken)
65 );
66 
67 #ifdef CONFIG_COMPACTION
68 TRACE_EVENT(mm_compaction_migratepages,
69 
70 	TP_PROTO(unsigned long nr_all,
71 		unsigned int nr_succeeded),
72 
73 	TP_ARGS(nr_all, nr_succeeded),
74 
75 	TP_STRUCT__entry(
76 		__field(unsigned long, nr_migrated)
77 		__field(unsigned long, nr_failed)
78 	),
79 
80 	TP_fast_assign(
81 		__entry->nr_migrated = nr_succeeded;
82 		__entry->nr_failed = nr_all - nr_succeeded;
83 	),
84 
85 	TP_printk("nr_migrated=%lu nr_failed=%lu",
86 		__entry->nr_migrated,
87 		__entry->nr_failed)
88 );
89 
90 TRACE_EVENT(mm_compaction_begin,
91 	TP_PROTO(unsigned long zone_start, unsigned long migrate_pfn,
92 		unsigned long free_pfn, unsigned long zone_end, bool sync),
93 
94 	TP_ARGS(zone_start, migrate_pfn, free_pfn, zone_end, sync),
95 
96 	TP_STRUCT__entry(
97 		__field(unsigned long, zone_start)
98 		__field(unsigned long, migrate_pfn)
99 		__field(unsigned long, free_pfn)
100 		__field(unsigned long, zone_end)
101 		__field(bool, sync)
102 	),
103 
104 	TP_fast_assign(
105 		__entry->zone_start = zone_start;
106 		__entry->migrate_pfn = migrate_pfn;
107 		__entry->free_pfn = free_pfn;
108 		__entry->zone_end = zone_end;
109 		__entry->sync = sync;
110 	),
111 
112 	TP_printk("zone_start=0x%lx migrate_pfn=0x%lx free_pfn=0x%lx zone_end=0x%lx, mode=%s",
113 		__entry->zone_start,
114 		__entry->migrate_pfn,
115 		__entry->free_pfn,
116 		__entry->zone_end,
117 		__entry->sync ? "sync" : "async")
118 );
119 
120 TRACE_EVENT(mm_compaction_end,
121 	TP_PROTO(unsigned long zone_start, unsigned long migrate_pfn,
122 		unsigned long free_pfn, unsigned long zone_end, bool sync,
123 		int status),
124 
125 	TP_ARGS(zone_start, migrate_pfn, free_pfn, zone_end, sync, status),
126 
127 	TP_STRUCT__entry(
128 		__field(unsigned long, zone_start)
129 		__field(unsigned long, migrate_pfn)
130 		__field(unsigned long, free_pfn)
131 		__field(unsigned long, zone_end)
132 		__field(bool, sync)
133 		__field(int, status)
134 	),
135 
136 	TP_fast_assign(
137 		__entry->zone_start = zone_start;
138 		__entry->migrate_pfn = migrate_pfn;
139 		__entry->free_pfn = free_pfn;
140 		__entry->zone_end = zone_end;
141 		__entry->sync = sync;
142 		__entry->status = status;
143 	),
144 
145 	TP_printk("zone_start=0x%lx migrate_pfn=0x%lx free_pfn=0x%lx zone_end=0x%lx, mode=%s status=%s",
146 		__entry->zone_start,
147 		__entry->migrate_pfn,
148 		__entry->free_pfn,
149 		__entry->zone_end,
150 		__entry->sync ? "sync" : "async",
151 		__print_symbolic(__entry->status, COMPACTION_STATUS))
152 );
153 
154 TRACE_EVENT(mm_compaction_try_to_compact_pages,
155 
156 	TP_PROTO(
157 		int order,
158 		gfp_t gfp_mask,
159 		int prio),
160 
161 	TP_ARGS(order, gfp_mask, prio),
162 
163 	TP_STRUCT__entry(
164 		__field(int, order)
165 		__field(gfp_t, gfp_mask)
166 		__field(int, prio)
167 	),
168 
169 	TP_fast_assign(
170 		__entry->order = order;
171 		__entry->gfp_mask = gfp_mask;
172 		__entry->prio = prio;
173 	),
174 
175 	TP_printk("order=%d gfp_mask=%s priority=%d",
176 		__entry->order,
177 		show_gfp_flags(__entry->gfp_mask),
178 		__entry->prio)
179 );
180 
181 DECLARE_EVENT_CLASS(mm_compaction_suitable_template,
182 
183 	TP_PROTO(struct zone *zone,
184 		int order,
185 		int ret),
186 
187 	TP_ARGS(zone, order, ret),
188 
189 	TP_STRUCT__entry(
190 		__field(int, nid)
191 		__field(enum zone_type, idx)
192 		__field(int, order)
193 		__field(int, ret)
194 	),
195 
196 	TP_fast_assign(
197 		__entry->nid = zone_to_nid(zone);
198 		__entry->idx = zone_idx(zone);
199 		__entry->order = order;
200 		__entry->ret = ret;
201 	),
202 
203 	TP_printk("node=%d zone=%-8s order=%d ret=%s",
204 		__entry->nid,
205 		__print_symbolic(__entry->idx, ZONE_TYPE),
206 		__entry->order,
207 		__print_symbolic(__entry->ret, COMPACTION_STATUS))
208 );
209 
210 DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_finished,
211 
212 	TP_PROTO(struct zone *zone,
213 		int order,
214 		int ret),
215 
216 	TP_ARGS(zone, order, ret)
217 );
218 
219 DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_suitable,
220 
221 	TP_PROTO(struct zone *zone,
222 		int order,
223 		int ret),
224 
225 	TP_ARGS(zone, order, ret)
226 );
227 
228 DECLARE_EVENT_CLASS(mm_compaction_defer_template,
229 
230 	TP_PROTO(struct zone *zone, int order),
231 
232 	TP_ARGS(zone, order),
233 
234 	TP_STRUCT__entry(
235 		__field(int, nid)
236 		__field(enum zone_type, idx)
237 		__field(int, order)
238 		__field(unsigned int, considered)
239 		__field(unsigned int, defer_shift)
240 		__field(int, order_failed)
241 	),
242 
243 	TP_fast_assign(
244 		__entry->nid = zone_to_nid(zone);
245 		__entry->idx = zone_idx(zone);
246 		__entry->order = order;
247 		__entry->considered = zone->compact_considered;
248 		__entry->defer_shift = zone->compact_defer_shift;
249 		__entry->order_failed = zone->compact_order_failed;
250 	),
251 
252 	TP_printk("node=%d zone=%-8s order=%d order_failed=%d consider=%u limit=%lu",
253 		__entry->nid,
254 		__print_symbolic(__entry->idx, ZONE_TYPE),
255 		__entry->order,
256 		__entry->order_failed,
257 		__entry->considered,
258 		1UL << __entry->defer_shift)
259 );
260 
261 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_deferred,
262 
263 	TP_PROTO(struct zone *zone, int order),
264 
265 	TP_ARGS(zone, order)
266 );
267 
268 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_defer_compaction,
269 
270 	TP_PROTO(struct zone *zone, int order),
271 
272 	TP_ARGS(zone, order)
273 );
274 
275 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_defer_reset,
276 
277 	TP_PROTO(struct zone *zone, int order),
278 
279 	TP_ARGS(zone, order)
280 );
281 
282 TRACE_EVENT(mm_compaction_kcompactd_sleep,
283 
284 	TP_PROTO(int nid),
285 
286 	TP_ARGS(nid),
287 
288 	TP_STRUCT__entry(
289 		__field(int, nid)
290 	),
291 
292 	TP_fast_assign(
293 		__entry->nid = nid;
294 	),
295 
296 	TP_printk("nid=%d", __entry->nid)
297 );
298 
299 DECLARE_EVENT_CLASS(kcompactd_wake_template,
300 
301 	TP_PROTO(int nid, int order, enum zone_type highest_zoneidx),
302 
303 	TP_ARGS(nid, order, highest_zoneidx),
304 
305 	TP_STRUCT__entry(
306 		__field(int, nid)
307 		__field(int, order)
308 		__field(enum zone_type, highest_zoneidx)
309 	),
310 
311 	TP_fast_assign(
312 		__entry->nid = nid;
313 		__entry->order = order;
314 		__entry->highest_zoneidx = highest_zoneidx;
315 	),
316 
317 	/*
318 	 * classzone_idx is previous name of the highest_zoneidx.
319 	 * Reason not to change it is the ABI requirement of the tracepoint.
320 	 */
321 	TP_printk("nid=%d order=%d classzone_idx=%-8s",
322 		__entry->nid,
323 		__entry->order,
324 		__print_symbolic(__entry->highest_zoneidx, ZONE_TYPE))
325 );
326 
327 DEFINE_EVENT(kcompactd_wake_template, mm_compaction_wakeup_kcompactd,
328 
329 	TP_PROTO(int nid, int order, enum zone_type highest_zoneidx),
330 
331 	TP_ARGS(nid, order, highest_zoneidx)
332 );
333 
334 DEFINE_EVENT(kcompactd_wake_template, mm_compaction_kcompactd_wake,
335 
336 	TP_PROTO(int nid, int order, enum zone_type highest_zoneidx),
337 
338 	TP_ARGS(nid, order, highest_zoneidx)
339 );
340 #endif
341 
342 #endif /* _TRACE_COMPACTION_H */
343 
344 /* This part must be outside protection */
345 #include <trace/define_trace.h>
346