1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM compaction
3 
4 #if !defined(_TRACE_COMPACTION_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_COMPACTION_H
6 
7 #include <linux/types.h>
8 #include <linux/list.h>
9 #include <linux/tracepoint.h>
10 #include <trace/events/mmflags.h>
11 
12 #define COMPACTION_STATUS					\
13 	EM( COMPACT_SKIPPED,		"skipped")		\
14 	EM( COMPACT_DEFERRED,		"deferred")		\
15 	EM( COMPACT_CONTINUE,		"continue")		\
16 	EM( COMPACT_SUCCESS,		"success")		\
17 	EM( COMPACT_PARTIAL_SKIPPED,	"partial_skipped")	\
18 	EM( COMPACT_COMPLETE,		"complete")		\
19 	EM( COMPACT_NO_SUITABLE_PAGE,	"no_suitable_page")	\
20 	EM( COMPACT_NOT_SUITABLE_ZONE,	"not_suitable_zone")	\
21 	EMe(COMPACT_CONTENDED,		"contended")
22 
23 #ifdef CONFIG_ZONE_DMA
24 #define IFDEF_ZONE_DMA(X) X
25 #else
26 #define IFDEF_ZONE_DMA(X)
27 #endif
28 
29 #ifdef CONFIG_ZONE_DMA32
30 #define IFDEF_ZONE_DMA32(X) X
31 #else
32 #define IFDEF_ZONE_DMA32(X)
33 #endif
34 
35 #ifdef CONFIG_HIGHMEM
36 #define IFDEF_ZONE_HIGHMEM(X) X
37 #else
38 #define IFDEF_ZONE_HIGHMEM(X)
39 #endif
40 
41 #define ZONE_TYPE						\
42 	IFDEF_ZONE_DMA(		EM (ZONE_DMA,	 "DMA"))	\
43 	IFDEF_ZONE_DMA32(	EM (ZONE_DMA32,	 "DMA32"))	\
44 				EM (ZONE_NORMAL, "Normal")	\
45 	IFDEF_ZONE_HIGHMEM(	EM (ZONE_HIGHMEM,"HighMem"))	\
46 				EMe(ZONE_MOVABLE,"Movable")
47 
48 /*
49  * First define the enums in the above macros to be exported to userspace
50  * via TRACE_DEFINE_ENUM().
51  */
52 #undef EM
53 #undef EMe
54 #define EM(a, b)	TRACE_DEFINE_ENUM(a);
55 #define EMe(a, b)	TRACE_DEFINE_ENUM(a);
56 
57 COMPACTION_STATUS
58 ZONE_TYPE
59 
60 /*
61  * Now redefine the EM() and EMe() macros to map the enums to the strings
62  * that will be printed in the output.
63  */
64 #undef EM
65 #undef EMe
66 #define EM(a, b)	{a, b},
67 #define EMe(a, b)	{a, b}
68 
69 DECLARE_EVENT_CLASS(mm_compaction_isolate_template,
70 
71 	TP_PROTO(
72 		unsigned long start_pfn,
73 		unsigned long end_pfn,
74 		unsigned long nr_scanned,
75 		unsigned long nr_taken),
76 
77 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken),
78 
79 	TP_STRUCT__entry(
80 		__field(unsigned long, start_pfn)
81 		__field(unsigned long, end_pfn)
82 		__field(unsigned long, nr_scanned)
83 		__field(unsigned long, nr_taken)
84 	),
85 
86 	TP_fast_assign(
87 		__entry->start_pfn = start_pfn;
88 		__entry->end_pfn = end_pfn;
89 		__entry->nr_scanned = nr_scanned;
90 		__entry->nr_taken = nr_taken;
91 	),
92 
93 	TP_printk("range=(0x%lx ~ 0x%lx) nr_scanned=%lu nr_taken=%lu",
94 		__entry->start_pfn,
95 		__entry->end_pfn,
96 		__entry->nr_scanned,
97 		__entry->nr_taken)
98 );
99 
100 DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_isolate_migratepages,
101 
102 	TP_PROTO(
103 		unsigned long start_pfn,
104 		unsigned long end_pfn,
105 		unsigned long nr_scanned,
106 		unsigned long nr_taken),
107 
108 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken)
109 );
110 
111 DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_isolate_freepages,
112 
113 	TP_PROTO(
114 		unsigned long start_pfn,
115 		unsigned long end_pfn,
116 		unsigned long nr_scanned,
117 		unsigned long nr_taken),
118 
119 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken)
120 );
121 
122 TRACE_EVENT(mm_compaction_migratepages,
123 
124 	TP_PROTO(unsigned long nr_all,
125 		int migrate_rc,
126 		struct list_head *migratepages),
127 
128 	TP_ARGS(nr_all, migrate_rc, migratepages),
129 
130 	TP_STRUCT__entry(
131 		__field(unsigned long, nr_migrated)
132 		__field(unsigned long, nr_failed)
133 	),
134 
135 	TP_fast_assign(
136 		unsigned long nr_failed = 0;
137 		struct list_head *page_lru;
138 
139 		/*
140 		 * migrate_pages() returns either a non-negative number
141 		 * with the number of pages that failed migration, or an
142 		 * error code, in which case we need to count the remaining
143 		 * pages manually
144 		 */
145 		if (migrate_rc >= 0)
146 			nr_failed = migrate_rc;
147 		else
148 			list_for_each(page_lru, migratepages)
149 				nr_failed++;
150 
151 		__entry->nr_migrated = nr_all - nr_failed;
152 		__entry->nr_failed = nr_failed;
153 	),
154 
155 	TP_printk("nr_migrated=%lu nr_failed=%lu",
156 		__entry->nr_migrated,
157 		__entry->nr_failed)
158 );
159 
160 TRACE_EVENT(mm_compaction_begin,
161 	TP_PROTO(unsigned long zone_start, unsigned long migrate_pfn,
162 		unsigned long free_pfn, unsigned long zone_end, bool sync),
163 
164 	TP_ARGS(zone_start, migrate_pfn, free_pfn, zone_end, sync),
165 
166 	TP_STRUCT__entry(
167 		__field(unsigned long, zone_start)
168 		__field(unsigned long, migrate_pfn)
169 		__field(unsigned long, free_pfn)
170 		__field(unsigned long, zone_end)
171 		__field(bool, sync)
172 	),
173 
174 	TP_fast_assign(
175 		__entry->zone_start = zone_start;
176 		__entry->migrate_pfn = migrate_pfn;
177 		__entry->free_pfn = free_pfn;
178 		__entry->zone_end = zone_end;
179 		__entry->sync = sync;
180 	),
181 
182 	TP_printk("zone_start=0x%lx migrate_pfn=0x%lx free_pfn=0x%lx zone_end=0x%lx, mode=%s",
183 		__entry->zone_start,
184 		__entry->migrate_pfn,
185 		__entry->free_pfn,
186 		__entry->zone_end,
187 		__entry->sync ? "sync" : "async")
188 );
189 
190 TRACE_EVENT(mm_compaction_end,
191 	TP_PROTO(unsigned long zone_start, unsigned long migrate_pfn,
192 		unsigned long free_pfn, unsigned long zone_end, bool sync,
193 		int status),
194 
195 	TP_ARGS(zone_start, migrate_pfn, free_pfn, zone_end, sync, status),
196 
197 	TP_STRUCT__entry(
198 		__field(unsigned long, zone_start)
199 		__field(unsigned long, migrate_pfn)
200 		__field(unsigned long, free_pfn)
201 		__field(unsigned long, zone_end)
202 		__field(bool, sync)
203 		__field(int, status)
204 	),
205 
206 	TP_fast_assign(
207 		__entry->zone_start = zone_start;
208 		__entry->migrate_pfn = migrate_pfn;
209 		__entry->free_pfn = free_pfn;
210 		__entry->zone_end = zone_end;
211 		__entry->sync = sync;
212 		__entry->status = status;
213 	),
214 
215 	TP_printk("zone_start=0x%lx migrate_pfn=0x%lx free_pfn=0x%lx zone_end=0x%lx, mode=%s status=%s",
216 		__entry->zone_start,
217 		__entry->migrate_pfn,
218 		__entry->free_pfn,
219 		__entry->zone_end,
220 		__entry->sync ? "sync" : "async",
221 		__print_symbolic(__entry->status, COMPACTION_STATUS))
222 );
223 
224 TRACE_EVENT(mm_compaction_try_to_compact_pages,
225 
226 	TP_PROTO(
227 		int order,
228 		gfp_t gfp_mask,
229 		int prio),
230 
231 	TP_ARGS(order, gfp_mask, prio),
232 
233 	TP_STRUCT__entry(
234 		__field(int, order)
235 		__field(gfp_t, gfp_mask)
236 		__field(int, prio)
237 	),
238 
239 	TP_fast_assign(
240 		__entry->order = order;
241 		__entry->gfp_mask = gfp_mask;
242 		__entry->prio = prio;
243 	),
244 
245 	TP_printk("order=%d gfp_mask=0x%x priority=%d",
246 		__entry->order,
247 		__entry->gfp_mask,
248 		__entry->prio)
249 );
250 
251 DECLARE_EVENT_CLASS(mm_compaction_suitable_template,
252 
253 	TP_PROTO(struct zone *zone,
254 		int order,
255 		int ret),
256 
257 	TP_ARGS(zone, order, ret),
258 
259 	TP_STRUCT__entry(
260 		__field(int, nid)
261 		__field(enum zone_type, idx)
262 		__field(int, order)
263 		__field(int, ret)
264 	),
265 
266 	TP_fast_assign(
267 		__entry->nid = zone_to_nid(zone);
268 		__entry->idx = zone_idx(zone);
269 		__entry->order = order;
270 		__entry->ret = ret;
271 	),
272 
273 	TP_printk("node=%d zone=%-8s order=%d ret=%s",
274 		__entry->nid,
275 		__print_symbolic(__entry->idx, ZONE_TYPE),
276 		__entry->order,
277 		__print_symbolic(__entry->ret, COMPACTION_STATUS))
278 );
279 
280 DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_finished,
281 
282 	TP_PROTO(struct zone *zone,
283 		int order,
284 		int ret),
285 
286 	TP_ARGS(zone, order, ret)
287 );
288 
289 DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_suitable,
290 
291 	TP_PROTO(struct zone *zone,
292 		int order,
293 		int ret),
294 
295 	TP_ARGS(zone, order, ret)
296 );
297 
298 #ifdef CONFIG_COMPACTION
299 DECLARE_EVENT_CLASS(mm_compaction_defer_template,
300 
301 	TP_PROTO(struct zone *zone, int order),
302 
303 	TP_ARGS(zone, order),
304 
305 	TP_STRUCT__entry(
306 		__field(int, nid)
307 		__field(enum zone_type, idx)
308 		__field(int, order)
309 		__field(unsigned int, considered)
310 		__field(unsigned int, defer_shift)
311 		__field(int, order_failed)
312 	),
313 
314 	TP_fast_assign(
315 		__entry->nid = zone_to_nid(zone);
316 		__entry->idx = zone_idx(zone);
317 		__entry->order = order;
318 		__entry->considered = zone->compact_considered;
319 		__entry->defer_shift = zone->compact_defer_shift;
320 		__entry->order_failed = zone->compact_order_failed;
321 	),
322 
323 	TP_printk("node=%d zone=%-8s order=%d order_failed=%d consider=%u limit=%lu",
324 		__entry->nid,
325 		__print_symbolic(__entry->idx, ZONE_TYPE),
326 		__entry->order,
327 		__entry->order_failed,
328 		__entry->considered,
329 		1UL << __entry->defer_shift)
330 );
331 
332 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_deferred,
333 
334 	TP_PROTO(struct zone *zone, int order),
335 
336 	TP_ARGS(zone, order)
337 );
338 
339 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_defer_compaction,
340 
341 	TP_PROTO(struct zone *zone, int order),
342 
343 	TP_ARGS(zone, order)
344 );
345 
346 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_defer_reset,
347 
348 	TP_PROTO(struct zone *zone, int order),
349 
350 	TP_ARGS(zone, order)
351 );
352 #endif
353 
354 TRACE_EVENT(mm_compaction_kcompactd_sleep,
355 
356 	TP_PROTO(int nid),
357 
358 	TP_ARGS(nid),
359 
360 	TP_STRUCT__entry(
361 		__field(int, nid)
362 	),
363 
364 	TP_fast_assign(
365 		__entry->nid = nid;
366 	),
367 
368 	TP_printk("nid=%d", __entry->nid)
369 );
370 
371 DECLARE_EVENT_CLASS(kcompactd_wake_template,
372 
373 	TP_PROTO(int nid, int order, enum zone_type classzone_idx),
374 
375 	TP_ARGS(nid, order, classzone_idx),
376 
377 	TP_STRUCT__entry(
378 		__field(int, nid)
379 		__field(int, order)
380 		__field(enum zone_type, classzone_idx)
381 	),
382 
383 	TP_fast_assign(
384 		__entry->nid = nid;
385 		__entry->order = order;
386 		__entry->classzone_idx = classzone_idx;
387 	),
388 
389 	TP_printk("nid=%d order=%d classzone_idx=%-8s",
390 		__entry->nid,
391 		__entry->order,
392 		__print_symbolic(__entry->classzone_idx, ZONE_TYPE))
393 );
394 
395 DEFINE_EVENT(kcompactd_wake_template, mm_compaction_wakeup_kcompactd,
396 
397 	TP_PROTO(int nid, int order, enum zone_type classzone_idx),
398 
399 	TP_ARGS(nid, order, classzone_idx)
400 );
401 
402 DEFINE_EVENT(kcompactd_wake_template, mm_compaction_kcompactd_wake,
403 
404 	TP_PROTO(int nid, int order, enum zone_type classzone_idx),
405 
406 	TP_ARGS(nid, order, classzone_idx)
407 );
408 
409 #endif /* _TRACE_COMPACTION_H */
410 
411 /* This part must be outside protection */
412 #include <trace/define_trace.h>
413