f2fs: add a tracepoint for discard thread

Message ID 20230419163131.7682-1-frank.li@vivo.com
State New
Headers
Series f2fs: add a tracepoint for discard thread |

Commit Message

李扬韬 April 19, 2023, 4:31 p.m. UTC
  This patch introduces a tracepoint to monitor discard thread behaviors.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/f2fs/segment.c           |  3 +++
 include/trace/events/f2fs.h | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
  

Patch

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 641bd8cc54da..e27ad310186c 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1839,6 +1839,9 @@  static int issue_discard_thread(void *data)
 		if (!atomic_read(&dcc->discard_cmd_cnt))
 			wait_ms = dpolicy.max_interval;
 
+		trace_f2fs_discard_thread(sbi->sb, wait_ms, dcc->undiscard_blks,
+				atomic_read(&dcc->discard_cmd_cnt));
+
 		sb_end_intwrite(sbi->sb);
 
 	} while (!kthread_should_stop());
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 99cbc5949e3c..e1939427deb2 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -1512,6 +1512,34 @@  DEFINE_EVENT(f2fs_discard, f2fs_remove_discard,
 	TP_ARGS(dev, blkstart, blklen)
 );
 
+TRACE_EVENT(f2fs_discard_thread,
+
+	TP_PROTO(struct super_block *sb, unsigned int wait_ms,
+			unsigned int undiscard_blks, unsigned int discard_cmd_cnt),
+
+	TP_ARGS(sb, wait_ms, undiscard_blks, discard_cmd_cnt),
+
+	TP_STRUCT__entry(
+		__field(dev_t,	dev)
+		__field(unsigned int, wait_ms)
+		__field(unsigned int, undiscard_blks)
+		__field(unsigned int, discard_cmd_cnt)
+	),
+
+	TP_fast_assign(
+		__entry->dev = sb->s_dev;
+		__entry->wait_ms = wait_ms;
+		__entry->undiscard_blks = undiscard_blks;
+		__entry->discard_cmd_cnt = discard_cmd_cnt;
+	),
+
+	TP_printk("dev = (%d,%d), wait_ms = %u, undiscard_blks = %u, discard_cmd_cnt = %u",
+		show_dev(__entry->dev),
+		__entry->wait_ms,
+		__entry->undiscard_blks,
+		__entry->discard_cmd_cnt)
+);
+
 TRACE_EVENT(f2fs_issue_reset_zone,
 
 	TP_PROTO(struct block_device *dev, block_t blkstart),