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