f2fs: add timeout in f2fs_enable_checkpoint()
Chao Yu
maintainerPATCH 1/2 f2fs: add timeout in f2fs_enable_checkpoint()
During f2fs_enable_checkpoint() in remount(), if we flush a large amount of dirty pages into slow device, it may take long time which will block write IO, let's add a timeout machanism during dirty pages flush to avoid long time block in f2fs_enable_checkpoint().
--- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/super.c | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +2 -0
@@ -275,6 +275,7 @@ enum {#define DEF_CP_INTERVAL 60/* 60 secs */ #define DEF_IDLE_INTERVAL 5/* 5 secs */ #define DEF_DISABLE_INTERVAL 5/* 5 secs */ +#define DEF_ENABLE_INTERVAL 16/* 16 secs */ #define DEF_DISABLE_QUICK_INTERVAL 1/* 1 secs */ #define DEF_UMOUNT_DISCARD_TIMEOUT 5/* 5 secs */
@@ -1406,6 +1407,7 @@ enum {DISCARD_TIME ,GC_TIME ,DISABLE_TIME , +ENABLE_TIME ,UMOUNT_DISCARD_TIMEOUT , MAX_TIME, };
fs/f2fs/super.c +15 -6
@@ -2623,16 +2623,24 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)static void f2fs_enable_checkpoint (struct f2fs_sb_info *sbi) { -int retry =DEFAULT_RETRY_IO_COUNT ; +unsigned int nr_pages =get_pages (sbi,F2FS_DIRTY_DATA ) /16 ; + +f2fs_update_time (sbi,ENABLE_TIME );/* we should flush all the data to keep data consistency */ -do { -sync_inodes_sb (sbi->sb); +while (get_pages (sbi,F2FS_DIRTY_DATA )) { +writeback_inodes_sb_nr (sbi->sb, nr_pages,WB_REASON_SYNC );f2fs_io_schedule_timeout (DEFAULT_IO_TIMEOUT ); - }while (get_pages (sbi,F2FS_DIRTY_DATA ) && retry--); -if (unlikely (retry <0 )) -f2fs_warn (sbi,"checkpoint=enable has some unwritten data." ); +if (f2fs_time_over (sbi,ENABLE_TIME )) +break ; + } + +sync_inodes_sb (sbi->sb); + +if (unlikely (get_pages (sbi,F2FS_DIRTY_DATA ))) +f2fs_warn (sbi,"checkpoint=enable has some unwritten data: %lld" , +get_pages (sbi,F2FS_DIRTY_DATA ));f2fs_down_write (&sbi->gc_lock);f2fs_dirty_to_prefree (sbi);
@@ -4229,6 +4237,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->interval_time[DISCARD_TIME ] =DEF_IDLE_INTERVAL ; sbi->interval_time[GC_TIME ] =DEF_IDLE_INTERVAL ; sbi->interval_time[DISABLE_TIME ] =DEF_DISABLE_INTERVAL ; + sbi->interval_time[ENABLE_TIME ] =DEF_ENABLE_INTERVAL ; sbi->interval_time[UMOUNT_DISCARD_TIMEOUT ] =DEF_UMOUNT_DISCARD_TIMEOUT ;clear_sbi_flag (sbi,SBI_NEED_FSCK );
Signature · 1 line
2.49.0
Chao Yu
maintainerPATCH 2/2 f2fs: dump more information for f2fs_{enable,disable}_checkpoint()
Changes as below:
- print more logs for f2fs_{enable,disable}_checkpoint()
- account and dump time stats for f2fs_enable_checkpoint()
--- fs/f2fs/super.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/f2fs/super.c +16 -0
@@ -2618,15 +2618,24 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) restore_flag: sbi->gc_mode = gc_mode; sbi->sb->s_flags = s_flags;/* Restore SB_RDONLY status */ +f2fs_info (sbi,"f2fs_disable_checkpoint() finish, err:%d" , err);return err; }static void f2fs_enable_checkpoint (struct f2fs_sb_info *sbi) {unsigned int nr_pages =get_pages (sbi,F2FS_DIRTY_DATA ) /16 ; +long long start, writeback, end; + +f2fs_info (sbi,"f2fs_enable_checkpoint() starts, meta: %lld, node: %lld, data: %lld" , +get_pages (sbi,F2FS_DIRTY_META ), +get_pages (sbi,F2FS_DIRTY_NODES ), +get_pages (sbi,F2FS_DIRTY_DATA ));f2fs_update_time (sbi,ENABLE_TIME ); + start =ktime_get (); +/* we should flush all the data to keep data consistency */ while (get_pages (sbi,F2FS_DIRTY_DATA )) {writeback_inodes_sb_nr (sbi->sb, nr_pages,WB_REASON_SYNC );
@@ -2635,6 +2644,7 @@ static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)if (f2fs_time_over (sbi,ENABLE_TIME ))break ; } + writeback =ktime_get ();sync_inodes_sb (sbi->sb);
@@ -2653,6 +2663,12 @@ static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)/* Let's ensure there's no pending checkpoint anymore */ f2fs_flush_ckpt_thread (sbi); + + end =ktime_get (); + +f2fs_info (sbi,"f2fs_enable_checkpoint() finishes, writeback:%llu, sync:%llu" , +ktime_ms_delta (writeback, start), +ktime_ms_delta (end, writeback)); }static int __f2fs_remount (struct fs_context *fc,struct super_block *sb)
Signature · 1 line
2.49.0
This series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 8 lines · On Thu, 7 Aug 2025 12:00:25 +0800 you wrote:
During
f2fs_enable_checkpoint()inremount(), if we flush a large amount of dirty pages into slow device, it may take long time which will block write IO, let's add a timeout machanism during dirty pages flush to avoid long time block inf2fs_enable_checkpoint().Signed-off-by Chao Yu <[email protected]>[...]
Here is the summary with links:
- [f2fs-dev,1/2] f2fs: add timeout in f2fs_enable_checkpoint()
https://git.kernel.org/jaegeuk/f2fs/c/da63f609094d - [f2fs-dev,2/2] f2fs: dump more information for f2fs_{enable, disable}_checkpoint() https://git.kernel.org/jaegeuk/f2fs/c/347ff7d828c0
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html