mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] f2fs: add checkpoint step timing statistics to debugfs
@ 2026-11-16  9:50 huang zheng
  2026-11-16 16:24 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: huang zheng @ 2026-11-16  9:50 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, huangzheng1, Huang Zheng

From: Huang Zheng <huangzheng9869@gmail.com>

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@xiaomi.com>
---
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] f2fs: add checkpoint step timing statistics to debugfs
  2026-11-16  9:50 [PATCH v2] f2fs: add checkpoint step timing statistics to debugfs huang zheng
@ 2026-11-16 16:24 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2026-11-16 16:24 UTC (permalink / raw)
  To: huang zheng, jaegeuk, chao
  Cc: oe-kbuild-all, linux-f2fs-devel, linux-kernel, huangzheng1, Huang Zheng

Hi huang,

kernel test robot noticed the following build errors:

[auto build test ERROR on jaegeuk-f2fs/dev-test]
[also build test ERROR on jaegeuk-f2fs/dev linus/master v7.4-rc3 next-20261113]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/huang-zheng/f2fs-add-checkpoint-step-timing-statistics-to-debugfs/20261116-175011
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test
patch link:    https://lore.kernel.org/r/20261116095011.2868219-1-huangzheng9869%40gmail.com
patch subject: [PATCH v2] f2fs: add checkpoint step timing statistics to debugfs
config: i386-buildonly-randconfig-1000-20261116 (https://download.01.org/0day-ci/archive/20261117/202611170005.Q9ISJ71Q-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261117/202611170005.Q9ISJ71Q-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611170005.Q9ISJ71Q-lkp@intel.com/

All errors (new ones prefixed by >>):

   fs/f2fs/checkpoint.c: In function 'check_cp_time':
>> fs/f2fs/checkpoint.c:1744:17: error: implicit declaration of function 'update_cp_stats'; did you mean 'update_ckpt_flags'? [-Wimplicit-function-declaration]
    1744 |                 update_cp_stats(sbi, cpc);
         |                 ^~~~~~~~~~~~~~~
         |                 update_ckpt_flags


vim +1744 fs/f2fs/checkpoint.c

  1732	
  1733	static inline void check_cp_time(struct f2fs_sb_info *sbi, struct cp_control *cpc)
  1734	{
  1735		unsigned long long sb_diff, cur_diff;
  1736		enum cp_time ct;
  1737	
  1738		sb_diff = (u64)ktime_ms_delta(sbi->cp_stats.times[CP_TIME_END],
  1739						sbi->cp_stats.times[CP_TIME_START]);
  1740		cur_diff = (u64)ktime_ms_delta(cpc->stats.times[CP_TIME_END],
  1741						cpc->stats.times[CP_TIME_START]);
  1742	
  1743		if (cur_diff > sb_diff) {
> 1744			update_cp_stats(sbi, cpc);
  1745			if (cur_diff < CP_LONG_LATENCY_THRESHOLD)
  1746				return;
  1747	
  1748			f2fs_warn(sbi, "checkpoint was blocked for %llu ms", cur_diff);
  1749			for (ct = CP_TIME_START; ct < CP_TIME_MAX - 1; ct++)
  1750				f2fs_warn(sbi, "Step#%d: %llu ms", ct,
  1751					(u64)ktime_ms_delta(cpc->stats.times[ct + 1],
  1752							cpc->stats.times[ct]));
  1753		}
  1754	}
  1755	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16 16:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16  9:50 [PATCH v2] f2fs: add checkpoint step timing statistics to debugfs huang zheng
2026-11-16 16:24 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®