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/gfpflags.h>
11 
12 DECLARE_EVENT_CLASS(mm_compaction_isolate_template,
13 
14 	TP_PROTO(
15 		unsigned long start_pfn,
16 		unsigned long end_pfn,
17 		unsigned long nr_scanned,
18 		unsigned long nr_taken),
19 
20 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken),
21 
22 	TP_STRUCT__entry(
23 		__field(unsigned long, start_pfn)
24 		__field(unsigned long, end_pfn)
25 		__field(unsigned long, nr_scanned)
26 		__field(unsigned long, nr_taken)
27 	),
28 
29 	TP_fast_assign(
30 		__entry->start_pfn = start_pfn;
31 		__entry->end_pfn = end_pfn;
32 		__entry->nr_scanned = nr_scanned;
33 		__entry->nr_taken = nr_taken;
34 	),
35 
36 	TP_printk("range=(0x%lx ~ 0x%lx) nr_scanned=%lu nr_taken=%lu",
37 		__entry->start_pfn,
38 		__entry->end_pfn,
39 		__entry->nr_scanned,
40 		__entry->nr_taken)
41 );
42 
43 DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_isolate_migratepages,
44 
45 	TP_PROTO(
46 		unsigned long start_pfn,
47 		unsigned long end_pfn,
48 		unsigned long nr_scanned,
49 		unsigned long nr_taken),
50 
51 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken)
52 );
53 
54 DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_isolate_freepages,
55 
56 	TP_PROTO(
57 		unsigned long start_pfn,
58 		unsigned long end_pfn,
59 		unsigned long nr_scanned,
60 		unsigned long nr_taken),
61 
62 	TP_ARGS(start_pfn, end_pfn, nr_scanned, nr_taken)
63 );
64 
65 TRACE_EVENT(mm_compaction_migratepages,
66 
67 	TP_PROTO(unsigned long nr_all,
68 		int migrate_rc,
69 		struct list_head *migratepages),
70 
71 	TP_ARGS(nr_all, migrate_rc, migratepages),
72 
73 	TP_STRUCT__entry(
74 		__field(unsigned long, nr_migrated)
75 		__field(unsigned long, nr_failed)
76 	),
77 
78 	TP_fast_assign(
79 		unsigned long nr_failed = 0;
80 		struct list_head *page_lru;
81 
82 		/*
83 		 * migrate_pages() returns either a non-negative number
84 		 * with the number of pages that failed migration, or an
85 		 * error code, in which case we need to count the remaining
86 		 * pages manually
87 		 */
88 		if (migrate_rc >= 0)
89 			nr_failed = migrate_rc;
90 		else
91 			list_for_each(page_lru, migratepages)
92 				nr_failed++;
93 
94 		__entry->nr_migrated = nr_all - nr_failed;
95 		__entry->nr_failed = nr_failed;
96 	),
97 
98 	TP_printk("nr_migrated=%lu nr_failed=%lu",
99 		__entry->nr_migrated,
100 		__entry->nr_failed)
101 );
102 
103 TRACE_EVENT(mm_compaction_begin,
104 	TP_PROTO(unsigned long zone_start, unsigned long migrate_pfn,
105 		unsigned long free_pfn, unsigned long zone_end, bool sync),
106 
107 	TP_ARGS(zone_start, migrate_pfn, free_pfn, zone_end, sync),
108 
109 	TP_STRUCT__entry(
110 		__field(unsigned long, zone_start)
111 		__field(unsigned long, migrate_pfn)
112 		__field(unsigned long, free_pfn)
113 		__field(unsigned long, zone_end)
114 		__field(bool, sync)
115 	),
116 
117 	TP_fast_assign(
118 		__entry->zone_start = zone_start;
119 		__entry->migrate_pfn = migrate_pfn;
120 		__entry->free_pfn = free_pfn;
121 		__entry->zone_end = zone_end;
122 		__entry->sync = sync;
123 	),
124 
125 	TP_printk("zone_start=0x%lx migrate_pfn=0x%lx free_pfn=0x%lx zone_end=0x%lx, mode=%s",
126 		__entry->zone_start,
127 		__entry->migrate_pfn,
128 		__entry->free_pfn,
129 		__entry->zone_end,
130 		__entry->sync ? "sync" : "async")
131 );
132 
133 TRACE_EVENT(mm_compaction_end,
134 	TP_PROTO(unsigned long zone_start, unsigned long migrate_pfn,
135 		unsigned long free_pfn, unsigned long zone_end, bool sync,
136 		int status),
137 
138 	TP_ARGS(zone_start, migrate_pfn, free_pfn, zone_end, sync, status),
139 
140 	TP_STRUCT__entry(
141 		__field(unsigned long, zone_start)
142 		__field(unsigned long, migrate_pfn)
143 		__field(unsigned long, free_pfn)
144 		__field(unsigned long, zone_end)
145 		__field(bool, sync)
146 		__field(int, status)
147 	),
148 
149 	TP_fast_assign(
150 		__entry->zone_start = zone_start;
151 		__entry->migrate_pfn = migrate_pfn;
152 		__entry->free_pfn = free_pfn;
153 		__entry->zone_end = zone_end;
154 		__entry->sync = sync;
155 		__entry->status = status;
156 	),
157 
158 	TP_printk("zone_start=0x%lx migrate_pfn=0x%lx free_pfn=0x%lx zone_end=0x%lx, mode=%s status=%s",
159 		__entry->zone_start,
160 		__entry->migrate_pfn,
161 		__entry->free_pfn,
162 		__entry->zone_end,
163 		__entry->sync ? "sync" : "async",
164 		compaction_status_string[__entry->status])
165 );
166 
167 TRACE_EVENT(mm_compaction_try_to_compact_pages,
168 
169 	TP_PROTO(
170 		int order,
171 		gfp_t gfp_mask,
172 		enum migrate_mode mode),
173 
174 	TP_ARGS(order, gfp_mask, mode),
175 
176 	TP_STRUCT__entry(
177 		__field(int, order)
178 		__field(gfp_t, gfp_mask)
179 		__field(enum migrate_mode, mode)
180 	),
181 
182 	TP_fast_assign(
183 		__entry->order = order;
184 		__entry->gfp_mask = gfp_mask;
185 		__entry->mode = mode;
186 	),
187 
188 	TP_printk("order=%d gfp_mask=0x%x mode=%d",
189 		__entry->order,
190 		__entry->gfp_mask,
191 		(int)__entry->mode)
192 );
193 
194 DECLARE_EVENT_CLASS(mm_compaction_suitable_template,
195 
196 	TP_PROTO(struct zone *zone,
197 		int order,
198 		int ret),
199 
200 	TP_ARGS(zone, order, ret),
201 
202 	TP_STRUCT__entry(
203 		__field(int, nid)
204 		__field(char *, name)
205 		__field(int, order)
206 		__field(int, ret)
207 	),
208 
209 	TP_fast_assign(
210 		__entry->nid = zone_to_nid(zone);
211 		__entry->name = (char *)zone->name;
212 		__entry->order = order;
213 		__entry->ret = ret;
214 	),
215 
216 	TP_printk("node=%d zone=%-8s order=%d ret=%s",
217 		__entry->nid,
218 		__entry->name,
219 		__entry->order,
220 		compaction_status_string[__entry->ret])
221 );
222 
223 DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_finished,
224 
225 	TP_PROTO(struct zone *zone,
226 		int order,
227 		int ret),
228 
229 	TP_ARGS(zone, order, ret)
230 );
231 
232 DEFINE_EVENT(mm_compaction_suitable_template, mm_compaction_suitable,
233 
234 	TP_PROTO(struct zone *zone,
235 		int order,
236 		int ret),
237 
238 	TP_ARGS(zone, order, ret)
239 );
240 
241 #ifdef CONFIG_COMPACTION
242 DECLARE_EVENT_CLASS(mm_compaction_defer_template,
243 
244 	TP_PROTO(struct zone *zone, int order),
245 
246 	TP_ARGS(zone, order),
247 
248 	TP_STRUCT__entry(
249 		__field(int, nid)
250 		__field(char *, name)
251 		__field(int, order)
252 		__field(unsigned int, considered)
253 		__field(unsigned int, defer_shift)
254 		__field(int, order_failed)
255 	),
256 
257 	TP_fast_assign(
258 		__entry->nid = zone_to_nid(zone);
259 		__entry->name = (char *)zone->name;
260 		__entry->order = order;
261 		__entry->considered = zone->compact_considered;
262 		__entry->defer_shift = zone->compact_defer_shift;
263 		__entry->order_failed = zone->compact_order_failed;
264 	),
265 
266 	TP_printk("node=%d zone=%-8s order=%d order_failed=%d consider=%u limit=%lu",
267 		__entry->nid,
268 		__entry->name,
269 		__entry->order,
270 		__entry->order_failed,
271 		__entry->considered,
272 		1UL << __entry->defer_shift)
273 );
274 
275 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_deferred,
276 
277 	TP_PROTO(struct zone *zone, int order),
278 
279 	TP_ARGS(zone, order)
280 );
281 
282 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_defer_compaction,
283 
284 	TP_PROTO(struct zone *zone, int order),
285 
286 	TP_ARGS(zone, order)
287 );
288 
289 DEFINE_EVENT(mm_compaction_defer_template, mm_compaction_defer_reset,
290 
291 	TP_PROTO(struct zone *zone, int order),
292 
293 	TP_ARGS(zone, order)
294 );
295 #endif
296 
297 #endif /* _TRACE_COMPACTION_H */
298 
299 /* This part must be outside protection */
300 #include <trace/define_trace.h>
301