[PATCH v3] f2fs: add checkpoint step timing statistics to debugfs
From: huang zheng
Date: Tue Nov 17 2026 - 02:00:36 EST
From: Huang Zheng <huangzheng9869@xxxxxxxxx>
This patch adds detailed timing statistics for each checkpoint step
to the debugfs stat_show interface. It displays the time taken by
each phase of the checkpoint process, including:
- lock acquisition
- block operations
- flushing data/node/meta pages
- flushing NAT/SIT
- syncing metadata
- waiting for dirty meta/checkpoint data
- device flushing
- waiting for last checkpoint
This information is valuable for debugging checkpoint performance
issues and identifying which steps are taking the most time during
the checkpoint process.
The statistics show the longest recorded time for each step, helping
developers and users understand where checkpoint bottlenecks occur.
Signed-off-by: Huang Zheng <huangzheng1@xxxxxxxxxx>
---
v2:
- Use the global lock f2fs_stat_lock to keep statistics consistent
when updating cp stat data in the super block
- The qualify test result as follow:
#cat /sys/kernel/debug/f2fs/status
CP steps (longest):
- Total : 524(ms)
- lock : 0(ms)
- block_operation : 13(ms)
- flush_data_node_meta : 0(ms)
- flush_nat : 93(ms)
- flush_sit : 56(ms)
- sync_meta : 32(ms)
- sync_cp_meta : 0(ms)
- wait_dirty_meta : 0(ms)
- wait_cp_data : 0(ms)
- flush_device : 0(ms)
- wait_last_cp : 0(ms)
- unblock_operation : 327(ms)
v3:
- As `f2fs_stat_lock` depends on `CONFIG_DEBUG_FS`, `check_cp_time` updates stats even when `CONFIG_DEBUG_FS` is disabled.
Revise the stat concurrency protection using `stat_lock` resides in `f2fs_sb_info`.
---
fs/f2fs/checkpoint.c | 2 ++
fs/f2fs/debug.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 5c5b45d3c67b..bbf8bc9a9f34 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1738,7 +1738,9 @@ static inline void check_cp_time(struct f2fs_sb_info *sbi, struct cp_control *cp
cpc->stats.times[CP_TIME_START]);
if (cur_diff > sb_diff) {
+ spin_lock(&sbi->stat_lock);
sbi->cp_stats = cpc->stats;
+ spin_unlock(&sbi->stat_lock);
if (cur_diff < CP_LONG_LATENCY_THRESHOLD)
return;
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 6fe606e2c70d..4fa44eb38bc8 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -445,9 +445,26 @@ static const char *ipu_mode_names[F2FS_IPU_MAX] = {
[F2FS_IPU_HONOR_OPU_WRITE] = "HONOR_OPU_WRITE",
};
+static const char *cp_time_names[CP_TIME_MAX] = {
+ [CP_TIME_START] = "begin",
+ [CP_TIME_LOCK] = "lock",
+ [CP_TIME_OP_LOCK] = "block_operation",
+ [CP_TIME_MERGE_WRITE] = "flush_data_node_meta",
+ [CP_TIME_FLUSH_NAT] = "flush_nat",
+ [CP_TIME_FLUSH_SIT] = "flush_sit",
+ [CP_TIME_SYNC_META] = "sync_meta",
+ [CP_TIME_SYNC_CP_META] = "sync_cp_meta",
+ [CP_TIME_WAIT_DIRTY_META] = "wait_dirty_meta",
+ [CP_TIME_WAIT_CP_DATA] = "wait_cp_data",
+ [CP_TIME_FLUSH_DEVICE] = "flush_device",
+ [CP_TIME_WAIT_LAST_CP] = "wait_last_cp",
+ [CP_TIME_END] = "unblock_operation",
+};
+
static int stat_show(struct seq_file *s, void *v)
{
struct f2fs_stat_info *si;
+ struct cp_stats ct;
int i = 0, j = 0;
spin_lock(&f2fs_stat_lock);
@@ -631,6 +648,19 @@ static int stat_show(struct seq_file *s, void *v)
seq_printf(s, " - Total : %4d\n", si->nr_total_ckpt);
seq_printf(s, " - Cur time : %4d(ms)\n", si->cur_ckpt_time);
seq_printf(s, " - Peak time : %4d(ms)\n", si->peak_ckpt_time);
+
+ spin_lock(&sbi->stat_lock);
+ ct = sbi->cp_stats;
+ spin_unlock(&sbi->stat_lock);
+
+ seq_puts(s, "CP steps (longest):\n");
+ seq_printf(s, " - Total : %llu(ms)\n",
+ (u64)ktime_ms_delta(ct.times[CP_TIME_END],
+ ct.times[CP_TIME_START]));
+ for (j = 0; j < CP_TIME_MAX - 1; j++)
+ seq_printf(s, " - %s : %llu(ms)\n", cp_time_names[j + 1],
+ (u64)ktime_ms_delta(ct.times[j + 1], ct.times[j]));
+
seq_printf(s, "GC calls: %d (gc_thread: %d)\n",
si->gc_call_count[BACKGROUND] +
si->gc_call_count[FOREGROUND],
--
2.43.0