1 #undef TRACE_SYSTEM 2 #define TRACE_SYSTEM writeback 3 4 #if !defined(_TRACE_WRITEBACK_H) || defined(TRACE_HEADER_MULTI_READ) 5 #define _TRACE_WRITEBACK_H 6 7 #include <linux/backing-dev.h> 8 #include <linux/writeback.h> 9 10 #define show_inode_state(state) \ 11 __print_flags(state, "|", \ 12 {I_DIRTY_SYNC, "I_DIRTY_SYNC"}, \ 13 {I_DIRTY_DATASYNC, "I_DIRTY_DATASYNC"}, \ 14 {I_DIRTY_PAGES, "I_DIRTY_PAGES"}, \ 15 {I_NEW, "I_NEW"}, \ 16 {I_WILL_FREE, "I_WILL_FREE"}, \ 17 {I_FREEING, "I_FREEING"}, \ 18 {I_CLEAR, "I_CLEAR"}, \ 19 {I_SYNC, "I_SYNC"}, \ 20 {I_REFERENCED, "I_REFERENCED"} \ 21 ) 22 23 #define WB_WORK_REASON \ 24 {WB_REASON_BACKGROUND, "background"}, \ 25 {WB_REASON_TRY_TO_FREE_PAGES, "try_to_free_pages"}, \ 26 {WB_REASON_SYNC, "sync"}, \ 27 {WB_REASON_PERIODIC, "periodic"}, \ 28 {WB_REASON_LAPTOP_TIMER, "laptop_timer"}, \ 29 {WB_REASON_FREE_MORE_MEM, "free_more_memory"}, \ 30 {WB_REASON_FS_FREE_SPACE, "fs_free_space"}, \ 31 {WB_REASON_FORKER_THREAD, "forker_thread"} 32 33 struct wb_writeback_work; 34 35 TRACE_EVENT(writeback_dirty_page, 36 37 TP_PROTO(struct page *page, struct address_space *mapping), 38 39 TP_ARGS(page, mapping), 40 41 TP_STRUCT__entry ( 42 __array(char, name, 32) 43 __field(unsigned long, ino) 44 __field(pgoff_t, index) 45 ), 46 47 TP_fast_assign( 48 strncpy(__entry->name, 49 mapping ? dev_name(mapping->backing_dev_info->dev) : "(unknown)", 32); 50 __entry->ino = mapping ? mapping->host->i_ino : 0; 51 __entry->index = page->index; 52 ), 53 54 TP_printk("bdi %s: ino=%lu index=%lu", 55 __entry->name, 56 __entry->ino, 57 __entry->index 58 ) 59 ); 60 61 DECLARE_EVENT_CLASS(writeback_dirty_inode_template, 62 63 TP_PROTO(struct inode *inode, int flags), 64 65 TP_ARGS(inode, flags), 66 67 TP_STRUCT__entry ( 68 __array(char, name, 32) 69 __field(unsigned long, ino) 70 __field(unsigned long, flags) 71 ), 72 73 TP_fast_assign( 74 struct backing_dev_info *bdi = inode->i_mapping->backing_dev_info; 75 76 /* may be called for files on pseudo FSes w/ unregistered bdi */ 77 strncpy(__entry->name, 78 bdi->dev ? dev_name(bdi->dev) : "(unknown)", 32); 79 __entry->ino = inode->i_ino; 80 __entry->flags = flags; 81 ), 82 83 TP_printk("bdi %s: ino=%lu flags=%s", 84 __entry->name, 85 __entry->ino, 86 show_inode_state(__entry->flags) 87 ) 88 ); 89 90 DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode_start, 91 92 TP_PROTO(struct inode *inode, int flags), 93 94 TP_ARGS(inode, flags) 95 ); 96 97 DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode, 98 99 TP_PROTO(struct inode *inode, int flags), 100 101 TP_ARGS(inode, flags) 102 ); 103 104 DECLARE_EVENT_CLASS(writeback_write_inode_template, 105 106 TP_PROTO(struct inode *inode, struct writeback_control *wbc), 107 108 TP_ARGS(inode, wbc), 109 110 TP_STRUCT__entry ( 111 __array(char, name, 32) 112 __field(unsigned long, ino) 113 __field(int, sync_mode) 114 ), 115 116 TP_fast_assign( 117 strncpy(__entry->name, 118 dev_name(inode->i_mapping->backing_dev_info->dev), 32); 119 __entry->ino = inode->i_ino; 120 __entry->sync_mode = wbc->sync_mode; 121 ), 122 123 TP_printk("bdi %s: ino=%lu sync_mode=%d", 124 __entry->name, 125 __entry->ino, 126 __entry->sync_mode 127 ) 128 ); 129 130 DEFINE_EVENT(writeback_write_inode_template, writeback_write_inode_start, 131 132 TP_PROTO(struct inode *inode, struct writeback_control *wbc), 133 134 TP_ARGS(inode, wbc) 135 ); 136 137 DEFINE_EVENT(writeback_write_inode_template, writeback_write_inode, 138 139 TP_PROTO(struct inode *inode, struct writeback_control *wbc), 140 141 TP_ARGS(inode, wbc) 142 ); 143 144 DECLARE_EVENT_CLASS(writeback_work_class, 145 TP_PROTO(struct backing_dev_info *bdi, struct wb_writeback_work *work), 146 TP_ARGS(bdi, work), 147 TP_STRUCT__entry( 148 __array(char, name, 32) 149 __field(long, nr_pages) 150 __field(dev_t, sb_dev) 151 __field(int, sync_mode) 152 __field(int, for_kupdate) 153 __field(int, range_cyclic) 154 __field(int, for_background) 155 __field(int, reason) 156 ), 157 TP_fast_assign( 158 struct device *dev = bdi->dev; 159 if (!dev) 160 dev = default_backing_dev_info.dev; 161 strncpy(__entry->name, dev_name(dev), 32); 162 __entry->nr_pages = work->nr_pages; 163 __entry->sb_dev = work->sb ? work->sb->s_dev : 0; 164 __entry->sync_mode = work->sync_mode; 165 __entry->for_kupdate = work->for_kupdate; 166 __entry->range_cyclic = work->range_cyclic; 167 __entry->for_background = work->for_background; 168 __entry->reason = work->reason; 169 ), 170 TP_printk("bdi %s: sb_dev %d:%d nr_pages=%ld sync_mode=%d " 171 "kupdate=%d range_cyclic=%d background=%d reason=%s", 172 __entry->name, 173 MAJOR(__entry->sb_dev), MINOR(__entry->sb_dev), 174 __entry->nr_pages, 175 __entry->sync_mode, 176 __entry->for_kupdate, 177 __entry->range_cyclic, 178 __entry->for_background, 179 __print_symbolic(__entry->reason, WB_WORK_REASON) 180 ) 181 ); 182 #define DEFINE_WRITEBACK_WORK_EVENT(name) \ 183 DEFINE_EVENT(writeback_work_class, name, \ 184 TP_PROTO(struct backing_dev_info *bdi, struct wb_writeback_work *work), \ 185 TP_ARGS(bdi, work)) 186 DEFINE_WRITEBACK_WORK_EVENT(writeback_queue); 187 DEFINE_WRITEBACK_WORK_EVENT(writeback_exec); 188 DEFINE_WRITEBACK_WORK_EVENT(writeback_start); 189 DEFINE_WRITEBACK_WORK_EVENT(writeback_written); 190 DEFINE_WRITEBACK_WORK_EVENT(writeback_wait); 191 192 TRACE_EVENT(writeback_pages_written, 193 TP_PROTO(long pages_written), 194 TP_ARGS(pages_written), 195 TP_STRUCT__entry( 196 __field(long, pages) 197 ), 198 TP_fast_assign( 199 __entry->pages = pages_written; 200 ), 201 TP_printk("%ld", __entry->pages) 202 ); 203 204 DECLARE_EVENT_CLASS(writeback_class, 205 TP_PROTO(struct backing_dev_info *bdi), 206 TP_ARGS(bdi), 207 TP_STRUCT__entry( 208 __array(char, name, 32) 209 ), 210 TP_fast_assign( 211 strncpy(__entry->name, dev_name(bdi->dev), 32); 212 ), 213 TP_printk("bdi %s", 214 __entry->name 215 ) 216 ); 217 #define DEFINE_WRITEBACK_EVENT(name) \ 218 DEFINE_EVENT(writeback_class, name, \ 219 TP_PROTO(struct backing_dev_info *bdi), \ 220 TP_ARGS(bdi)) 221 222 DEFINE_WRITEBACK_EVENT(writeback_nowork); 223 DEFINE_WRITEBACK_EVENT(writeback_wake_background); 224 DEFINE_WRITEBACK_EVENT(writeback_bdi_register); 225 DEFINE_WRITEBACK_EVENT(writeback_bdi_unregister); 226 227 DECLARE_EVENT_CLASS(wbc_class, 228 TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi), 229 TP_ARGS(wbc, bdi), 230 TP_STRUCT__entry( 231 __array(char, name, 32) 232 __field(long, nr_to_write) 233 __field(long, pages_skipped) 234 __field(int, sync_mode) 235 __field(int, for_kupdate) 236 __field(int, for_background) 237 __field(int, for_reclaim) 238 __field(int, range_cyclic) 239 __field(long, range_start) 240 __field(long, range_end) 241 ), 242 243 TP_fast_assign( 244 strncpy(__entry->name, dev_name(bdi->dev), 32); 245 __entry->nr_to_write = wbc->nr_to_write; 246 __entry->pages_skipped = wbc->pages_skipped; 247 __entry->sync_mode = wbc->sync_mode; 248 __entry->for_kupdate = wbc->for_kupdate; 249 __entry->for_background = wbc->for_background; 250 __entry->for_reclaim = wbc->for_reclaim; 251 __entry->range_cyclic = wbc->range_cyclic; 252 __entry->range_start = (long)wbc->range_start; 253 __entry->range_end = (long)wbc->range_end; 254 ), 255 256 TP_printk("bdi %s: towrt=%ld skip=%ld mode=%d kupd=%d " 257 "bgrd=%d reclm=%d cyclic=%d " 258 "start=0x%lx end=0x%lx", 259 __entry->name, 260 __entry->nr_to_write, 261 __entry->pages_skipped, 262 __entry->sync_mode, 263 __entry->for_kupdate, 264 __entry->for_background, 265 __entry->for_reclaim, 266 __entry->range_cyclic, 267 __entry->range_start, 268 __entry->range_end) 269 ) 270 271 #define DEFINE_WBC_EVENT(name) \ 272 DEFINE_EVENT(wbc_class, name, \ 273 TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi), \ 274 TP_ARGS(wbc, bdi)) 275 DEFINE_WBC_EVENT(wbc_writepage); 276 277 TRACE_EVENT(writeback_queue_io, 278 TP_PROTO(struct bdi_writeback *wb, 279 struct wb_writeback_work *work, 280 int moved), 281 TP_ARGS(wb, work, moved), 282 TP_STRUCT__entry( 283 __array(char, name, 32) 284 __field(unsigned long, older) 285 __field(long, age) 286 __field(int, moved) 287 __field(int, reason) 288 ), 289 TP_fast_assign( 290 unsigned long older_than_this = work->older_than_this; 291 strncpy(__entry->name, dev_name(wb->bdi->dev), 32); 292 __entry->older = older_than_this; 293 __entry->age = older_than_this ? 294 (jiffies - older_than_this) * 1000 / HZ : -1; 295 __entry->moved = moved; 296 __entry->reason = work->reason; 297 ), 298 TP_printk("bdi %s: older=%lu age=%ld enqueue=%d reason=%s", 299 __entry->name, 300 __entry->older, /* older_than_this in jiffies */ 301 __entry->age, /* older_than_this in relative milliseconds */ 302 __entry->moved, 303 __print_symbolic(__entry->reason, WB_WORK_REASON) 304 ) 305 ); 306 307 TRACE_EVENT(global_dirty_state, 308 309 TP_PROTO(unsigned long background_thresh, 310 unsigned long dirty_thresh 311 ), 312 313 TP_ARGS(background_thresh, 314 dirty_thresh 315 ), 316 317 TP_STRUCT__entry( 318 __field(unsigned long, nr_dirty) 319 __field(unsigned long, nr_writeback) 320 __field(unsigned long, nr_unstable) 321 __field(unsigned long, background_thresh) 322 __field(unsigned long, dirty_thresh) 323 __field(unsigned long, dirty_limit) 324 __field(unsigned long, nr_dirtied) 325 __field(unsigned long, nr_written) 326 ), 327 328 TP_fast_assign( 329 __entry->nr_dirty = global_page_state(NR_FILE_DIRTY); 330 __entry->nr_writeback = global_page_state(NR_WRITEBACK); 331 __entry->nr_unstable = global_page_state(NR_UNSTABLE_NFS); 332 __entry->nr_dirtied = global_page_state(NR_DIRTIED); 333 __entry->nr_written = global_page_state(NR_WRITTEN); 334 __entry->background_thresh = background_thresh; 335 __entry->dirty_thresh = dirty_thresh; 336 __entry->dirty_limit = global_dirty_limit; 337 ), 338 339 TP_printk("dirty=%lu writeback=%lu unstable=%lu " 340 "bg_thresh=%lu thresh=%lu limit=%lu " 341 "dirtied=%lu written=%lu", 342 __entry->nr_dirty, 343 __entry->nr_writeback, 344 __entry->nr_unstable, 345 __entry->background_thresh, 346 __entry->dirty_thresh, 347 __entry->dirty_limit, 348 __entry->nr_dirtied, 349 __entry->nr_written 350 ) 351 ); 352 353 #define KBps(x) ((x) << (PAGE_SHIFT - 10)) 354 355 TRACE_EVENT(bdi_dirty_ratelimit, 356 357 TP_PROTO(struct backing_dev_info *bdi, 358 unsigned long dirty_rate, 359 unsigned long task_ratelimit), 360 361 TP_ARGS(bdi, dirty_rate, task_ratelimit), 362 363 TP_STRUCT__entry( 364 __array(char, bdi, 32) 365 __field(unsigned long, write_bw) 366 __field(unsigned long, avg_write_bw) 367 __field(unsigned long, dirty_rate) 368 __field(unsigned long, dirty_ratelimit) 369 __field(unsigned long, task_ratelimit) 370 __field(unsigned long, balanced_dirty_ratelimit) 371 ), 372 373 TP_fast_assign( 374 strlcpy(__entry->bdi, dev_name(bdi->dev), 32); 375 __entry->write_bw = KBps(bdi->write_bandwidth); 376 __entry->avg_write_bw = KBps(bdi->avg_write_bandwidth); 377 __entry->dirty_rate = KBps(dirty_rate); 378 __entry->dirty_ratelimit = KBps(bdi->dirty_ratelimit); 379 __entry->task_ratelimit = KBps(task_ratelimit); 380 __entry->balanced_dirty_ratelimit = 381 KBps(bdi->balanced_dirty_ratelimit); 382 ), 383 384 TP_printk("bdi %s: " 385 "write_bw=%lu awrite_bw=%lu dirty_rate=%lu " 386 "dirty_ratelimit=%lu task_ratelimit=%lu " 387 "balanced_dirty_ratelimit=%lu", 388 __entry->bdi, 389 __entry->write_bw, /* write bandwidth */ 390 __entry->avg_write_bw, /* avg write bandwidth */ 391 __entry->dirty_rate, /* bdi dirty rate */ 392 __entry->dirty_ratelimit, /* base ratelimit */ 393 __entry->task_ratelimit, /* ratelimit with position control */ 394 __entry->balanced_dirty_ratelimit /* the balanced ratelimit */ 395 ) 396 ); 397 398 TRACE_EVENT(balance_dirty_pages, 399 400 TP_PROTO(struct backing_dev_info *bdi, 401 unsigned long thresh, 402 unsigned long bg_thresh, 403 unsigned long dirty, 404 unsigned long bdi_thresh, 405 unsigned long bdi_dirty, 406 unsigned long dirty_ratelimit, 407 unsigned long task_ratelimit, 408 unsigned long dirtied, 409 unsigned long period, 410 long pause, 411 unsigned long start_time), 412 413 TP_ARGS(bdi, thresh, bg_thresh, dirty, bdi_thresh, bdi_dirty, 414 dirty_ratelimit, task_ratelimit, 415 dirtied, period, pause, start_time), 416 417 TP_STRUCT__entry( 418 __array( char, bdi, 32) 419 __field(unsigned long, limit) 420 __field(unsigned long, setpoint) 421 __field(unsigned long, dirty) 422 __field(unsigned long, bdi_setpoint) 423 __field(unsigned long, bdi_dirty) 424 __field(unsigned long, dirty_ratelimit) 425 __field(unsigned long, task_ratelimit) 426 __field(unsigned int, dirtied) 427 __field(unsigned int, dirtied_pause) 428 __field(unsigned long, paused) 429 __field( long, pause) 430 __field(unsigned long, period) 431 __field( long, think) 432 ), 433 434 TP_fast_assign( 435 unsigned long freerun = (thresh + bg_thresh) / 2; 436 strlcpy(__entry->bdi, dev_name(bdi->dev), 32); 437 438 __entry->limit = global_dirty_limit; 439 __entry->setpoint = (global_dirty_limit + freerun) / 2; 440 __entry->dirty = dirty; 441 __entry->bdi_setpoint = __entry->setpoint * 442 bdi_thresh / (thresh + 1); 443 __entry->bdi_dirty = bdi_dirty; 444 __entry->dirty_ratelimit = KBps(dirty_ratelimit); 445 __entry->task_ratelimit = KBps(task_ratelimit); 446 __entry->dirtied = dirtied; 447 __entry->dirtied_pause = current->nr_dirtied_pause; 448 __entry->think = current->dirty_paused_when == 0 ? 0 : 449 (long)(jiffies - current->dirty_paused_when) * 1000/HZ; 450 __entry->period = period * 1000 / HZ; 451 __entry->pause = pause * 1000 / HZ; 452 __entry->paused = (jiffies - start_time) * 1000 / HZ; 453 ), 454 455 456 TP_printk("bdi %s: " 457 "limit=%lu setpoint=%lu dirty=%lu " 458 "bdi_setpoint=%lu bdi_dirty=%lu " 459 "dirty_ratelimit=%lu task_ratelimit=%lu " 460 "dirtied=%u dirtied_pause=%u " 461 "paused=%lu pause=%ld period=%lu think=%ld", 462 __entry->bdi, 463 __entry->limit, 464 __entry->setpoint, 465 __entry->dirty, 466 __entry->bdi_setpoint, 467 __entry->bdi_dirty, 468 __entry->dirty_ratelimit, 469 __entry->task_ratelimit, 470 __entry->dirtied, 471 __entry->dirtied_pause, 472 __entry->paused, /* ms */ 473 __entry->pause, /* ms */ 474 __entry->period, /* ms */ 475 __entry->think /* ms */ 476 ) 477 ); 478 479 TRACE_EVENT(writeback_sb_inodes_requeue, 480 481 TP_PROTO(struct inode *inode), 482 TP_ARGS(inode), 483 484 TP_STRUCT__entry( 485 __array(char, name, 32) 486 __field(unsigned long, ino) 487 __field(unsigned long, state) 488 __field(unsigned long, dirtied_when) 489 ), 490 491 TP_fast_assign( 492 strncpy(__entry->name, 493 dev_name(inode_to_bdi(inode)->dev), 32); 494 __entry->ino = inode->i_ino; 495 __entry->state = inode->i_state; 496 __entry->dirtied_when = inode->dirtied_when; 497 ), 498 499 TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu", 500 __entry->name, 501 __entry->ino, 502 show_inode_state(__entry->state), 503 __entry->dirtied_when, 504 (jiffies - __entry->dirtied_when) / HZ 505 ) 506 ); 507 508 DECLARE_EVENT_CLASS(writeback_congest_waited_template, 509 510 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed), 511 512 TP_ARGS(usec_timeout, usec_delayed), 513 514 TP_STRUCT__entry( 515 __field( unsigned int, usec_timeout ) 516 __field( unsigned int, usec_delayed ) 517 ), 518 519 TP_fast_assign( 520 __entry->usec_timeout = usec_timeout; 521 __entry->usec_delayed = usec_delayed; 522 ), 523 524 TP_printk("usec_timeout=%u usec_delayed=%u", 525 __entry->usec_timeout, 526 __entry->usec_delayed) 527 ); 528 529 DEFINE_EVENT(writeback_congest_waited_template, writeback_congestion_wait, 530 531 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed), 532 533 TP_ARGS(usec_timeout, usec_delayed) 534 ); 535 536 DEFINE_EVENT(writeback_congest_waited_template, writeback_wait_iff_congested, 537 538 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed), 539 540 TP_ARGS(usec_timeout, usec_delayed) 541 ); 542 543 DECLARE_EVENT_CLASS(writeback_single_inode_template, 544 545 TP_PROTO(struct inode *inode, 546 struct writeback_control *wbc, 547 unsigned long nr_to_write 548 ), 549 550 TP_ARGS(inode, wbc, nr_to_write), 551 552 TP_STRUCT__entry( 553 __array(char, name, 32) 554 __field(unsigned long, ino) 555 __field(unsigned long, state) 556 __field(unsigned long, dirtied_when) 557 __field(unsigned long, writeback_index) 558 __field(long, nr_to_write) 559 __field(unsigned long, wrote) 560 ), 561 562 TP_fast_assign( 563 strncpy(__entry->name, 564 dev_name(inode_to_bdi(inode)->dev), 32); 565 __entry->ino = inode->i_ino; 566 __entry->state = inode->i_state; 567 __entry->dirtied_when = inode->dirtied_when; 568 __entry->writeback_index = inode->i_mapping->writeback_index; 569 __entry->nr_to_write = nr_to_write; 570 __entry->wrote = nr_to_write - wbc->nr_to_write; 571 ), 572 573 TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu " 574 "index=%lu to_write=%ld wrote=%lu", 575 __entry->name, 576 __entry->ino, 577 show_inode_state(__entry->state), 578 __entry->dirtied_when, 579 (jiffies - __entry->dirtied_when) / HZ, 580 __entry->writeback_index, 581 __entry->nr_to_write, 582 __entry->wrote 583 ) 584 ); 585 586 DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode_start, 587 TP_PROTO(struct inode *inode, 588 struct writeback_control *wbc, 589 unsigned long nr_to_write), 590 TP_ARGS(inode, wbc, nr_to_write) 591 ); 592 593 DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode, 594 TP_PROTO(struct inode *inode, 595 struct writeback_control *wbc, 596 unsigned long nr_to_write), 597 TP_ARGS(inode, wbc, nr_to_write) 598 ); 599 600 #endif /* _TRACE_WRITEBACK_H */ 601 602 /* This part must be outside protection */ 603 #include <trace/define_trace.h> 604