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