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 int lru), 289 290 TP_ARGS(highest_zoneidx, order, nr_requested, nr_scanned, nr_skipped, nr_taken, lru), 291 292 TP_STRUCT__entry( 293 __field(int, highest_zoneidx) 294 __field(int, order) 295 __field(unsigned long, nr_requested) 296 __field(unsigned long, nr_scanned) 297 __field(unsigned long, nr_skipped) 298 __field(unsigned long, nr_taken) 299 __field(int, lru) 300 ), 301 302 TP_fast_assign( 303 __entry->highest_zoneidx = highest_zoneidx; 304 __entry->order = order; 305 __entry->nr_requested = nr_requested; 306 __entry->nr_scanned = nr_scanned; 307 __entry->nr_skipped = nr_skipped; 308 __entry->nr_taken = nr_taken; 309 __entry->lru = lru; 310 ), 311 312 /* 313 * classzone is previous name of the highest_zoneidx. 314 * Reason not to change it is the ABI requirement of the tracepoint. 315 */ 316 TP_printk("classzone=%d order=%d nr_requested=%lu nr_scanned=%lu nr_skipped=%lu nr_taken=%lu lru=%s", 317 __entry->highest_zoneidx, 318 __entry->order, 319 __entry->nr_requested, 320 __entry->nr_scanned, 321 __entry->nr_skipped, 322 __entry->nr_taken, 323 __print_symbolic(__entry->lru, LRU_NAMES)) 324 ); 325 326 TRACE_EVENT(mm_vmscan_write_folio, 327 328 TP_PROTO(struct folio *folio), 329 330 TP_ARGS(folio), 331 332 TP_STRUCT__entry( 333 __field(unsigned long, pfn) 334 __field(int, reclaim_flags) 335 ), 336 337 TP_fast_assign( 338 __entry->pfn = folio_pfn(folio); 339 __entry->reclaim_flags = trace_reclaim_flags( 340 folio_is_file_lru(folio)); 341 ), 342 343 TP_printk("page=%p pfn=0x%lx flags=%s", 344 pfn_to_page(__entry->pfn), 345 __entry->pfn, 346 show_reclaim_flags(__entry->reclaim_flags)) 347 ); 348 349 TRACE_EVENT(mm_vmscan_reclaim_pages, 350 351 TP_PROTO(int nid, 352 unsigned long nr_scanned, unsigned long nr_reclaimed, 353 struct reclaim_stat *stat), 354 355 TP_ARGS(nid, nr_scanned, nr_reclaimed, stat), 356 357 TP_STRUCT__entry( 358 __field(int, nid) 359 __field(unsigned long, nr_scanned) 360 __field(unsigned long, nr_reclaimed) 361 __field(unsigned long, nr_dirty) 362 __field(unsigned long, nr_writeback) 363 __field(unsigned long, nr_congested) 364 __field(unsigned long, nr_immediate) 365 __field(unsigned int, nr_activate0) 366 __field(unsigned int, nr_activate1) 367 __field(unsigned long, nr_ref_keep) 368 __field(unsigned long, nr_unmap_fail) 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 = stat->nr_dirty; 376 __entry->nr_writeback = stat->nr_writeback; 377 __entry->nr_congested = stat->nr_congested; 378 __entry->nr_immediate = stat->nr_immediate; 379 __entry->nr_activate0 = stat->nr_activate[0]; 380 __entry->nr_activate1 = stat->nr_activate[1]; 381 __entry->nr_ref_keep = stat->nr_ref_keep; 382 __entry->nr_unmap_fail = stat->nr_unmap_fail; 383 ), 384 385 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", 386 __entry->nid, 387 __entry->nr_scanned, __entry->nr_reclaimed, 388 __entry->nr_dirty, __entry->nr_writeback, 389 __entry->nr_congested, __entry->nr_immediate, 390 __entry->nr_activate0, __entry->nr_activate1, 391 __entry->nr_ref_keep, __entry->nr_unmap_fail) 392 ); 393 394 TRACE_EVENT(mm_vmscan_lru_shrink_inactive, 395 396 TP_PROTO(int nid, 397 unsigned long nr_scanned, unsigned long nr_reclaimed, 398 struct reclaim_stat *stat, int priority, int file), 399 400 TP_ARGS(nid, nr_scanned, nr_reclaimed, stat, priority, file), 401 402 TP_STRUCT__entry( 403 __field(int, nid) 404 __field(unsigned long, nr_scanned) 405 __field(unsigned long, nr_reclaimed) 406 __field(unsigned long, nr_dirty) 407 __field(unsigned long, nr_writeback) 408 __field(unsigned long, nr_congested) 409 __field(unsigned long, nr_immediate) 410 __field(unsigned int, nr_activate0) 411 __field(unsigned int, nr_activate1) 412 __field(unsigned long, nr_ref_keep) 413 __field(unsigned long, nr_unmap_fail) 414 __field(int, priority) 415 __field(int, reclaim_flags) 416 ), 417 418 TP_fast_assign( 419 __entry->nid = nid; 420 __entry->nr_scanned = nr_scanned; 421 __entry->nr_reclaimed = nr_reclaimed; 422 __entry->nr_dirty = stat->nr_dirty; 423 __entry->nr_writeback = stat->nr_writeback; 424 __entry->nr_congested = stat->nr_congested; 425 __entry->nr_immediate = stat->nr_immediate; 426 __entry->nr_activate0 = stat->nr_activate[0]; 427 __entry->nr_activate1 = stat->nr_activate[1]; 428 __entry->nr_ref_keep = stat->nr_ref_keep; 429 __entry->nr_unmap_fail = stat->nr_unmap_fail; 430 __entry->priority = priority; 431 __entry->reclaim_flags = trace_reclaim_flags(file); 432 ), 433 434 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", 435 __entry->nid, 436 __entry->nr_scanned, __entry->nr_reclaimed, 437 __entry->nr_dirty, __entry->nr_writeback, 438 __entry->nr_congested, __entry->nr_immediate, 439 __entry->nr_activate0, __entry->nr_activate1, 440 __entry->nr_ref_keep, __entry->nr_unmap_fail, 441 __entry->priority, 442 show_reclaim_flags(__entry->reclaim_flags)) 443 ); 444 445 TRACE_EVENT(mm_vmscan_lru_shrink_active, 446 447 TP_PROTO(int nid, unsigned long nr_taken, 448 unsigned long nr_active, unsigned long nr_deactivated, 449 unsigned long nr_referenced, int priority, int file), 450 451 TP_ARGS(nid, nr_taken, nr_active, nr_deactivated, nr_referenced, priority, file), 452 453 TP_STRUCT__entry( 454 __field(int, nid) 455 __field(unsigned long, nr_taken) 456 __field(unsigned long, nr_active) 457 __field(unsigned long, nr_deactivated) 458 __field(unsigned long, nr_referenced) 459 __field(int, priority) 460 __field(int, reclaim_flags) 461 ), 462 463 TP_fast_assign( 464 __entry->nid = nid; 465 __entry->nr_taken = nr_taken; 466 __entry->nr_active = nr_active; 467 __entry->nr_deactivated = nr_deactivated; 468 __entry->nr_referenced = nr_referenced; 469 __entry->priority = priority; 470 __entry->reclaim_flags = trace_reclaim_flags(file); 471 ), 472 473 TP_printk("nid=%d nr_taken=%ld nr_active=%ld nr_deactivated=%ld nr_referenced=%ld priority=%d flags=%s", 474 __entry->nid, 475 __entry->nr_taken, 476 __entry->nr_active, __entry->nr_deactivated, __entry->nr_referenced, 477 __entry->priority, 478 show_reclaim_flags(__entry->reclaim_flags)) 479 ); 480 481 TRACE_EVENT(mm_vmscan_node_reclaim_begin, 482 483 TP_PROTO(int nid, int order, gfp_t gfp_flags), 484 485 TP_ARGS(nid, order, gfp_flags), 486 487 TP_STRUCT__entry( 488 __field(int, nid) 489 __field(int, order) 490 __field(unsigned long, gfp_flags) 491 ), 492 493 TP_fast_assign( 494 __entry->nid = nid; 495 __entry->order = order; 496 __entry->gfp_flags = (__force unsigned long)gfp_flags; 497 ), 498 499 TP_printk("nid=%d order=%d gfp_flags=%s", 500 __entry->nid, 501 __entry->order, 502 show_gfp_flags(__entry->gfp_flags)) 503 ); 504 505 DEFINE_EVENT(mm_vmscan_direct_reclaim_end_template, mm_vmscan_node_reclaim_end, 506 507 TP_PROTO(unsigned long nr_reclaimed), 508 509 TP_ARGS(nr_reclaimed) 510 ); 511 512 TRACE_EVENT(mm_vmscan_throttled, 513 514 TP_PROTO(int nid, int usec_timeout, int usec_delayed, int reason), 515 516 TP_ARGS(nid, usec_timeout, usec_delayed, reason), 517 518 TP_STRUCT__entry( 519 __field(int, nid) 520 __field(int, usec_timeout) 521 __field(int, usec_delayed) 522 __field(int, reason) 523 ), 524 525 TP_fast_assign( 526 __entry->nid = nid; 527 __entry->usec_timeout = usec_timeout; 528 __entry->usec_delayed = usec_delayed; 529 __entry->reason = 1U << reason; 530 ), 531 532 TP_printk("nid=%d usec_timeout=%d usect_delayed=%d reason=%s", 533 __entry->nid, 534 __entry->usec_timeout, 535 __entry->usec_delayed, 536 show_throttle_flags(__entry->reason)) 537 ); 538 #endif /* _TRACE_VMSCAN_H */ 539 540 /* This part must be outside protection */ 541 #include <trace/define_trace.h> 542