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