1 // SPDX-FileCopyrightText: 2012 Andrew Gabbasov <andrew_gabbasov@mentor.com>
3 // SPDX-License-Identifier: GPL-2.0-only
6 #define TRACE_SYSTEM writeback
8 #if !defined(LTTNG_TRACE_WRITEBACK_H) || defined(TRACE_HEADER_MULTI_READ)
9 #define LTTNG_TRACE_WRITEBACK_H
11 #include <lttng/tracepoint-event.h>
12 #include <linux/tracepoint.h>
13 #include <linux/backing-dev.h>
14 #include <linux/writeback.h>
15 #include <lttng/kernel-version.h>
17 #ifndef _TRACE_WRITEBACK_DEF_
18 #define _TRACE_WRITEBACK_DEF_
21 * Use the GPL-exported bdi_dev_name introduced in kernel 5.7. Do not use
22 * static inline bdi_dev_name in prior kernels because it uses the bdi_unknown_name
23 * symbol which is not exported to GPL modules.
25 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,7,0))
26 static inline const char *lttng_bdi_dev_name(struct backing_dev_info
*bdi
)
28 return bdi_dev_name(bdi
);
31 static inline const char *lttng_bdi_dev_name(struct backing_dev_info
*bdi
)
33 if (!bdi
|| !bdi
->dev
)
35 return dev_name(bdi
->dev
);
41 * Keep this macro around to track changes in the valid values for `state`.
42 * Eventually, we will have a enum to describe that field. If the macro is
43 * changed by an upstream kernel, the fact that we have a redefinition here
44 * will generate a compiler warning.
46 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0) || \
47 LTTNG_KERNEL_RANGE(4,14,218, 4,15,0) || \
48 LTTNG_KERNEL_RANGE(4,19,172, 4,20,0) || \
49 LTTNG_KERNEL_RANGE(5,4,94, 5,5,0) || \
50 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,141, 4,16,0,0) || \
51 LTTNG_RHEL_KERNEL_RANGE(4,18,0,240,0,0, 4,19,0,0,0,0))
52 #define show_inode_state(state) \
53 __print_flags(state, "|", \
54 {I_DIRTY_SYNC, "I_DIRTY_SYNC"}, \
55 {I_DIRTY_DATASYNC, "I_DIRTY_DATASYNC"}, \
56 {I_DIRTY_PAGES, "I_DIRTY_PAGES"}, \
58 {I_WILL_FREE, "I_WILL_FREE"}, \
59 {I_FREEING, "I_FREEING"}, \
60 {I_CLEAR, "I_CLEAR"}, \
62 {I_DIRTY_TIME, "I_DIRTY_TIME"}, \
63 {I_REFERENCED, "I_REFERENCED"} \
66 #define show_inode_state(state) \
67 __print_flags(state, "|", \
68 {I_DIRTY_SYNC, "I_DIRTY_SYNC"}, \
69 {I_DIRTY_DATASYNC, "I_DIRTY_DATASYNC"}, \
70 {I_DIRTY_PAGES, "I_DIRTY_PAGES"}, \
72 {I_WILL_FREE, "I_WILL_FREE"}, \
73 {I_FREEING, "I_FREEING"}, \
74 {I_CLEAR, "I_CLEAR"}, \
76 {I_DIRTY_TIME, "I_DIRTY_TIME"}, \
77 {I_DIRTY_TIME_EXPIRED, "I_DIRTY_TIME_EXPIRED"}, \
78 {I_REFERENCED, "I_REFERENCED"} \
80 #endif /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
82 LTTNG_TRACEPOINT_EVENT(writeback_dirty_page
,
83 TP_PROTO(struct page
*page
, struct address_space
*mapping
),
84 TP_ARGS(page
, mapping
),
86 ctf_string(name
, lttng_bdi_dev_name(mapping
? inode_to_bdi(mapping
->host
) : NULL
))
87 ctf_integer(unsigned long, ino
, mapping
? mapping
->host
->i_ino
: 0)
88 ctf_integer(pgoff_t
, index
, page
->index
)
92 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_dirty_inode_template
,
93 TP_PROTO(struct inode
*inode
, int flags
),
94 TP_ARGS(inode
, flags
),
96 /* may be called for files on pseudo FSes w/ unregistered bdi */
97 ctf_string(name
, lttng_bdi_dev_name(inode_to_bdi(inode
)))
98 ctf_integer(unsigned long, ino
, inode
->i_ino
)
99 ctf_integer(unsigned long, state
, inode
->i_state
)
100 ctf_integer(unsigned long, flags
, flags
)
103 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(name) \
104 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_dirty_inode_template, name, \
105 TP_PROTO(struct inode *inode, int flags), \
106 TP_ARGS(inode, flags))
107 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_dirty_inode_start
)
108 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_dirty_inode
)
109 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_mark_inode_dirty
)
111 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_write_inode_template
,
112 TP_PROTO(struct inode
*inode
, struct writeback_control
*wbc
),
115 ctf_string(name
, lttng_bdi_dev_name(inode_to_bdi(inode
)))
116 ctf_integer(unsigned long, ino
, inode
->i_ino
)
117 ctf_integer(int, sync_mode
, wbc
->sync_mode
)
121 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(name) \
122 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_write_inode_template, name, \
123 TP_PROTO(struct inode *inode, struct writeback_control *wbc), \
125 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(writeback_write_inode_start
)
126 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(writeback_write_inode
)
129 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_work_class
,
130 TP_PROTO(struct bdi_writeback
*wb
, struct wb_writeback_work
*work
),
133 ctf_string(name
, lttng_bdi_dev_name(wb
->bdi
))
137 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(name) \
138 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_work_class, name, \
139 TP_PROTO(struct bdi_writeback *wb, struct wb_writeback_work *work), \
142 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_nothread
)
143 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_queue
)
144 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_exec
)
145 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_start
)
146 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_written
)
147 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_wait
)
149 LTTNG_TRACEPOINT_EVENT(writeback_pages_written
,
150 TP_PROTO(long pages_written
),
151 TP_ARGS(pages_written
),
153 ctf_integer(long, pages
, pages_written
)
157 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_class
,
158 TP_PROTO(struct bdi_writeback
*wb
),
161 ctf_string(name
, lttng_bdi_dev_name(wb
->bdi
))
165 #undef DEFINE_WRITEBACK_EVENT
166 #define DEFINE_WRITEBACK_EVENT(name) \
167 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_class, name, \
168 TP_PROTO(struct bdi_writeback *wb), \
171 #define DEFINE_WRITEBACK_EVENT_MAP(name, map) \
172 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(writeback_class, name, map, \
173 TP_PROTO(struct bdi_writeback *wb), \
176 LTTNG_TRACEPOINT_EVENT(writeback_bdi_register
,
177 TP_PROTO(struct backing_dev_info
*bdi
),
180 ctf_string(name
, lttng_bdi_dev_name(bdi
))
184 DEFINE_WRITEBACK_EVENT(writeback_nowork
)
185 DEFINE_WRITEBACK_EVENT(writeback_wake_background
)
186 DEFINE_WRITEBACK_EVENT(writeback_wake_thread
)
187 DEFINE_WRITEBACK_EVENT(writeback_wake_forker_thread
)
188 DEFINE_WRITEBACK_EVENT(writeback_bdi_unregister
)
189 DEFINE_WRITEBACK_EVENT(writeback_thread_start
)
190 DEFINE_WRITEBACK_EVENT(writeback_thread_stop
)
192 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_wbc_class
,
193 TP_PROTO(struct writeback_control
*wbc
, struct backing_dev_info
*bdi
),
196 ctf_string(name
, lttng_bdi_dev_name(bdi
))
197 ctf_integer(long, nr_to_write
, wbc
->nr_to_write
)
198 ctf_integer(long, pages_skipped
, wbc
->pages_skipped
)
199 ctf_integer(int, sync_mode
, wbc
->sync_mode
)
200 ctf_integer(int, for_kupdate
, wbc
->for_kupdate
)
201 ctf_integer(int, for_background
, wbc
->for_background
)
202 ctf_integer(int, for_reclaim
, wbc
->for_reclaim
)
203 ctf_integer(int, range_cyclic
, wbc
->range_cyclic
)
204 ctf_integer(long, range_start
, (long) wbc
->range_start
)
205 ctf_integer(long, range_end
, (long) wbc
->range_end
)
209 #undef DEFINE_WBC_EVENT
210 #define LTTNG_TRACEPOINT_EVENT_WBC_INSTANCE(name, map) \
211 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(writeback_wbc_class, name, map, \
212 TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi), \
214 LTTNG_TRACEPOINT_EVENT_WBC_INSTANCE(wbc_writepage
, writeback_wbc_writepage
)
216 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0) || \
217 LTTNG_KERNEL_RANGE(5,8,6, 5,9,0) || \
218 LTTNG_KERNEL_RANGE(5,4,62, 5,5,0) || \
219 LTTNG_KERNEL_RANGE(4,19,143, 4,20,0) || \
220 LTTNG_KERNEL_RANGE(4,14,196, 4,15,0) || \
221 LTTNG_KERNEL_RANGE(4,9,235, 4,10,0) || \
222 LTTNG_KERNEL_RANGE(4,4,235, 4,5,0) || \
223 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,119, 4,16,0,0) || \
224 LTTNG_RHEL_KERNEL_RANGE(4,18,0,240,0,0, 4,19,0,0,0,0))
225 LTTNG_TRACEPOINT_EVENT(writeback_queue_io
,
226 TP_PROTO(struct bdi_writeback
*wb
,
227 struct wb_writeback_work
*work
,
228 unsigned long dirtied_before
,
230 TP_ARGS(wb
, work
, dirtied_before
, moved
),
232 ctf_string(name
, lttng_bdi_dev_name(wb
->bdi
))
233 ctf_integer(unsigned long, older
, dirtied_before
)
234 ctf_integer(int, moved
, moved
)
238 LTTNG_TRACEPOINT_EVENT(writeback_queue_io
,
239 TP_PROTO(struct bdi_writeback
*wb
,
240 struct wb_writeback_work
*work
,
242 TP_ARGS(wb
, work
, moved
),
244 ctf_string(name
, lttng_bdi_dev_name(wb
->bdi
))
245 ctf_integer(int, moved
, moved
)
250 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,8,0) || \
251 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
252 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state
,
254 writeback_global_dirty_state
,
256 TP_PROTO(unsigned long background_thresh
,
257 unsigned long dirty_thresh
260 TP_ARGS(background_thresh
,
265 ctf_integer(unsigned long, nr_dirty
, global_node_page_state(NR_FILE_DIRTY
))
266 ctf_integer(unsigned long, nr_writeback
, global_node_page_state(NR_WRITEBACK
))
267 ctf_integer(unsigned long, nr_dirtied
, global_node_page_state(NR_DIRTIED
))
268 ctf_integer(unsigned long, nr_written
, global_node_page_state(NR_WRITTEN
))
269 ctf_integer(unsigned long, background_thresh
, background_thresh
)
270 ctf_integer(unsigned long, dirty_thresh
, dirty_thresh
)
271 ctf_integer(unsigned long, dirty_limit
, global_dirty_limit
)
274 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0))
275 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state
,
277 writeback_global_dirty_state
,
279 TP_PROTO(unsigned long background_thresh
,
280 unsigned long dirty_thresh
283 TP_ARGS(background_thresh
,
288 ctf_integer(unsigned long, nr_dirty
, global_node_page_state(NR_FILE_DIRTY
))
289 ctf_integer(unsigned long, nr_writeback
, global_node_page_state(NR_WRITEBACK
))
290 ctf_integer(unsigned long, nr_unstable
, global_node_page_state(NR_UNSTABLE_NFS
))
291 ctf_integer(unsigned long, nr_dirtied
, global_node_page_state(NR_DIRTIED
))
292 ctf_integer(unsigned long, nr_written
, global_node_page_state(NR_WRITTEN
))
293 ctf_integer(unsigned long, background_thresh
, background_thresh
)
294 ctf_integer(unsigned long, dirty_thresh
, dirty_thresh
)
295 ctf_integer(unsigned long, dirty_limit
, global_dirty_limit
)
299 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state
,
301 writeback_global_dirty_state
,
303 TP_PROTO(unsigned long background_thresh
,
304 unsigned long dirty_thresh
307 TP_ARGS(background_thresh
,
312 ctf_integer(unsigned long, nr_dirty
, global_page_state(NR_FILE_DIRTY
))
313 ctf_integer(unsigned long, nr_writeback
, global_page_state(NR_WRITEBACK
))
314 ctf_integer(unsigned long, nr_unstable
, global_page_state(NR_UNSTABLE_NFS
))
315 ctf_integer(unsigned long, nr_dirtied
, global_page_state(NR_DIRTIED
))
316 ctf_integer(unsigned long, nr_written
, global_page_state(NR_WRITTEN
))
317 ctf_integer(unsigned long, background_thresh
, background_thresh
)
318 ctf_integer(unsigned long, dirty_thresh
, dirty_thresh
)
319 ctf_integer(unsigned long, dirty_limit
, global_dirty_limit
)
324 #define KBps(x) ((x) << (PAGE_SHIFT - 10))
326 LTTNG_TRACEPOINT_EVENT_MAP(bdi_dirty_ratelimit
,
328 writeback_bdi_dirty_ratelimit
,
330 TP_PROTO(struct bdi_writeback
*wb
,
331 unsigned long dirty_rate
,
332 unsigned long task_ratelimit
),
334 TP_ARGS(wb
, dirty_rate
, task_ratelimit
),
337 ctf_string(bdi
, lttng_bdi_dev_name(wb
->bdi
))
338 ctf_integer(unsigned long, write_bw
, KBps(wb
->bdi
->wb
.write_bandwidth
))
339 ctf_integer(unsigned long, avg_write_bw
, KBps(wb
->bdi
->wb
.avg_write_bandwidth
))
340 ctf_integer(unsigned long, dirty_rate
, KBps(dirty_rate
))
341 ctf_integer(unsigned long, dirty_ratelimit
, KBps(wb
->bdi
->wb
.dirty_ratelimit
))
342 ctf_integer(unsigned long, task_ratelimit
, KBps(task_ratelimit
))
343 ctf_integer(unsigned long, balanced_dirty_ratelimit
,
344 KBps(wb
->bdi
->wb
.balanced_dirty_ratelimit
))
348 LTTNG_TRACEPOINT_EVENT_MAP(balance_dirty_pages
,
350 writeback_balance_dirty_pages
,
352 TP_PROTO(struct bdi_writeback
*wb
,
353 unsigned long thresh
,
354 unsigned long bg_thresh
,
356 unsigned long bdi_thresh
,
357 unsigned long bdi_dirty
,
358 unsigned long dirty_ratelimit
,
359 unsigned long task_ratelimit
,
360 unsigned long dirtied
,
361 unsigned long period
,
363 unsigned long start_time
),
365 TP_ARGS(wb
, thresh
, bg_thresh
, dirty
, bdi_thresh
, bdi_dirty
,
366 dirty_ratelimit
, task_ratelimit
,
367 dirtied
, period
, pause
, start_time
371 ctf_string(bdi
, lttng_bdi_dev_name(wb
->bdi
))
372 ctf_integer(unsigned long, limit
, global_dirty_limit
)
373 ctf_integer(unsigned long, setpoint
,
374 (global_dirty_limit
+ (thresh
+ bg_thresh
) / 2) / 2)
375 ctf_integer(unsigned long, dirty
, dirty
)
376 ctf_integer(unsigned long, bdi_setpoint
,
377 ((global_dirty_limit
+ (thresh
+ bg_thresh
) / 2) / 2) *
378 bdi_thresh
/ (thresh
+ 1))
379 ctf_integer(unsigned long, bdi_dirty
, bdi_dirty
)
380 ctf_integer(unsigned long, dirty_ratelimit
,
381 KBps(dirty_ratelimit
))
382 ctf_integer(unsigned long, task_ratelimit
,
383 KBps(task_ratelimit
))
384 ctf_integer(unsigned int, dirtied
, dirtied
)
385 ctf_integer(unsigned int, dirtied_pause
,
386 current
->nr_dirtied_pause
)
387 ctf_integer(unsigned long, paused
,
388 (jiffies
- start_time
) * 1000 / HZ
)
389 ctf_integer(long, pause
, pause
* 1000 / HZ
)
390 ctf_integer(unsigned long, period
,
392 ctf_integer(long, think
,
393 current
->dirty_paused_when
== 0 ? 0 :
394 (long)(jiffies
- current
->dirty_paused_when
) * 1000/HZ
)
398 LTTNG_TRACEPOINT_EVENT(writeback_sb_inodes_requeue
,
400 TP_PROTO(struct inode
*inode
),
404 ctf_string(name
, lttng_bdi_dev_name(inode_to_bdi(inode
)))
405 ctf_integer(unsigned long, ino
, inode
->i_ino
)
406 ctf_integer(unsigned long, state
, inode
->i_state
)
407 ctf_integer(unsigned long, dirtied_when
, inode
->dirtied_when
)
411 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_congest_waited_template
,
413 TP_PROTO(unsigned int usec_timeout
, unsigned int usec_delayed
),
415 TP_ARGS(usec_timeout
, usec_delayed
),
418 ctf_integer(unsigned int, usec_timeout
, usec_timeout
)
419 ctf_integer(unsigned int, usec_delayed
, usec_delayed
)
423 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_congest_waited_template
, writeback_congestion_wait
,
425 TP_PROTO(unsigned int usec_timeout
, unsigned int usec_delayed
),
427 TP_ARGS(usec_timeout
, usec_delayed
)
430 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_congest_waited_template
, writeback_wait_iff_congested
,
432 TP_PROTO(unsigned int usec_timeout
, unsigned int usec_delayed
),
434 TP_ARGS(usec_timeout
, usec_delayed
)
437 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_single_inode_template
,
439 TP_PROTO(struct inode
*inode
,
440 struct writeback_control
*wbc
,
441 unsigned long nr_to_write
444 TP_ARGS(inode
, wbc
, nr_to_write
),
447 ctf_string(name
, lttng_bdi_dev_name(inode_to_bdi(inode
)))
448 ctf_integer(unsigned long, ino
, inode
->i_ino
)
449 ctf_integer(unsigned long, state
, inode
->i_state
)
450 ctf_integer(unsigned long, dirtied_when
, inode
->dirtied_when
)
451 ctf_integer(unsigned long, writeback_index
,
452 inode
->i_mapping
->writeback_index
)
453 ctf_integer(long, nr_to_write
, nr_to_write
)
454 ctf_integer(unsigned long, wrote
,
455 nr_to_write
- wbc
->nr_to_write
)
459 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_single_inode_template
, writeback_single_inode
,
460 TP_PROTO(struct inode
*inode
,
461 struct writeback_control
*wbc
,
462 unsigned long nr_to_write
),
463 TP_ARGS(inode
, wbc
, nr_to_write
)
466 #endif /* LTTNG_TRACE_WRITEBACK_H */
468 /* This part must be outside protection */
469 #include <lttng/define_trace.h>