1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #define TRACE_SYSTEM writeback
5 #if !defined(LTTNG_TRACE_WRITEBACK_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define LTTNG_TRACE_WRITEBACK_H
8 #include <lttng/tracepoint-event.h>
9 #include <linux/tracepoint.h>
10 #include <linux/backing-dev.h>
11 #include <linux/writeback.h>
12 #include <lttng/kernel-version.h>
14 #ifndef _TRACE_WRITEBACK_DEF_
15 #define _TRACE_WRITEBACK_DEF_
18 * Use the GPL-exported bdi_dev_name introduced in kernel 5.7. Do not use
19 * static inline bdi_dev_name in prior kernels because it uses the bdi_unknown_name
20 * symbol which is not exported to GPL modules.
22 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,7,0))
23 static inline const char *lttng_bdi_dev_name(struct backing_dev_info
*bdi
)
25 return bdi_dev_name(bdi
);
28 static inline const char *lttng_bdi_dev_name(struct backing_dev_info
*bdi
)
30 if (!bdi
|| !bdi
->dev
)
32 return dev_name(bdi
->dev
);
38 * Keep this macro around to track changes in the valid values for `state`.
39 * Eventually, we will have a enum to describe that field. If the macro is
40 * changed by an upstream kernel, the fact that we have a redefinition here
41 * will generate a compiler warning.
43 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0) || \
44 LTTNG_KERNEL_RANGE(4,14,218, 4,15,0) || \
45 LTTNG_KERNEL_RANGE(4,19,172, 4,20,0) || \
46 LTTNG_KERNEL_RANGE(5,4,94, 5,5,0) || \
47 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,141, 4,16,0,0) || \
48 LTTNG_RHEL_KERNEL_RANGE(4,18,0,240,0,0, 4,19,0,0,0,0))
49 #define show_inode_state(state) \
50 __print_flags(state, "|", \
51 {I_DIRTY_SYNC, "I_DIRTY_SYNC"}, \
52 {I_DIRTY_DATASYNC, "I_DIRTY_DATASYNC"}, \
53 {I_DIRTY_PAGES, "I_DIRTY_PAGES"}, \
55 {I_WILL_FREE, "I_WILL_FREE"}, \
56 {I_FREEING, "I_FREEING"}, \
57 {I_CLEAR, "I_CLEAR"}, \
59 {I_DIRTY_TIME, "I_DIRTY_TIME"}, \
60 {I_REFERENCED, "I_REFERENCED"} \
63 #define show_inode_state(state) \
64 __print_flags(state, "|", \
65 {I_DIRTY_SYNC, "I_DIRTY_SYNC"}, \
66 {I_DIRTY_DATASYNC, "I_DIRTY_DATASYNC"}, \
67 {I_DIRTY_PAGES, "I_DIRTY_PAGES"}, \
69 {I_WILL_FREE, "I_WILL_FREE"}, \
70 {I_FREEING, "I_FREEING"}, \
71 {I_CLEAR, "I_CLEAR"}, \
73 {I_DIRTY_TIME, "I_DIRTY_TIME"}, \
74 {I_DIRTY_TIME_EXPIRED, "I_DIRTY_TIME_EXPIRED"}, \
75 {I_REFERENCED, "I_REFERENCED"} \
77 #endif /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
79 LTTNG_TRACEPOINT_EVENT(writeback_dirty_page
,
80 TP_PROTO(struct page
*page
, struct address_space
*mapping
),
81 TP_ARGS(page
, mapping
),
83 ctf_string(name
, lttng_bdi_dev_name(mapping
? inode_to_bdi(mapping
->host
) : NULL
))
84 ctf_integer(unsigned long, ino
, mapping
? mapping
->host
->i_ino
: 0)
85 ctf_integer(pgoff_t
, index
, page
->index
)
89 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_dirty_inode_template
,
90 TP_PROTO(struct inode
*inode
, int flags
),
91 TP_ARGS(inode
, flags
),
93 /* may be called for files on pseudo FSes w/ unregistered bdi */
94 ctf_string(name
, lttng_bdi_dev_name(inode_to_bdi(inode
)))
95 ctf_integer(unsigned long, ino
, inode
->i_ino
)
96 ctf_integer(unsigned long, state
, inode
->i_state
)
97 ctf_integer(unsigned long, flags
, flags
)
100 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(name) \
101 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_dirty_inode_template, name, \
102 TP_PROTO(struct inode *inode, int flags), \
103 TP_ARGS(inode, flags))
104 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_dirty_inode_start
)
105 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_dirty_inode
)
106 LTTNG_TRACEPOINT_EVENT_WRITEBACK_DIRTY_INODE_TEMPLATE(writeback_mark_inode_dirty
)
108 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_write_inode_template
,
109 TP_PROTO(struct inode
*inode
, struct writeback_control
*wbc
),
112 ctf_string(name
, lttng_bdi_dev_name(inode_to_bdi(inode
)))
113 ctf_integer(unsigned long, ino
, inode
->i_ino
)
114 ctf_integer(int, sync_mode
, wbc
->sync_mode
)
118 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(name) \
119 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_write_inode_template, name, \
120 TP_PROTO(struct inode *inode, struct writeback_control *wbc), \
122 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(writeback_write_inode_start
)
123 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WRITE_INODE(writeback_write_inode
)
126 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_work_class
,
127 TP_PROTO(struct bdi_writeback
*wb
, struct wb_writeback_work
*work
),
130 ctf_string(name
, lttng_bdi_dev_name(wb
->bdi
))
134 #define LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(name) \
135 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_work_class, name, \
136 TP_PROTO(struct bdi_writeback *wb, struct wb_writeback_work *work), \
139 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_nothread
)
140 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_queue
)
141 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_exec
)
142 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_start
)
143 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_written
)
144 LTTNG_TRACEPOINT_EVENT_WRITEBACK_WORK_INSTANCE(writeback_wait
)
146 LTTNG_TRACEPOINT_EVENT(writeback_pages_written
,
147 TP_PROTO(long pages_written
),
148 TP_ARGS(pages_written
),
150 ctf_integer(long, pages
, pages_written
)
154 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_class
,
155 TP_PROTO(struct bdi_writeback
*wb
),
158 ctf_string(name
, lttng_bdi_dev_name(wb
->bdi
))
162 #undef DEFINE_WRITEBACK_EVENT
163 #define DEFINE_WRITEBACK_EVENT(name) \
164 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_class, name, \
165 TP_PROTO(struct bdi_writeback *wb), \
168 #define DEFINE_WRITEBACK_EVENT_MAP(name, map) \
169 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(writeback_class, name, map, \
170 TP_PROTO(struct bdi_writeback *wb), \
173 LTTNG_TRACEPOINT_EVENT(writeback_bdi_register
,
174 TP_PROTO(struct backing_dev_info
*bdi
),
177 ctf_string(name
, lttng_bdi_dev_name(bdi
))
181 DEFINE_WRITEBACK_EVENT(writeback_nowork
)
182 DEFINE_WRITEBACK_EVENT(writeback_wake_background
)
183 DEFINE_WRITEBACK_EVENT(writeback_wake_thread
)
184 DEFINE_WRITEBACK_EVENT(writeback_wake_forker_thread
)
185 DEFINE_WRITEBACK_EVENT(writeback_bdi_unregister
)
186 DEFINE_WRITEBACK_EVENT(writeback_thread_start
)
187 DEFINE_WRITEBACK_EVENT(writeback_thread_stop
)
189 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_wbc_class
,
190 TP_PROTO(struct writeback_control
*wbc
, struct backing_dev_info
*bdi
),
193 ctf_string(name
, lttng_bdi_dev_name(bdi
))
194 ctf_integer(long, nr_to_write
, wbc
->nr_to_write
)
195 ctf_integer(long, pages_skipped
, wbc
->pages_skipped
)
196 ctf_integer(int, sync_mode
, wbc
->sync_mode
)
197 ctf_integer(int, for_kupdate
, wbc
->for_kupdate
)
198 ctf_integer(int, for_background
, wbc
->for_background
)
199 ctf_integer(int, for_reclaim
, wbc
->for_reclaim
)
200 ctf_integer(int, range_cyclic
, wbc
->range_cyclic
)
201 ctf_integer(long, range_start
, (long) wbc
->range_start
)
202 ctf_integer(long, range_end
, (long) wbc
->range_end
)
206 #undef DEFINE_WBC_EVENT
207 #define LTTNG_TRACEPOINT_EVENT_WBC_INSTANCE(name, map) \
208 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(writeback_wbc_class, name, map, \
209 TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi), \
211 LTTNG_TRACEPOINT_EVENT_WBC_INSTANCE(wbc_writepage
, writeback_wbc_writepage
)
213 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0) || \
214 LTTNG_KERNEL_RANGE(5,8,6, 5,9,0) || \
215 LTTNG_KERNEL_RANGE(5,4,62, 5,5,0) || \
216 LTTNG_KERNEL_RANGE(4,19,143, 4,20,0) || \
217 LTTNG_KERNEL_RANGE(4,14,196, 4,15,0) || \
218 LTTNG_KERNEL_RANGE(4,9,235, 4,10,0) || \
219 LTTNG_KERNEL_RANGE(4,4,235, 4,5,0) || \
220 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,119, 4,16,0,0) || \
221 LTTNG_RHEL_KERNEL_RANGE(4,18,0,240,0,0, 4,19,0,0,0,0))
222 LTTNG_TRACEPOINT_EVENT(writeback_queue_io
,
223 TP_PROTO(struct bdi_writeback
*wb
,
224 struct wb_writeback_work
*work
,
225 unsigned long dirtied_before
,
227 TP_ARGS(wb
, work
, dirtied_before
, moved
),
229 ctf_string(name
, lttng_bdi_dev_name(wb
->bdi
))
230 ctf_integer(unsigned long, older
, dirtied_before
)
231 ctf_integer(int, moved
, moved
)
235 LTTNG_TRACEPOINT_EVENT(writeback_queue_io
,
236 TP_PROTO(struct bdi_writeback
*wb
,
237 struct wb_writeback_work
*work
,
239 TP_ARGS(wb
, work
, moved
),
241 ctf_string(name
, lttng_bdi_dev_name(wb
->bdi
))
242 ctf_integer(int, moved
, moved
)
247 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,8,0) || \
248 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
249 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state
,
251 writeback_global_dirty_state
,
253 TP_PROTO(unsigned long background_thresh
,
254 unsigned long dirty_thresh
257 TP_ARGS(background_thresh
,
262 ctf_integer(unsigned long, nr_dirty
, global_node_page_state(NR_FILE_DIRTY
))
263 ctf_integer(unsigned long, nr_writeback
, global_node_page_state(NR_WRITEBACK
))
264 ctf_integer(unsigned long, nr_dirtied
, global_node_page_state(NR_DIRTIED
))
265 ctf_integer(unsigned long, nr_written
, global_node_page_state(NR_WRITTEN
))
266 ctf_integer(unsigned long, background_thresh
, background_thresh
)
267 ctf_integer(unsigned long, dirty_thresh
, dirty_thresh
)
268 ctf_integer(unsigned long, dirty_limit
, global_dirty_limit
)
271 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0))
272 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state
,
274 writeback_global_dirty_state
,
276 TP_PROTO(unsigned long background_thresh
,
277 unsigned long dirty_thresh
280 TP_ARGS(background_thresh
,
285 ctf_integer(unsigned long, nr_dirty
, global_node_page_state(NR_FILE_DIRTY
))
286 ctf_integer(unsigned long, nr_writeback
, global_node_page_state(NR_WRITEBACK
))
287 ctf_integer(unsigned long, nr_unstable
, global_node_page_state(NR_UNSTABLE_NFS
))
288 ctf_integer(unsigned long, nr_dirtied
, global_node_page_state(NR_DIRTIED
))
289 ctf_integer(unsigned long, nr_written
, global_node_page_state(NR_WRITTEN
))
290 ctf_integer(unsigned long, background_thresh
, background_thresh
)
291 ctf_integer(unsigned long, dirty_thresh
, dirty_thresh
)
292 ctf_integer(unsigned long, dirty_limit
, global_dirty_limit
)
296 LTTNG_TRACEPOINT_EVENT_MAP(global_dirty_state
,
298 writeback_global_dirty_state
,
300 TP_PROTO(unsigned long background_thresh
,
301 unsigned long dirty_thresh
304 TP_ARGS(background_thresh
,
309 ctf_integer(unsigned long, nr_dirty
, global_page_state(NR_FILE_DIRTY
))
310 ctf_integer(unsigned long, nr_writeback
, global_page_state(NR_WRITEBACK
))
311 ctf_integer(unsigned long, nr_unstable
, global_page_state(NR_UNSTABLE_NFS
))
312 ctf_integer(unsigned long, nr_dirtied
, global_page_state(NR_DIRTIED
))
313 ctf_integer(unsigned long, nr_written
, global_page_state(NR_WRITTEN
))
314 ctf_integer(unsigned long, background_thresh
, background_thresh
)
315 ctf_integer(unsigned long, dirty_thresh
, dirty_thresh
)
316 ctf_integer(unsigned long, dirty_limit
, global_dirty_limit
)
321 #define KBps(x) ((x) << (PAGE_SHIFT - 10))
323 LTTNG_TRACEPOINT_EVENT_MAP(bdi_dirty_ratelimit
,
325 writeback_bdi_dirty_ratelimit
,
327 TP_PROTO(struct bdi_writeback
*wb
,
328 unsigned long dirty_rate
,
329 unsigned long task_ratelimit
),
331 TP_ARGS(wb
, dirty_rate
, task_ratelimit
),
334 ctf_string(bdi
, lttng_bdi_dev_name(wb
->bdi
))
335 ctf_integer(unsigned long, write_bw
, KBps(wb
->bdi
->wb
.write_bandwidth
))
336 ctf_integer(unsigned long, avg_write_bw
, KBps(wb
->bdi
->wb
.avg_write_bandwidth
))
337 ctf_integer(unsigned long, dirty_rate
, KBps(dirty_rate
))
338 ctf_integer(unsigned long, dirty_ratelimit
, KBps(wb
->bdi
->wb
.dirty_ratelimit
))
339 ctf_integer(unsigned long, task_ratelimit
, KBps(task_ratelimit
))
340 ctf_integer(unsigned long, balanced_dirty_ratelimit
,
341 KBps(wb
->bdi
->wb
.balanced_dirty_ratelimit
))
345 LTTNG_TRACEPOINT_EVENT_MAP(balance_dirty_pages
,
347 writeback_balance_dirty_pages
,
349 TP_PROTO(struct bdi_writeback
*wb
,
350 unsigned long thresh
,
351 unsigned long bg_thresh
,
353 unsigned long bdi_thresh
,
354 unsigned long bdi_dirty
,
355 unsigned long dirty_ratelimit
,
356 unsigned long task_ratelimit
,
357 unsigned long dirtied
,
358 unsigned long period
,
360 unsigned long start_time
),
362 TP_ARGS(wb
, thresh
, bg_thresh
, dirty
, bdi_thresh
, bdi_dirty
,
363 dirty_ratelimit
, task_ratelimit
,
364 dirtied
, period
, pause
, start_time
368 ctf_string(bdi
, lttng_bdi_dev_name(wb
->bdi
))
369 ctf_integer(unsigned long, limit
, global_dirty_limit
)
370 ctf_integer(unsigned long, setpoint
,
371 (global_dirty_limit
+ (thresh
+ bg_thresh
) / 2) / 2)
372 ctf_integer(unsigned long, dirty
, dirty
)
373 ctf_integer(unsigned long, bdi_setpoint
,
374 ((global_dirty_limit
+ (thresh
+ bg_thresh
) / 2) / 2) *
375 bdi_thresh
/ (thresh
+ 1))
376 ctf_integer(unsigned long, bdi_dirty
, bdi_dirty
)
377 ctf_integer(unsigned long, dirty_ratelimit
,
378 KBps(dirty_ratelimit
))
379 ctf_integer(unsigned long, task_ratelimit
,
380 KBps(task_ratelimit
))
381 ctf_integer(unsigned int, dirtied
, dirtied
)
382 ctf_integer(unsigned int, dirtied_pause
,
383 current
->nr_dirtied_pause
)
384 ctf_integer(unsigned long, paused
,
385 (jiffies
- start_time
) * 1000 / HZ
)
386 ctf_integer(long, pause
, pause
* 1000 / HZ
)
387 ctf_integer(unsigned long, period
,
389 ctf_integer(long, think
,
390 current
->dirty_paused_when
== 0 ? 0 :
391 (long)(jiffies
- current
->dirty_paused_when
) * 1000/HZ
)
395 LTTNG_TRACEPOINT_EVENT(writeback_sb_inodes_requeue
,
397 TP_PROTO(struct inode
*inode
),
401 ctf_string(name
, lttng_bdi_dev_name(inode_to_bdi(inode
)))
402 ctf_integer(unsigned long, ino
, inode
->i_ino
)
403 ctf_integer(unsigned long, state
, inode
->i_state
)
404 ctf_integer(unsigned long, dirtied_when
, inode
->dirtied_when
)
408 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_congest_waited_template
,
410 TP_PROTO(unsigned int usec_timeout
, unsigned int usec_delayed
),
412 TP_ARGS(usec_timeout
, usec_delayed
),
415 ctf_integer(unsigned int, usec_timeout
, usec_timeout
)
416 ctf_integer(unsigned int, usec_delayed
, usec_delayed
)
420 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_congest_waited_template
, writeback_congestion_wait
,
422 TP_PROTO(unsigned int usec_timeout
, unsigned int usec_delayed
),
424 TP_ARGS(usec_timeout
, usec_delayed
)
427 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_congest_waited_template
, writeback_wait_iff_congested
,
429 TP_PROTO(unsigned int usec_timeout
, unsigned int usec_delayed
),
431 TP_ARGS(usec_timeout
, usec_delayed
)
434 LTTNG_TRACEPOINT_EVENT_CLASS(writeback_single_inode_template
,
436 TP_PROTO(struct inode
*inode
,
437 struct writeback_control
*wbc
,
438 unsigned long nr_to_write
441 TP_ARGS(inode
, wbc
, nr_to_write
),
444 ctf_string(name
, lttng_bdi_dev_name(inode_to_bdi(inode
)))
445 ctf_integer(unsigned long, ino
, inode
->i_ino
)
446 ctf_integer(unsigned long, state
, inode
->i_state
)
447 ctf_integer(unsigned long, dirtied_when
, inode
->dirtied_when
)
448 ctf_integer(unsigned long, writeback_index
,
449 inode
->i_mapping
->writeback_index
)
450 ctf_integer(long, nr_to_write
, nr_to_write
)
451 ctf_integer(unsigned long, wrote
,
452 nr_to_write
- wbc
->nr_to_write
)
456 LTTNG_TRACEPOINT_EVENT_INSTANCE(writeback_single_inode_template
, writeback_single_inode
,
457 TP_PROTO(struct inode
*inode
,
458 struct writeback_control
*wbc
,
459 unsigned long nr_to_write
),
460 TP_ARGS(inode
, wbc
, nr_to_write
)
463 #endif /* LTTNG_TRACE_WRITEBACK_H */
465 /* This part must be outside protection */
466 #include <lttng/define_trace.h>