1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM vmscan
3 
4 #if !defined(_TRACE_VMSCAN_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_VMSCAN_H
6 
7 #include <linux/types.h>
8 #include <linux/tracepoint.h>
9 #include <linux/mm.h>
10 #include <linux/memcontrol.h>
11 #include "gfpflags.h"
12 
13 #define RECLAIM_WB_ANON		0x0001u
14 #define RECLAIM_WB_FILE		0x0002u
15 #define RECLAIM_WB_MIXED	0x0010u
16 #define RECLAIM_WB_SYNC		0x0004u
17 #define RECLAIM_WB_ASYNC	0x0008u
18 
19 #define show_reclaim_flags(flags)				\
20 	(flags) ? __print_flags(flags, "|",			\
21 		{RECLAIM_WB_ANON,	"RECLAIM_WB_ANON"},	\
22 		{RECLAIM_WB_FILE,	"RECLAIM_WB_FILE"},	\
23 		{RECLAIM_WB_MIXED,	"RECLAIM_WB_MIXED"},	\
24 		{RECLAIM_WB_SYNC,	"RECLAIM_WB_SYNC"},	\
25 		{RECLAIM_WB_ASYNC,	"RECLAIM_WB_ASYNC"}	\
26 		) : "RECLAIM_WB_NONE"
27 
28 #define trace_reclaim_flags(page, sync) ( \
29 	(page_is_file_cache(page) ? RECLAIM_WB_FILE : RECLAIM_WB_ANON) | \
30 	(sync & RECLAIM_MODE_SYNC ? RECLAIM_WB_SYNC : RECLAIM_WB_ASYNC)   \
31 	)
32 
33 #define trace_shrink_flags(file, sync) ( \
34 	(sync & RECLAIM_MODE_SYNC ? RECLAIM_WB_MIXED : \
35 			(file ? RECLAIM_WB_FILE : RECLAIM_WB_ANON)) |  \
36 	(sync & RECLAIM_MODE_SYNC ? RECLAIM_WB_SYNC : RECLAIM_WB_ASYNC) \
37 	)
38 
39 TRACE_EVENT(mm_vmscan_kswapd_sleep,
40 
41 	TP_PROTO(int nid),
42 
43 	TP_ARGS(nid),
44 
45 	TP_STRUCT__entry(
46 		__field(	int,	nid	)
47 	),
48 
49 	TP_fast_assign(
50 		__entry->nid	= nid;
51 	),
52 
53 	TP_printk("nid=%d", __entry->nid)
54 );
55 
56 TRACE_EVENT(mm_vmscan_kswapd_wake,
57 
58 	TP_PROTO(int nid, int order),
59 
60 	TP_ARGS(nid, order),
61 
62 	TP_STRUCT__entry(
63 		__field(	int,	nid	)
64 		__field(	int,	order	)
65 	),
66 
67 	TP_fast_assign(
68 		__entry->nid	= nid;
69 		__entry->order	= order;
70 	),
71 
72 	TP_printk("nid=%d order=%d", __entry->nid, __entry->order)
73 );
74 
75 TRACE_EVENT(mm_vmscan_wakeup_kswapd,
76 
77 	TP_PROTO(int nid, int zid, int order),
78 
79 	TP_ARGS(nid, zid, order),
80 
81 	TP_STRUCT__entry(
82 		__field(	int,		nid	)
83 		__field(	int,		zid	)
84 		__field(	int,		order	)
85 	),
86 
87 	TP_fast_assign(
88 		__entry->nid		= nid;
89 		__entry->zid		= zid;
90 		__entry->order		= order;
91 	),
92 
93 	TP_printk("nid=%d zid=%d order=%d",
94 		__entry->nid,
95 		__entry->zid,
96 		__entry->order)
97 );
98 
99 DECLARE_EVENT_CLASS(mm_vmscan_direct_reclaim_begin_template,
100 
101 	TP_PROTO(int order, int may_writepage, gfp_t gfp_flags),
102 
103 	TP_ARGS(order, may_writepage, gfp_flags),
104 
105 	TP_STRUCT__entry(
106 		__field(	int,	order		)
107 		__field(	int,	may_writepage	)
108 		__field(	gfp_t,	gfp_flags	)
109 	),
110 
111 	TP_fast_assign(
112 		__entry->order		= order;
113 		__entry->may_writepage	= may_writepage;
114 		__entry->gfp_flags	= gfp_flags;
115 	),
116 
117 	TP_printk("order=%d may_writepage=%d gfp_flags=%s",
118 		__entry->order,
119 		__entry->may_writepage,
120 		show_gfp_flags(__entry->gfp_flags))
121 );
122 
123 DEFINE_EVENT(mm_vmscan_direct_reclaim_begin_template, mm_vmscan_direct_reclaim_begin,
124 
125 	TP_PROTO(int order, int may_writepage, gfp_t gfp_flags),
126 
127 	TP_ARGS(order, may_writepage, gfp_flags)
128 );
129 
130 DEFINE_EVENT(mm_vmscan_direct_reclaim_begin_template, mm_vmscan_memcg_reclaim_begin,
131 
132 	TP_PROTO(int order, int may_writepage, gfp_t gfp_flags),
133 
134 	TP_ARGS(order, may_writepage, gfp_flags)
135 );
136 
137 DEFINE_EVENT(mm_vmscan_direct_reclaim_begin_template, mm_vmscan_memcg_softlimit_reclaim_begin,
138 
139 	TP_PROTO(int order, int may_writepage, gfp_t gfp_flags),
140 
141 	TP_ARGS(order, may_writepage, gfp_flags)
142 );
143 
144 DECLARE_EVENT_CLASS(mm_vmscan_direct_reclaim_end_template,
145 
146 	TP_PROTO(unsigned long nr_reclaimed),
147 
148 	TP_ARGS(nr_reclaimed),
149 
150 	TP_STRUCT__entry(
151 		__field(	unsigned long,	nr_reclaimed	)
152 	),
153 
154 	TP_fast_assign(
155 		__entry->nr_reclaimed	= nr_reclaimed;
156 	),
157 
158 	TP_printk("nr_reclaimed=%lu", __entry->nr_reclaimed)
159 );
160 
161 DEFINE_EVENT(mm_vmscan_direct_reclaim_end_template, mm_vmscan_direct_reclaim_end,
162 
163 	TP_PROTO(unsigned long nr_reclaimed),
164 
165 	TP_ARGS(nr_reclaimed)
166 );
167 
168 DEFINE_EVENT(mm_vmscan_direct_reclaim_end_template, mm_vmscan_memcg_reclaim_end,
169 
170 	TP_PROTO(unsigned long nr_reclaimed),
171 
172 	TP_ARGS(nr_reclaimed)
173 );
174 
175 DEFINE_EVENT(mm_vmscan_direct_reclaim_end_template, mm_vmscan_memcg_softlimit_reclaim_end,
176 
177 	TP_PROTO(unsigned long nr_reclaimed),
178 
179 	TP_ARGS(nr_reclaimed)
180 );
181 
182 TRACE_EVENT(mm_shrink_slab_start,
183 	TP_PROTO(struct shrinker *shr, struct shrink_control *sc,
184 		long nr_objects_to_shrink, unsigned long pgs_scanned,
185 		unsigned long lru_pgs, unsigned long cache_items,
186 		unsigned long long delta, unsigned long total_scan),
187 
188 	TP_ARGS(shr, sc, nr_objects_to_shrink, pgs_scanned, lru_pgs,
189 		cache_items, delta, total_scan),
190 
191 	TP_STRUCT__entry(
192 		__field(struct shrinker *, shr)
193 		__field(void *, shrink)
194 		__field(long, nr_objects_to_shrink)
195 		__field(gfp_t, gfp_flags)
196 		__field(unsigned long, pgs_scanned)
197 		__field(unsigned long, lru_pgs)
198 		__field(unsigned long, cache_items)
199 		__field(unsigned long long, delta)
200 		__field(unsigned long, total_scan)
201 	),
202 
203 	TP_fast_assign(
204 		__entry->shr = shr;
205 		__entry->shrink = shr->shrink;
206 		__entry->nr_objects_to_shrink = nr_objects_to_shrink;
207 		__entry->gfp_flags = sc->gfp_mask;
208 		__entry->pgs_scanned = pgs_scanned;
209 		__entry->lru_pgs = lru_pgs;
210 		__entry->cache_items = cache_items;
211 		__entry->delta = delta;
212 		__entry->total_scan = total_scan;
213 	),
214 
215 	TP_printk("%pF %p: objects to shrink %ld gfp_flags %s pgs_scanned %ld lru_pgs %ld cache items %ld delta %lld total_scan %ld",
216 		__entry->shrink,
217 		__entry->shr,
218 		__entry->nr_objects_to_shrink,
219 		show_gfp_flags(__entry->gfp_flags),
220 		__entry->pgs_scanned,
221 		__entry->lru_pgs,
222 		__entry->cache_items,
223 		__entry->delta,
224 		__entry->total_scan)
225 );
226 
227 TRACE_EVENT(mm_shrink_slab_end,
228 	TP_PROTO(struct shrinker *shr, int shrinker_retval,
229 		long unused_scan_cnt, long new_scan_cnt),
230 
231 	TP_ARGS(shr, shrinker_retval, unused_scan_cnt, new_scan_cnt),
232 
233 	TP_STRUCT__entry(
234 		__field(struct shrinker *, shr)
235 		__field(void *, shrink)
236 		__field(long, unused_scan)
237 		__field(long, new_scan)
238 		__field(int, retval)
239 		__field(long, total_scan)
240 	),
241 
242 	TP_fast_assign(
243 		__entry->shr = shr;
244 		__entry->shrink = shr->shrink;
245 		__entry->unused_scan = unused_scan_cnt;
246 		__entry->new_scan = new_scan_cnt;
247 		__entry->retval = shrinker_retval;
248 		__entry->total_scan = new_scan_cnt - unused_scan_cnt;
249 	),
250 
251 	TP_printk("%pF %p: unused scan count %ld new scan count %ld total_scan %ld last shrinker return val %d",
252 		__entry->shrink,
253 		__entry->shr,
254 		__entry->unused_scan,
255 		__entry->new_scan,
256 		__entry->total_scan,
257 		__entry->retval)
258 );
259 
260 DECLARE_EVENT_CLASS(mm_vmscan_lru_isolate_template,
261 
262 	TP_PROTO(int order,
263 		unsigned long nr_requested,
264 		unsigned long nr_scanned,
265 		unsigned long nr_taken,
266 		unsigned long nr_lumpy_taken,
267 		unsigned long nr_lumpy_dirty,
268 		unsigned long nr_lumpy_failed,
269 		isolate_mode_t isolate_mode,
270 		int file),
271 
272 	TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode, file),
273 
274 	TP_STRUCT__entry(
275 		__field(int, order)
276 		__field(unsigned long, nr_requested)
277 		__field(unsigned long, nr_scanned)
278 		__field(unsigned long, nr_taken)
279 		__field(unsigned long, nr_lumpy_taken)
280 		__field(unsigned long, nr_lumpy_dirty)
281 		__field(unsigned long, nr_lumpy_failed)
282 		__field(isolate_mode_t, isolate_mode)
283 		__field(int, file)
284 	),
285 
286 	TP_fast_assign(
287 		__entry->order = order;
288 		__entry->nr_requested = nr_requested;
289 		__entry->nr_scanned = nr_scanned;
290 		__entry->nr_taken = nr_taken;
291 		__entry->nr_lumpy_taken = nr_lumpy_taken;
292 		__entry->nr_lumpy_dirty = nr_lumpy_dirty;
293 		__entry->nr_lumpy_failed = nr_lumpy_failed;
294 		__entry->isolate_mode = isolate_mode;
295 		__entry->file = file;
296 	),
297 
298 	TP_printk("isolate_mode=%d order=%d nr_requested=%lu nr_scanned=%lu nr_taken=%lu contig_taken=%lu contig_dirty=%lu contig_failed=%lu file=%d",
299 		__entry->isolate_mode,
300 		__entry->order,
301 		__entry->nr_requested,
302 		__entry->nr_scanned,
303 		__entry->nr_taken,
304 		__entry->nr_lumpy_taken,
305 		__entry->nr_lumpy_dirty,
306 		__entry->nr_lumpy_failed,
307 		__entry->file)
308 );
309 
310 DEFINE_EVENT(mm_vmscan_lru_isolate_template, mm_vmscan_lru_isolate,
311 
312 	TP_PROTO(int order,
313 		unsigned long nr_requested,
314 		unsigned long nr_scanned,
315 		unsigned long nr_taken,
316 		unsigned long nr_lumpy_taken,
317 		unsigned long nr_lumpy_dirty,
318 		unsigned long nr_lumpy_failed,
319 		isolate_mode_t isolate_mode,
320 		int file),
321 
322 	TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode, file)
323 
324 );
325 
326 DEFINE_EVENT(mm_vmscan_lru_isolate_template, mm_vmscan_memcg_isolate,
327 
328 	TP_PROTO(int order,
329 		unsigned long nr_requested,
330 		unsigned long nr_scanned,
331 		unsigned long nr_taken,
332 		unsigned long nr_lumpy_taken,
333 		unsigned long nr_lumpy_dirty,
334 		unsigned long nr_lumpy_failed,
335 		isolate_mode_t isolate_mode,
336 		int file),
337 
338 	TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode, file)
339 
340 );
341 
342 TRACE_EVENT(mm_vmscan_writepage,
343 
344 	TP_PROTO(struct page *page,
345 		int reclaim_flags),
346 
347 	TP_ARGS(page, reclaim_flags),
348 
349 	TP_STRUCT__entry(
350 		__field(struct page *, page)
351 		__field(int, reclaim_flags)
352 	),
353 
354 	TP_fast_assign(
355 		__entry->page = page;
356 		__entry->reclaim_flags = reclaim_flags;
357 	),
358 
359 	TP_printk("page=%p pfn=%lu flags=%s",
360 		__entry->page,
361 		page_to_pfn(__entry->page),
362 		show_reclaim_flags(__entry->reclaim_flags))
363 );
364 
365 TRACE_EVENT(mm_vmscan_lru_shrink_inactive,
366 
367 	TP_PROTO(int nid, int zid,
368 			unsigned long nr_scanned, unsigned long nr_reclaimed,
369 			int priority, int reclaim_flags),
370 
371 	TP_ARGS(nid, zid, nr_scanned, nr_reclaimed, priority, reclaim_flags),
372 
373 	TP_STRUCT__entry(
374 		__field(int, nid)
375 		__field(int, zid)
376 		__field(unsigned long, nr_scanned)
377 		__field(unsigned long, nr_reclaimed)
378 		__field(int, priority)
379 		__field(int, reclaim_flags)
380 	),
381 
382 	TP_fast_assign(
383 		__entry->nid = nid;
384 		__entry->zid = zid;
385 		__entry->nr_scanned = nr_scanned;
386 		__entry->nr_reclaimed = nr_reclaimed;
387 		__entry->priority = priority;
388 		__entry->reclaim_flags = reclaim_flags;
389 	),
390 
391 	TP_printk("nid=%d zid=%d nr_scanned=%ld nr_reclaimed=%ld priority=%d flags=%s",
392 		__entry->nid, __entry->zid,
393 		__entry->nr_scanned, __entry->nr_reclaimed,
394 		__entry->priority,
395 		show_reclaim_flags(__entry->reclaim_flags))
396 );
397 
398 TRACE_EVENT(replace_swap_token,
399 	TP_PROTO(struct mm_struct *old_mm,
400 		 struct mm_struct *new_mm),
401 
402 	TP_ARGS(old_mm, new_mm),
403 
404 	TP_STRUCT__entry(
405 		__field(struct mm_struct*,	old_mm)
406 		__field(unsigned int,		old_prio)
407 		__field(struct mm_struct*,	new_mm)
408 		__field(unsigned int,		new_prio)
409 	),
410 
411 	TP_fast_assign(
412 		__entry->old_mm   = old_mm;
413 		__entry->old_prio = old_mm ? old_mm->token_priority : 0;
414 		__entry->new_mm   = new_mm;
415 		__entry->new_prio = new_mm->token_priority;
416 	),
417 
418 	TP_printk("old_token_mm=%p old_prio=%u new_token_mm=%p new_prio=%u",
419 		  __entry->old_mm, __entry->old_prio,
420 		  __entry->new_mm, __entry->new_prio)
421 );
422 
423 DECLARE_EVENT_CLASS(put_swap_token_template,
424 	TP_PROTO(struct mm_struct *swap_token_mm),
425 
426 	TP_ARGS(swap_token_mm),
427 
428 	TP_STRUCT__entry(
429 		__field(struct mm_struct*, swap_token_mm)
430 	),
431 
432 	TP_fast_assign(
433 		__entry->swap_token_mm = swap_token_mm;
434 	),
435 
436 	TP_printk("token_mm=%p", __entry->swap_token_mm)
437 );
438 
439 DEFINE_EVENT(put_swap_token_template, put_swap_token,
440 	TP_PROTO(struct mm_struct *swap_token_mm),
441 	TP_ARGS(swap_token_mm)
442 );
443 
444 DEFINE_EVENT_CONDITION(put_swap_token_template, disable_swap_token,
445 	TP_PROTO(struct mm_struct *swap_token_mm),
446 	TP_ARGS(swap_token_mm),
447 	TP_CONDITION(swap_token_mm != NULL)
448 );
449 
450 TRACE_EVENT_CONDITION(update_swap_token_priority,
451 	TP_PROTO(struct mm_struct *mm,
452 		 unsigned int old_prio,
453 		 struct mm_struct *swap_token_mm),
454 
455 	TP_ARGS(mm, old_prio, swap_token_mm),
456 
457 	TP_CONDITION(mm->token_priority != old_prio),
458 
459 	TP_STRUCT__entry(
460 		__field(struct mm_struct*, mm)
461 		__field(unsigned int, old_prio)
462 		__field(unsigned int, new_prio)
463 		__field(struct mm_struct*, swap_token_mm)
464 		__field(unsigned int, swap_token_prio)
465 	),
466 
467 	TP_fast_assign(
468 		__entry->mm		= mm;
469 		__entry->old_prio	= old_prio;
470 		__entry->new_prio	= mm->token_priority;
471 		__entry->swap_token_mm	= swap_token_mm;
472 		__entry->swap_token_prio = swap_token_mm ? swap_token_mm->token_priority : 0;
473 	),
474 
475 	TP_printk("mm=%p old_prio=%u new_prio=%u swap_token_mm=%p token_prio=%u",
476 		  __entry->mm, __entry->old_prio, __entry->new_prio,
477 		  __entry->swap_token_mm, __entry->swap_token_prio)
478 );
479 
480 #endif /* _TRACE_VMSCAN_H */
481 
482 /* This part must be outside protection */
483 #include <trace/define_trace.h>
484