[PATCH v2] f2fs: add checkpoint step timing statistics to debugfs

From: huang zheng

Date: Mon Nov 16 2026 - 04:50:28 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)

---
fs/f2fs/checkpoint.c | 2 +-
fs/f2fs/debug.c | 31 +++++++++++++++++++++++++++++++
fs/f2fs/f2fs.h | 1 +
3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 5c5b45d3c67b..b407adb9bf18 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1738,7 +1738,7 @@ 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) {
- sbi->cp_stats = cpc->stats;
+ update_cp_stats(sbi, cpc);
if (cur_diff < CP_LONG_LATENCY_THRESHOLD)
return;

diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 6fe606e2c70d..7ff124784c1b 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -414,6 +414,13 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
#endif
}

+void update_cp_stats(struct f2fs_sb_info *sbi, struct cp_control *cpc)
+{
+ spin_lock(&f2fs_stat_lock);
+ sbi->cp_stats = cpc->stats;
+ spin_unlock(&f2fs_stat_lock);
+}
+
static const char *s_flag[MAX_SBI_FLAG] = {
[SBI_IS_DIRTY] = "fs_dirty",
[SBI_IS_CLOSE] = "closing",
@@ -445,6 +452,22 @@ 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;
@@ -631,6 +654,14 @@ 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);
+ seq_puts(s, "CP steps (longest):\n");
+ seq_printf(s, " - Total : %llu(ms)\n",
+ (u64)ktime_ms_delta(sbi->cp_stats.times[CP_TIME_END],
+ sbi->cp_stats.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(sbi->cp_stats.times[j + 1],
+ sbi->cp_stats.times[j]));
seq_printf(s, "GC calls: %d (gc_thread: %d)\n",
si->gc_call_count[BACKGROUND] +
si->gc_call_count[FOREGROUND],
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index f7423b3f6e4a..0f1255ff93d5 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4642,6 +4642,7 @@ void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
void __init f2fs_create_root_stats(void);
void f2fs_destroy_root_stats(void);
void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
+void update_cp_stats(struct f2fs_sb_info *sbi, struct cp_control *cpc);
#else
#define stat_inc_cp_call_count(sbi, foreground) do { } while (0)
#define stat_inc_cp_count(sbi) do { } while (0)
--
2.43.0