blob: 32db72c7c055fa2f566f70d89cce51402f213b28 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Dave Chinner455b2862010-07-07 13:24:06 +10002#undef TRACE_SYSTEM
3#define TRACE_SYSTEM writeback
4
5#if !defined(_TRACE_WRITEBACK_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_WRITEBACK_H
7
Steven Rostedt (Red Hat)f4794472014-02-26 12:52:13 -05008#include <linux/tracepoint.h>
Dave Chinner455b2862010-07-07 13:24:06 +10009#include <linux/backing-dev.h>
10#include <linux/writeback.h>
11
Wu Fengguang251d6a42010-12-01 17:33:37 -060012#define show_inode_state(state) \
13 __print_flags(state, "|", \
14 {I_DIRTY_SYNC, "I_DIRTY_SYNC"}, \
15 {I_DIRTY_DATASYNC, "I_DIRTY_DATASYNC"}, \
16 {I_DIRTY_PAGES, "I_DIRTY_PAGES"}, \
17 {I_NEW, "I_NEW"}, \
18 {I_WILL_FREE, "I_WILL_FREE"}, \
19 {I_FREEING, "I_FREEING"}, \
20 {I_CLEAR, "I_CLEAR"}, \
21 {I_SYNC, "I_SYNC"}, \
Theodore Ts'o0ae45f62015-02-02 00:37:00 -050022 {I_DIRTY_TIME, "I_DIRTY_TIME"}, \
23 {I_DIRTY_TIME_EXPIRED, "I_DIRTY_TIME_EXPIRED"}, \
Wu Fengguang251d6a42010-12-01 17:33:37 -060024 {I_REFERENCED, "I_REFERENCED"} \
25 )
26
Steven Rostedt (Red Hat)91df6082015-03-27 17:08:41 -040027/* enums need to be exported to user space */
28#undef EM
29#undef EMe
30#define EM(a,b) TRACE_DEFINE_ENUM(a);
31#define EMe(a,b) TRACE_DEFINE_ENUM(a);
32
Wu Fengguangb3bba8722011-12-08 16:53:54 -060033#define WB_WORK_REASON \
Steven Rostedt (Red Hat)91df6082015-03-27 17:08:41 -040034 EM( WB_REASON_BACKGROUND, "background") \
Johannes Weiner726d061f2017-02-24 14:56:14 -080035 EM( WB_REASON_VMSCAN, "vmscan") \
Steven Rostedt (Red Hat)91df6082015-03-27 17:08:41 -040036 EM( WB_REASON_SYNC, "sync") \
37 EM( WB_REASON_PERIODIC, "periodic") \
38 EM( WB_REASON_LAPTOP_TIMER, "laptop_timer") \
39 EM( WB_REASON_FREE_MORE_MEM, "free_more_memory") \
40 EM( WB_REASON_FS_FREE_SPACE, "fs_free_space") \
41 EMe(WB_REASON_FORKER_THREAD, "forker_thread")
42
43WB_WORK_REASON
44
45/*
46 * Now redefine the EM() and EMe() macros to map the enums to the strings
47 * that will be printed in the output.
48 */
49#undef EM
50#undef EMe
51#define EM(a,b) { a, b },
52#define EMe(a,b) { a, b }
Wu Fengguangb3bba8722011-12-08 16:53:54 -060053
Dave Chinner455b2862010-07-07 13:24:06 +100054struct wb_writeback_work;
55
Tejun Heo9fb0a7d2013-01-11 13:06:37 -080056TRACE_EVENT(writeback_dirty_page,
57
58 TP_PROTO(struct page *page, struct address_space *mapping),
59
60 TP_ARGS(page, mapping),
61
62 TP_STRUCT__entry (
63 __array(char, name, 32)
64 __field(unsigned long, ino)
65 __field(pgoff_t, index)
66 ),
67
68 TP_fast_assign(
69 strncpy(__entry->name,
Christoph Hellwigde1414a2015-01-14 10:42:36 +010070 mapping ? dev_name(inode_to_bdi(mapping->host)->dev) : "(unknown)", 32);
Tejun Heo9fb0a7d2013-01-11 13:06:37 -080071 __entry->ino = mapping ? mapping->host->i_ino : 0;
72 __entry->index = page->index;
73 ),
74
75 TP_printk("bdi %s: ino=%lu index=%lu",
76 __entry->name,
77 __entry->ino,
78 __entry->index
79 )
80);
81
82DECLARE_EVENT_CLASS(writeback_dirty_inode_template,
83
84 TP_PROTO(struct inode *inode, int flags),
85
86 TP_ARGS(inode, flags),
87
88 TP_STRUCT__entry (
89 __array(char, name, 32)
90 __field(unsigned long, ino)
Theodore Ts'o0ae45f62015-02-02 00:37:00 -050091 __field(unsigned long, state)
Tejun Heo9fb0a7d2013-01-11 13:06:37 -080092 __field(unsigned long, flags)
93 ),
94
95 TP_fast_assign(
Christoph Hellwigde1414a2015-01-14 10:42:36 +010096 struct backing_dev_info *bdi = inode_to_bdi(inode);
Tejun Heo9fb0a7d2013-01-11 13:06:37 -080097
98 /* may be called for files on pseudo FSes w/ unregistered bdi */
99 strncpy(__entry->name,
100 bdi->dev ? dev_name(bdi->dev) : "(unknown)", 32);
101 __entry->ino = inode->i_ino;
Theodore Ts'o0ae45f62015-02-02 00:37:00 -0500102 __entry->state = inode->i_state;
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800103 __entry->flags = flags;
104 ),
105
Theodore Ts'o0ae45f62015-02-02 00:37:00 -0500106 TP_printk("bdi %s: ino=%lu state=%s flags=%s",
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800107 __entry->name,
108 __entry->ino,
Theodore Ts'o0ae45f62015-02-02 00:37:00 -0500109 show_inode_state(__entry->state),
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800110 show_inode_state(__entry->flags)
111 )
112);
113
Theodore Ts'o0ae45f62015-02-02 00:37:00 -0500114DEFINE_EVENT(writeback_dirty_inode_template, writeback_mark_inode_dirty,
115
116 TP_PROTO(struct inode *inode, int flags),
117
118 TP_ARGS(inode, flags)
119);
120
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800121DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode_start,
122
123 TP_PROTO(struct inode *inode, int flags),
124
125 TP_ARGS(inode, flags)
126);
127
128DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode,
129
130 TP_PROTO(struct inode *inode, int flags),
131
132 TP_ARGS(inode, flags)
133);
134
Tejun Heo5634cc22015-08-18 14:54:56 -0700135#ifdef CREATE_TRACE_POINTS
136#ifdef CONFIG_CGROUP_WRITEBACK
137
Yang Shia664edb2016-03-03 01:08:57 -0800138static inline unsigned int __trace_wb_assign_cgroup(struct bdi_writeback *wb)
Tejun Heo5634cc22015-08-18 14:54:56 -0700139{
Shaohua Lic53cd492017-07-12 11:49:50 -0700140 return wb->memcg_css->cgroup->kn->id.ino;
Tejun Heo5634cc22015-08-18 14:54:56 -0700141}
142
Yang Shia664edb2016-03-03 01:08:57 -0800143static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *wbc)
Tejun Heo5634cc22015-08-18 14:54:56 -0700144{
145 if (wbc->wb)
Yang Shia664edb2016-03-03 01:08:57 -0800146 return __trace_wb_assign_cgroup(wbc->wb);
Tejun Heo5634cc22015-08-18 14:54:56 -0700147 else
Yang Shia664edb2016-03-03 01:08:57 -0800148 return -1U;
Tejun Heo5634cc22015-08-18 14:54:56 -0700149}
Tejun Heo5634cc22015-08-18 14:54:56 -0700150#else /* CONFIG_CGROUP_WRITEBACK */
151
Yang Shia664edb2016-03-03 01:08:57 -0800152static inline unsigned int __trace_wb_assign_cgroup(struct bdi_writeback *wb)
Tejun Heo5634cc22015-08-18 14:54:56 -0700153{
Yang Shia664edb2016-03-03 01:08:57 -0800154 return -1U;
Tejun Heo5634cc22015-08-18 14:54:56 -0700155}
156
Yang Shia664edb2016-03-03 01:08:57 -0800157static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *wbc)
Tejun Heo5634cc22015-08-18 14:54:56 -0700158{
Yang Shia664edb2016-03-03 01:08:57 -0800159 return -1U;
Tejun Heo5634cc22015-08-18 14:54:56 -0700160}
161
162#endif /* CONFIG_CGROUP_WRITEBACK */
163#endif /* CREATE_TRACE_POINTS */
164
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800165DECLARE_EVENT_CLASS(writeback_write_inode_template,
166
167 TP_PROTO(struct inode *inode, struct writeback_control *wbc),
168
169 TP_ARGS(inode, wbc),
170
171 TP_STRUCT__entry (
172 __array(char, name, 32)
173 __field(unsigned long, ino)
174 __field(int, sync_mode)
Yang Shia664edb2016-03-03 01:08:57 -0800175 __field(unsigned int, cgroup_ino)
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800176 ),
177
178 TP_fast_assign(
179 strncpy(__entry->name,
Christoph Hellwigde1414a2015-01-14 10:42:36 +0100180 dev_name(inode_to_bdi(inode)->dev), 32);
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800181 __entry->ino = inode->i_ino;
182 __entry->sync_mode = wbc->sync_mode;
Yang Shia664edb2016-03-03 01:08:57 -0800183 __entry->cgroup_ino = __trace_wbc_assign_cgroup(wbc);
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800184 ),
185
Yang Shia664edb2016-03-03 01:08:57 -0800186 TP_printk("bdi %s: ino=%lu sync_mode=%d cgroup_ino=%u",
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800187 __entry->name,
188 __entry->ino,
Tejun Heo5634cc22015-08-18 14:54:56 -0700189 __entry->sync_mode,
Yang Shia664edb2016-03-03 01:08:57 -0800190 __entry->cgroup_ino
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800191 )
192);
193
194DEFINE_EVENT(writeback_write_inode_template, writeback_write_inode_start,
195
196 TP_PROTO(struct inode *inode, struct writeback_control *wbc),
197
198 TP_ARGS(inode, wbc)
199);
200
201DEFINE_EVENT(writeback_write_inode_template, writeback_write_inode,
202
203 TP_PROTO(struct inode *inode, struct writeback_control *wbc),
204
205 TP_ARGS(inode, wbc)
206);
207
Dave Chinner455b2862010-07-07 13:24:06 +1000208DECLARE_EVENT_CLASS(writeback_work_class,
Tejun Heo5634cc22015-08-18 14:54:56 -0700209 TP_PROTO(struct bdi_writeback *wb, struct wb_writeback_work *work),
210 TP_ARGS(wb, work),
Dave Chinner455b2862010-07-07 13:24:06 +1000211 TP_STRUCT__entry(
212 __array(char, name, 32)
213 __field(long, nr_pages)
214 __field(dev_t, sb_dev)
215 __field(int, sync_mode)
216 __field(int, for_kupdate)
217 __field(int, range_cyclic)
218 __field(int, for_background)
Curt Wohlgemuth0e175a12011-10-07 21:54:10 -0600219 __field(int, reason)
Yang Shia664edb2016-03-03 01:08:57 -0800220 __field(unsigned int, cgroup_ino)
Dave Chinner455b2862010-07-07 13:24:06 +1000221 ),
222 TP_fast_assign(
Christoph Hellwigdf0ce262015-01-14 10:42:41 +0100223 strncpy(__entry->name,
Tejun Heo5634cc22015-08-18 14:54:56 -0700224 wb->bdi->dev ? dev_name(wb->bdi->dev) : "(unknown)", 32);
Dave Chinner455b2862010-07-07 13:24:06 +1000225 __entry->nr_pages = work->nr_pages;
226 __entry->sb_dev = work->sb ? work->sb->s_dev : 0;
227 __entry->sync_mode = work->sync_mode;
228 __entry->for_kupdate = work->for_kupdate;
229 __entry->range_cyclic = work->range_cyclic;
230 __entry->for_background = work->for_background;
Curt Wohlgemuth0e175a12011-10-07 21:54:10 -0600231 __entry->reason = work->reason;
Yang Shia664edb2016-03-03 01:08:57 -0800232 __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
Dave Chinner455b2862010-07-07 13:24:06 +1000233 ),
234 TP_printk("bdi %s: sb_dev %d:%d nr_pages=%ld sync_mode=%d "
Yang Shia664edb2016-03-03 01:08:57 -0800235 "kupdate=%d range_cyclic=%d background=%d reason=%s cgroup_ino=%u",
Dave Chinner455b2862010-07-07 13:24:06 +1000236 __entry->name,
237 MAJOR(__entry->sb_dev), MINOR(__entry->sb_dev),
238 __entry->nr_pages,
239 __entry->sync_mode,
240 __entry->for_kupdate,
241 __entry->range_cyclic,
Curt Wohlgemuth0e175a12011-10-07 21:54:10 -0600242 __entry->for_background,
Tejun Heo5634cc22015-08-18 14:54:56 -0700243 __print_symbolic(__entry->reason, WB_WORK_REASON),
Yang Shia664edb2016-03-03 01:08:57 -0800244 __entry->cgroup_ino
Dave Chinner455b2862010-07-07 13:24:06 +1000245 )
246);
247#define DEFINE_WRITEBACK_WORK_EVENT(name) \
248DEFINE_EVENT(writeback_work_class, name, \
Tejun Heo5634cc22015-08-18 14:54:56 -0700249 TP_PROTO(struct bdi_writeback *wb, struct wb_writeback_work *work), \
250 TP_ARGS(wb, work))
Dave Chinner455b2862010-07-07 13:24:06 +1000251DEFINE_WRITEBACK_WORK_EVENT(writeback_queue);
252DEFINE_WRITEBACK_WORK_EVENT(writeback_exec);
Wu Fengguangd46db3d2011-05-04 19:54:37 -0600253DEFINE_WRITEBACK_WORK_EVENT(writeback_start);
254DEFINE_WRITEBACK_WORK_EVENT(writeback_written);
255DEFINE_WRITEBACK_WORK_EVENT(writeback_wait);
Dave Chinner455b2862010-07-07 13:24:06 +1000256
257TRACE_EVENT(writeback_pages_written,
258 TP_PROTO(long pages_written),
259 TP_ARGS(pages_written),
260 TP_STRUCT__entry(
261 __field(long, pages)
262 ),
263 TP_fast_assign(
264 __entry->pages = pages_written;
265 ),
266 TP_printk("%ld", __entry->pages)
267);
268
269DECLARE_EVENT_CLASS(writeback_class,
Tejun Heo5634cc22015-08-18 14:54:56 -0700270 TP_PROTO(struct bdi_writeback *wb),
271 TP_ARGS(wb),
272 TP_STRUCT__entry(
273 __array(char, name, 32)
Yang Shia664edb2016-03-03 01:08:57 -0800274 __field(unsigned int, cgroup_ino)
Tejun Heo5634cc22015-08-18 14:54:56 -0700275 ),
276 TP_fast_assign(
277 strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
Yang Shia664edb2016-03-03 01:08:57 -0800278 __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
Tejun Heo5634cc22015-08-18 14:54:56 -0700279 ),
Yang Shia664edb2016-03-03 01:08:57 -0800280 TP_printk("bdi %s: cgroup_ino=%u",
Tejun Heo5634cc22015-08-18 14:54:56 -0700281 __entry->name,
Yang Shia664edb2016-03-03 01:08:57 -0800282 __entry->cgroup_ino
Tejun Heo5634cc22015-08-18 14:54:56 -0700283 )
284);
285#define DEFINE_WRITEBACK_EVENT(name) \
286DEFINE_EVENT(writeback_class, name, \
287 TP_PROTO(struct bdi_writeback *wb), \
288 TP_ARGS(wb))
289
Tejun Heo5634cc22015-08-18 14:54:56 -0700290DEFINE_WRITEBACK_EVENT(writeback_wake_background);
291
292TRACE_EVENT(writeback_bdi_register,
Dave Chinner455b2862010-07-07 13:24:06 +1000293 TP_PROTO(struct backing_dev_info *bdi),
294 TP_ARGS(bdi),
295 TP_STRUCT__entry(
296 __array(char, name, 32)
297 ),
298 TP_fast_assign(
299 strncpy(__entry->name, dev_name(bdi->dev), 32);
300 ),
301 TP_printk("bdi %s",
Tejun Heo5634cc22015-08-18 14:54:56 -0700302 __entry->name
Dave Chinner455b2862010-07-07 13:24:06 +1000303 )
304);
Dave Chinner455b2862010-07-07 13:24:06 +1000305
Dave Chinner028c2dd2010-07-07 13:24:07 +1000306DECLARE_EVENT_CLASS(wbc_class,
307 TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi),
308 TP_ARGS(wbc, bdi),
309 TP_STRUCT__entry(
310 __array(char, name, 32)
311 __field(long, nr_to_write)
312 __field(long, pages_skipped)
313 __field(int, sync_mode)
Dave Chinner028c2dd2010-07-07 13:24:07 +1000314 __field(int, for_kupdate)
315 __field(int, for_background)
316 __field(int, for_reclaim)
317 __field(int, range_cyclic)
Dave Chinner028c2dd2010-07-07 13:24:07 +1000318 __field(long, range_start)
319 __field(long, range_end)
Yang Shia664edb2016-03-03 01:08:57 -0800320 __field(unsigned int, cgroup_ino)
Dave Chinner028c2dd2010-07-07 13:24:07 +1000321 ),
322
323 TP_fast_assign(
324 strncpy(__entry->name, dev_name(bdi->dev), 32);
325 __entry->nr_to_write = wbc->nr_to_write;
326 __entry->pages_skipped = wbc->pages_skipped;
327 __entry->sync_mode = wbc->sync_mode;
328 __entry->for_kupdate = wbc->for_kupdate;
329 __entry->for_background = wbc->for_background;
330 __entry->for_reclaim = wbc->for_reclaim;
331 __entry->range_cyclic = wbc->range_cyclic;
Dave Chinner028c2dd2010-07-07 13:24:07 +1000332 __entry->range_start = (long)wbc->range_start;
333 __entry->range_end = (long)wbc->range_end;
Yang Shia664edb2016-03-03 01:08:57 -0800334 __entry->cgroup_ino = __trace_wbc_assign_cgroup(wbc);
Dave Chinner028c2dd2010-07-07 13:24:07 +1000335 ),
336
337 TP_printk("bdi %s: towrt=%ld skip=%ld mode=%d kupd=%d "
Wu Fengguangd46db3d2011-05-04 19:54:37 -0600338 "bgrd=%d reclm=%d cyclic=%d "
Yang Shia664edb2016-03-03 01:08:57 -0800339 "start=0x%lx end=0x%lx cgroup_ino=%u",
Dave Chinner028c2dd2010-07-07 13:24:07 +1000340 __entry->name,
341 __entry->nr_to_write,
342 __entry->pages_skipped,
343 __entry->sync_mode,
344 __entry->for_kupdate,
345 __entry->for_background,
346 __entry->for_reclaim,
347 __entry->range_cyclic,
Dave Chinner028c2dd2010-07-07 13:24:07 +1000348 __entry->range_start,
Tejun Heo5634cc22015-08-18 14:54:56 -0700349 __entry->range_end,
Yang Shia664edb2016-03-03 01:08:57 -0800350 __entry->cgroup_ino
Tejun Heo5634cc22015-08-18 14:54:56 -0700351 )
Dave Chinner028c2dd2010-07-07 13:24:07 +1000352)
353
354#define DEFINE_WBC_EVENT(name) \
355DEFINE_EVENT(wbc_class, name, \
356 TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi), \
357 TP_ARGS(wbc, bdi))
Dave Chinner9e094382010-07-07 13:24:08 +1000358DEFINE_WBC_EVENT(wbc_writepage);
Dave Chinner028c2dd2010-07-07 13:24:07 +1000359
Wu Fengguange84d0a42011-04-23 12:27:27 -0600360TRACE_EVENT(writeback_queue_io,
361 TP_PROTO(struct bdi_writeback *wb,
Curt Wohlgemuthad4e38d2011-10-07 21:51:56 -0600362 struct wb_writeback_work *work,
Wu Fengguange84d0a42011-04-23 12:27:27 -0600363 int moved),
Curt Wohlgemuthad4e38d2011-10-07 21:51:56 -0600364 TP_ARGS(wb, work, moved),
Wu Fengguange84d0a42011-04-23 12:27:27 -0600365 TP_STRUCT__entry(
366 __array(char, name, 32)
367 __field(unsigned long, older)
368 __field(long, age)
369 __field(int, moved)
Curt Wohlgemuth0e175a12011-10-07 21:54:10 -0600370 __field(int, reason)
Yang Shia664edb2016-03-03 01:08:57 -0800371 __field(unsigned int, cgroup_ino)
Wu Fengguange84d0a42011-04-23 12:27:27 -0600372 ),
373 TP_fast_assign(
Jan Kara0dc83bd2014-02-21 11:19:04 +0100374 unsigned long *older_than_this = work->older_than_this;
Wu Fengguange84d0a42011-04-23 12:27:27 -0600375 strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
Jan Kara0dc83bd2014-02-21 11:19:04 +0100376 __entry->older = older_than_this ? *older_than_this : 0;
Wu Fengguange84d0a42011-04-23 12:27:27 -0600377 __entry->age = older_than_this ?
Jan Kara0dc83bd2014-02-21 11:19:04 +0100378 (jiffies - *older_than_this) * 1000 / HZ : -1;
Wu Fengguange84d0a42011-04-23 12:27:27 -0600379 __entry->moved = moved;
Curt Wohlgemuth0e175a12011-10-07 21:54:10 -0600380 __entry->reason = work->reason;
Yang Shia664edb2016-03-03 01:08:57 -0800381 __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
Wu Fengguange84d0a42011-04-23 12:27:27 -0600382 ),
Yang Shia664edb2016-03-03 01:08:57 -0800383 TP_printk("bdi %s: older=%lu age=%ld enqueue=%d reason=%s cgroup_ino=%u",
Wu Fengguange84d0a42011-04-23 12:27:27 -0600384 __entry->name,
385 __entry->older, /* older_than_this in jiffies */
386 __entry->age, /* older_than_this in relative milliseconds */
Curt Wohlgemuth0e175a12011-10-07 21:54:10 -0600387 __entry->moved,
Tejun Heo5634cc22015-08-18 14:54:56 -0700388 __print_symbolic(__entry->reason, WB_WORK_REASON),
Yang Shia664edb2016-03-03 01:08:57 -0800389 __entry->cgroup_ino
Wu Fengguangb3bba8722011-12-08 16:53:54 -0600390 )
Wu Fengguange84d0a42011-04-23 12:27:27 -0600391);
392
Wu Fengguange1cbe232010-12-06 22:34:29 -0600393TRACE_EVENT(global_dirty_state,
394
395 TP_PROTO(unsigned long background_thresh,
396 unsigned long dirty_thresh
397 ),
398
399 TP_ARGS(background_thresh,
400 dirty_thresh
401 ),
402
403 TP_STRUCT__entry(
404 __field(unsigned long, nr_dirty)
405 __field(unsigned long, nr_writeback)
406 __field(unsigned long, nr_unstable)
407 __field(unsigned long, background_thresh)
408 __field(unsigned long, dirty_thresh)
409 __field(unsigned long, dirty_limit)
410 __field(unsigned long, nr_dirtied)
411 __field(unsigned long, nr_written)
412 ),
413
414 TP_fast_assign(
Mel Gorman11fb9982016-07-28 15:46:20 -0700415 __entry->nr_dirty = global_node_page_state(NR_FILE_DIRTY);
416 __entry->nr_writeback = global_node_page_state(NR_WRITEBACK);
417 __entry->nr_unstable = global_node_page_state(NR_UNSTABLE_NFS);
Mel Gormanc4a25632016-07-28 15:46:23 -0700418 __entry->nr_dirtied = global_node_page_state(NR_DIRTIED);
419 __entry->nr_written = global_node_page_state(NR_WRITTEN);
Wu Fengguange1cbe232010-12-06 22:34:29 -0600420 __entry->background_thresh = background_thresh;
421 __entry->dirty_thresh = dirty_thresh;
Tejun Heodcc25ae2015-05-22 18:23:22 -0400422 __entry->dirty_limit = global_wb_domain.dirty_limit;
Wu Fengguange1cbe232010-12-06 22:34:29 -0600423 ),
424
425 TP_printk("dirty=%lu writeback=%lu unstable=%lu "
426 "bg_thresh=%lu thresh=%lu limit=%lu "
427 "dirtied=%lu written=%lu",
428 __entry->nr_dirty,
429 __entry->nr_writeback,
430 __entry->nr_unstable,
431 __entry->background_thresh,
432 __entry->dirty_thresh,
433 __entry->dirty_limit,
434 __entry->nr_dirtied,
435 __entry->nr_written
436 )
437);
438
Wu Fengguangb48c1042011-03-02 17:22:49 -0600439#define KBps(x) ((x) << (PAGE_SHIFT - 10))
440
441TRACE_EVENT(bdi_dirty_ratelimit,
442
Tejun Heo5634cc22015-08-18 14:54:56 -0700443 TP_PROTO(struct bdi_writeback *wb,
Wu Fengguangb48c1042011-03-02 17:22:49 -0600444 unsigned long dirty_rate,
445 unsigned long task_ratelimit),
446
Tejun Heo5634cc22015-08-18 14:54:56 -0700447 TP_ARGS(wb, dirty_rate, task_ratelimit),
Wu Fengguangb48c1042011-03-02 17:22:49 -0600448
449 TP_STRUCT__entry(
450 __array(char, bdi, 32)
451 __field(unsigned long, write_bw)
452 __field(unsigned long, avg_write_bw)
453 __field(unsigned long, dirty_rate)
454 __field(unsigned long, dirty_ratelimit)
455 __field(unsigned long, task_ratelimit)
456 __field(unsigned long, balanced_dirty_ratelimit)
Yang Shia664edb2016-03-03 01:08:57 -0800457 __field(unsigned int, cgroup_ino)
Wu Fengguangb48c1042011-03-02 17:22:49 -0600458 ),
459
460 TP_fast_assign(
Tejun Heo5634cc22015-08-18 14:54:56 -0700461 strlcpy(__entry->bdi, dev_name(wb->bdi->dev), 32);
462 __entry->write_bw = KBps(wb->write_bandwidth);
463 __entry->avg_write_bw = KBps(wb->avg_write_bandwidth);
Wu Fengguangb48c1042011-03-02 17:22:49 -0600464 __entry->dirty_rate = KBps(dirty_rate);
Tejun Heo5634cc22015-08-18 14:54:56 -0700465 __entry->dirty_ratelimit = KBps(wb->dirty_ratelimit);
Wu Fengguangb48c1042011-03-02 17:22:49 -0600466 __entry->task_ratelimit = KBps(task_ratelimit);
467 __entry->balanced_dirty_ratelimit =
Tejun Heo5634cc22015-08-18 14:54:56 -0700468 KBps(wb->balanced_dirty_ratelimit);
Yang Shia664edb2016-03-03 01:08:57 -0800469 __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
Wu Fengguangb48c1042011-03-02 17:22:49 -0600470 ),
471
472 TP_printk("bdi %s: "
473 "write_bw=%lu awrite_bw=%lu dirty_rate=%lu "
474 "dirty_ratelimit=%lu task_ratelimit=%lu "
Yang Shia664edb2016-03-03 01:08:57 -0800475 "balanced_dirty_ratelimit=%lu cgroup_ino=%u",
Wu Fengguangb48c1042011-03-02 17:22:49 -0600476 __entry->bdi,
477 __entry->write_bw, /* write bandwidth */
478 __entry->avg_write_bw, /* avg write bandwidth */
479 __entry->dirty_rate, /* bdi dirty rate */
480 __entry->dirty_ratelimit, /* base ratelimit */
481 __entry->task_ratelimit, /* ratelimit with position control */
Tejun Heo5634cc22015-08-18 14:54:56 -0700482 __entry->balanced_dirty_ratelimit, /* the balanced ratelimit */
Yang Shia664edb2016-03-03 01:08:57 -0800483 __entry->cgroup_ino
Wu Fengguangb48c1042011-03-02 17:22:49 -0600484 )
485);
486
Wu Fengguangece13ac32010-08-29 23:33:20 -0600487TRACE_EVENT(balance_dirty_pages,
488
Tejun Heo5634cc22015-08-18 14:54:56 -0700489 TP_PROTO(struct bdi_writeback *wb,
Wu Fengguangece13ac32010-08-29 23:33:20 -0600490 unsigned long thresh,
491 unsigned long bg_thresh,
492 unsigned long dirty,
493 unsigned long bdi_thresh,
494 unsigned long bdi_dirty,
495 unsigned long dirty_ratelimit,
496 unsigned long task_ratelimit,
497 unsigned long dirtied,
Wu Fengguang83712352011-06-11 19:25:42 -0600498 unsigned long period,
Wu Fengguangece13ac32010-08-29 23:33:20 -0600499 long pause,
500 unsigned long start_time),
501
Tejun Heo5634cc22015-08-18 14:54:56 -0700502 TP_ARGS(wb, thresh, bg_thresh, dirty, bdi_thresh, bdi_dirty,
Wu Fengguangece13ac32010-08-29 23:33:20 -0600503 dirty_ratelimit, task_ratelimit,
Wu Fengguang83712352011-06-11 19:25:42 -0600504 dirtied, period, pause, start_time),
Wu Fengguangece13ac32010-08-29 23:33:20 -0600505
506 TP_STRUCT__entry(
507 __array( char, bdi, 32)
508 __field(unsigned long, limit)
509 __field(unsigned long, setpoint)
510 __field(unsigned long, dirty)
511 __field(unsigned long, bdi_setpoint)
512 __field(unsigned long, bdi_dirty)
513 __field(unsigned long, dirty_ratelimit)
514 __field(unsigned long, task_ratelimit)
515 __field(unsigned int, dirtied)
516 __field(unsigned int, dirtied_pause)
517 __field(unsigned long, paused)
518 __field( long, pause)
Wu Fengguang83712352011-06-11 19:25:42 -0600519 __field(unsigned long, period)
520 __field( long, think)
Yang Shia664edb2016-03-03 01:08:57 -0800521 __field(unsigned int, cgroup_ino)
Wu Fengguangece13ac32010-08-29 23:33:20 -0600522 ),
523
524 TP_fast_assign(
525 unsigned long freerun = (thresh + bg_thresh) / 2;
Tejun Heo5634cc22015-08-18 14:54:56 -0700526 strlcpy(__entry->bdi, dev_name(wb->bdi->dev), 32);
Wu Fengguangece13ac32010-08-29 23:33:20 -0600527
Tejun Heodcc25ae2015-05-22 18:23:22 -0400528 __entry->limit = global_wb_domain.dirty_limit;
529 __entry->setpoint = (global_wb_domain.dirty_limit +
530 freerun) / 2;
Wu Fengguangece13ac32010-08-29 23:33:20 -0600531 __entry->dirty = dirty;
532 __entry->bdi_setpoint = __entry->setpoint *
533 bdi_thresh / (thresh + 1);
534 __entry->bdi_dirty = bdi_dirty;
535 __entry->dirty_ratelimit = KBps(dirty_ratelimit);
536 __entry->task_ratelimit = KBps(task_ratelimit);
537 __entry->dirtied = dirtied;
538 __entry->dirtied_pause = current->nr_dirtied_pause;
Wu Fengguang83712352011-06-11 19:25:42 -0600539 __entry->think = current->dirty_paused_when == 0 ? 0 :
540 (long)(jiffies - current->dirty_paused_when) * 1000/HZ;
541 __entry->period = period * 1000 / HZ;
Wu Fengguangece13ac32010-08-29 23:33:20 -0600542 __entry->pause = pause * 1000 / HZ;
543 __entry->paused = (jiffies - start_time) * 1000 / HZ;
Yang Shia664edb2016-03-03 01:08:57 -0800544 __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
Wu Fengguangece13ac32010-08-29 23:33:20 -0600545 ),
546
547
548 TP_printk("bdi %s: "
549 "limit=%lu setpoint=%lu dirty=%lu "
550 "bdi_setpoint=%lu bdi_dirty=%lu "
551 "dirty_ratelimit=%lu task_ratelimit=%lu "
552 "dirtied=%u dirtied_pause=%u "
Yang Shia664edb2016-03-03 01:08:57 -0800553 "paused=%lu pause=%ld period=%lu think=%ld cgroup_ino=%u",
Wu Fengguangece13ac32010-08-29 23:33:20 -0600554 __entry->bdi,
555 __entry->limit,
556 __entry->setpoint,
557 __entry->dirty,
558 __entry->bdi_setpoint,
559 __entry->bdi_dirty,
560 __entry->dirty_ratelimit,
561 __entry->task_ratelimit,
562 __entry->dirtied,
563 __entry->dirtied_pause,
564 __entry->paused, /* ms */
Wu Fengguang83712352011-06-11 19:25:42 -0600565 __entry->pause, /* ms */
566 __entry->period, /* ms */
Tejun Heo5634cc22015-08-18 14:54:56 -0700567 __entry->think, /* ms */
Yang Shia664edb2016-03-03 01:08:57 -0800568 __entry->cgroup_ino
Wu Fengguangece13ac32010-08-29 23:33:20 -0600569 )
570);
571
Jan Karacc1676d2012-05-03 14:47:56 +0200572TRACE_EVENT(writeback_sb_inodes_requeue,
573
574 TP_PROTO(struct inode *inode),
575 TP_ARGS(inode),
576
577 TP_STRUCT__entry(
578 __array(char, name, 32)
579 __field(unsigned long, ino)
580 __field(unsigned long, state)
581 __field(unsigned long, dirtied_when)
Yang Shia664edb2016-03-03 01:08:57 -0800582 __field(unsigned int, cgroup_ino)
Jan Karacc1676d2012-05-03 14:47:56 +0200583 ),
584
585 TP_fast_assign(
586 strncpy(__entry->name,
587 dev_name(inode_to_bdi(inode)->dev), 32);
588 __entry->ino = inode->i_ino;
589 __entry->state = inode->i_state;
590 __entry->dirtied_when = inode->dirtied_when;
Yang Shia664edb2016-03-03 01:08:57 -0800591 __entry->cgroup_ino = __trace_wb_assign_cgroup(inode_to_wb(inode));
Jan Karacc1676d2012-05-03 14:47:56 +0200592 ),
593
Yang Shia664edb2016-03-03 01:08:57 -0800594 TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu cgroup_ino=%u",
Jan Karacc1676d2012-05-03 14:47:56 +0200595 __entry->name,
596 __entry->ino,
597 show_inode_state(__entry->state),
598 __entry->dirtied_when,
Tejun Heo5634cc22015-08-18 14:54:56 -0700599 (jiffies - __entry->dirtied_when) / HZ,
Yang Shia664edb2016-03-03 01:08:57 -0800600 __entry->cgroup_ino
Jan Karacc1676d2012-05-03 14:47:56 +0200601 )
602);
603
Mel Gorman52bb9192010-10-26 14:21:41 -0700604DECLARE_EVENT_CLASS(writeback_congest_waited_template,
605
606 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
607
608 TP_ARGS(usec_timeout, usec_delayed),
609
610 TP_STRUCT__entry(
611 __field( unsigned int, usec_timeout )
612 __field( unsigned int, usec_delayed )
613 ),
614
615 TP_fast_assign(
616 __entry->usec_timeout = usec_timeout;
617 __entry->usec_delayed = usec_delayed;
618 ),
619
620 TP_printk("usec_timeout=%u usec_delayed=%u",
621 __entry->usec_timeout,
622 __entry->usec_delayed)
623);
624
625DEFINE_EVENT(writeback_congest_waited_template, writeback_congestion_wait,
626
627 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
628
629 TP_ARGS(usec_timeout, usec_delayed)
630);
631
Mel Gorman0e093d992010-10-26 14:21:45 -0700632DEFINE_EVENT(writeback_congest_waited_template, writeback_wait_iff_congested,
633
634 TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
635
636 TP_ARGS(usec_timeout, usec_delayed)
637);
638
Wu Fengguang251d6a42010-12-01 17:33:37 -0600639DECLARE_EVENT_CLASS(writeback_single_inode_template,
640
641 TP_PROTO(struct inode *inode,
642 struct writeback_control *wbc,
643 unsigned long nr_to_write
644 ),
645
646 TP_ARGS(inode, wbc, nr_to_write),
647
648 TP_STRUCT__entry(
649 __array(char, name, 32)
650 __field(unsigned long, ino)
651 __field(unsigned long, state)
Wu Fengguangc8ad6202011-08-29 09:52:23 -0600652 __field(unsigned long, dirtied_when)
Wu Fengguang251d6a42010-12-01 17:33:37 -0600653 __field(unsigned long, writeback_index)
654 __field(long, nr_to_write)
655 __field(unsigned long, wrote)
Yang Shia664edb2016-03-03 01:08:57 -0800656 __field(unsigned int, cgroup_ino)
Wu Fengguang251d6a42010-12-01 17:33:37 -0600657 ),
658
659 TP_fast_assign(
660 strncpy(__entry->name,
Wu Fengguang15eb77a2012-01-17 11:18:56 -0600661 dev_name(inode_to_bdi(inode)->dev), 32);
Wu Fengguang251d6a42010-12-01 17:33:37 -0600662 __entry->ino = inode->i_ino;
663 __entry->state = inode->i_state;
Wu Fengguangc8ad6202011-08-29 09:52:23 -0600664 __entry->dirtied_when = inode->dirtied_when;
Wu Fengguang251d6a42010-12-01 17:33:37 -0600665 __entry->writeback_index = inode->i_mapping->writeback_index;
666 __entry->nr_to_write = nr_to_write;
667 __entry->wrote = nr_to_write - wbc->nr_to_write;
Yang Shia664edb2016-03-03 01:08:57 -0800668 __entry->cgroup_ino = __trace_wbc_assign_cgroup(wbc);
Wu Fengguang251d6a42010-12-01 17:33:37 -0600669 ),
670
Wu Fengguangc8ad6202011-08-29 09:52:23 -0600671 TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu "
Yang Shia664edb2016-03-03 01:08:57 -0800672 "index=%lu to_write=%ld wrote=%lu cgroup_ino=%u",
Wu Fengguang251d6a42010-12-01 17:33:37 -0600673 __entry->name,
674 __entry->ino,
675 show_inode_state(__entry->state),
Wu Fengguangc8ad6202011-08-29 09:52:23 -0600676 __entry->dirtied_when,
677 (jiffies - __entry->dirtied_when) / HZ,
Wu Fengguang251d6a42010-12-01 17:33:37 -0600678 __entry->writeback_index,
679 __entry->nr_to_write,
Tejun Heo5634cc22015-08-18 14:54:56 -0700680 __entry->wrote,
Yang Shia664edb2016-03-03 01:08:57 -0800681 __entry->cgroup_ino
Wu Fengguang251d6a42010-12-01 17:33:37 -0600682 )
683);
684
Tejun Heo9fb0a7d2013-01-11 13:06:37 -0800685DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode_start,
686 TP_PROTO(struct inode *inode,
687 struct writeback_control *wbc,
688 unsigned long nr_to_write),
689 TP_ARGS(inode, wbc, nr_to_write)
690);
691
Wu Fengguang251d6a42010-12-01 17:33:37 -0600692DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode,
693 TP_PROTO(struct inode *inode,
694 struct writeback_control *wbc,
695 unsigned long nr_to_write),
696 TP_ARGS(inode, wbc, nr_to_write)
697);
698
Brian Foster9a46b04f2016-07-26 15:21:53 -0700699DECLARE_EVENT_CLASS(writeback_inode_template,
Theodore Ts'o0ae45f62015-02-02 00:37:00 -0500700 TP_PROTO(struct inode *inode),
701
702 TP_ARGS(inode),
703
704 TP_STRUCT__entry(
705 __field( dev_t, dev )
706 __field(unsigned long, ino )
707 __field(unsigned long, state )
708 __field( __u16, mode )
709 __field(unsigned long, dirtied_when )
710 ),
711
712 TP_fast_assign(
713 __entry->dev = inode->i_sb->s_dev;
714 __entry->ino = inode->i_ino;
715 __entry->state = inode->i_state;
716 __entry->mode = inode->i_mode;
717 __entry->dirtied_when = inode->dirtied_when;
718 ),
719
720 TP_printk("dev %d,%d ino %lu dirtied %lu state %s mode 0%o",
721 MAJOR(__entry->dev), MINOR(__entry->dev),
722 __entry->ino, __entry->dirtied_when,
723 show_inode_state(__entry->state), __entry->mode)
724);
725
Brian Foster9a46b04f2016-07-26 15:21:53 -0700726DEFINE_EVENT(writeback_inode_template, writeback_lazytime,
Theodore Ts'o0ae45f62015-02-02 00:37:00 -0500727 TP_PROTO(struct inode *inode),
728
729 TP_ARGS(inode)
730);
731
Brian Foster9a46b04f2016-07-26 15:21:53 -0700732DEFINE_EVENT(writeback_inode_template, writeback_lazytime_iput,
Theodore Ts'o0ae45f62015-02-02 00:37:00 -0500733 TP_PROTO(struct inode *inode),
734
735 TP_ARGS(inode)
736);
737
Brian Foster9a46b04f2016-07-26 15:21:53 -0700738DEFINE_EVENT(writeback_inode_template, writeback_dirty_inode_enqueue,
Theodore Ts'o0ae45f62015-02-02 00:37:00 -0500739
740 TP_PROTO(struct inode *inode),
741
742 TP_ARGS(inode)
743);
744
Brian Foster9a46b04f2016-07-26 15:21:53 -0700745/*
746 * Inode writeback list tracking.
747 */
748
749DEFINE_EVENT(writeback_inode_template, sb_mark_inode_writeback,
750 TP_PROTO(struct inode *inode),
751 TP_ARGS(inode)
752);
753
754DEFINE_EVENT(writeback_inode_template, sb_clear_inode_writeback,
755 TP_PROTO(struct inode *inode),
756 TP_ARGS(inode)
757);
758
Dave Chinner455b2862010-07-07 13:24:06 +1000759#endif /* _TRACE_WRITEBACK_H */
760
761/* This part must be outside protection */
762#include <trace/define_trace.h>