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