f2fs: modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable
PATCH v3 1/1 f2fs: modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable
When the free segment is used up during CP disable, many write or ioctl operations will get ENOSPC error codes, even if there are still many blocks available. We can reproduce it in the following steps:
dd if=/dev/zero of=f2fs.img bs=1M count=65
mkfs.f2fs -f f2fs.img
mount f2fs.img f2fs_dir -o checkpoint=disable:10%
cd f2fs_dir
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; dd \
if=/dev/random of=$file_name bs=1M count=2); i=$((i+1)); done sync
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; truncate \
-s 1K $file_name); i=$((i+1)); done
sync
dd if=/dev/zero of=./file bs=1M count=20
In f2fs_need_SSR() function, it is allowed to use SSR to allocate blocks when CP is disabled, so in f2fs_is_checkpoint_ready function, can we judge the number of invalid blocks when free segment is not enough, and return ENOSPC only if the number of invalid blocks is also not enough?
--- fs/f2fs/segment.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/f2fs/segment.h +17 -0
@@ -637,12 +637,29 @@ static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi,return !has_not_enough_free_secs (sbi, freed, needed); } +static inline bool has_enough_free_blks (struct f2fs_sb_info *sbi) +{ +unsigned int total_free_blocks =0 ; +unsigned int avail_user_block_count; + +spin_lock (&sbi->stat_lock); + + avail_user_block_count =get_available_block_count (sbi,NULL , true); + total_free_blocks = avail_user_block_count - (unsigned int )valid_user_blocks (sbi); + +spin_unlock (&sbi->stat_lock); + +return total_free_blocks >0 ; +} +static inline bool f2fs_is_checkpoint_ready (struct f2fs_sb_info *sbi) {if (likely (!is_sbi_flag_set (sbi,SBI_CP_DISABLED )))return true;if (likely (has_enough_free_secs (sbi,0 ,0 )))return true; +if (likely (has_enough_free_blks (sbi))) +return true;return false; }
Signature · 1 line
2.39.0
Quoted 17 lines · Qi Han
When the free segment is used up during CP disable, many write or ioctl operations will get ENOSPC error codes, even if there are still many blocks available. We can reproduce it in the following steps:
dd if=/dev/zero of=f2fs.img bs=1M count=65
mkfs.f2fs -f f2fs.img
mount f2fs.imgf2fs_dir-o checkpoint=disable:10%
cdf2fs_dir
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; dd \
if=/dev/random of=$file_name bs=1M count=2); i=$((i+1)); done sync
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; truncate \
-s 1K $file_name); i=$((i+1)); done
sync
dd if=/dev/zero of=./file bs=1M count=20
Quoted 7 lines
In
f2fs_need_SSR()function, it is allowed to use SSR to allocate blocks when CP is disabled, so inf2fs_is_checkpoint_readyfunction, can we judge the number of invalid blocks when free segment is not enough, and return ENOSPC only if the number of invalid blocks is also not enough?Signed-off-by Qi Han <[email protected]>
Thanks,
Quoted 47 lines · Qi Han
When the free segment is used up during CP disable, many write or ioctl operations will get ENOSPC error codes, even if there are still many blocks available. We can reproduce it in the following steps:
dd if=/dev/zero of=f2fs.img bs=1M count=65
mkfs.f2fs -f f2fs.img
mount f2fs.imgf2fs_dir-o checkpoint=disable:10%
cdf2fs_dir
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; dd \
if=/dev/random of=$file_name bs=1M count=2); i=$((i+1)); done sync
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; truncate \
-s 1K $file_name); i=$((i+1)); done
sync
dd if=/dev/zero of=./file bs=1M count=20In
f2fs_need_SSR()function, it is allowed to use SSR to allocate blocks when CP is disabled, so inf2fs_is_checkpoint_readyfunction, can we judge the number of invalid blocks when free segment is not enough, and return ENOSPC only if the number of invalid blocks is also not enough?Signed-off-by Qi Han <[email protected]>--- fs/f2fs/segment.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)fs/f2fs/segment.h +11
-0@@ -637,12 +637,29 @@ static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi,return !has_not_enough_free_secs (sbi, freed, needed); } +static inline bool has_enough_free_blks (struct f2fs_sb_info *sbi) +{ +unsigned int total_free_blocks =0 ; +unsigned int avail_user_block_count; + +spin_lock (&sbi->stat_lock); + + avail_user_block_count =get_available_block_count (sbi,NULL , true); + total_free_blocks = avail_user_block_count - (unsigned int )valid_user_blocks (sbi); + +spin_unlock (&sbi->stat_lock);
fs/f2fs/segment.h static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi, · line 660
Quoted 10 lines
fs/f2fs/segment.h +4
-0+ +return total_free_blocks >0 ; +} +static inline bool f2fs_is_checkpoint_ready (struct f2fs_sb_info *sbi) {if (likely (!is_sbi_flag_set (sbi,SBI_CP_DISABLED )))return true;if (likely (has_enough_free_secs (sbi,0 ,0 )))return true;
Hi, Chao,
After Zhiguo's reminder, I just saw your previous patch:
f2fs: fix to account dirty data in __get_secs_required(), the current modification may still return true if the segment is found to be insufficient when LFS and CP is closed, should I add the LFS mode restriction here?
Thanks.
Quoted 5 lines
fs/f2fs/segment.h +2
-0+if (likely (has_enough_free_blks (sbi))) +return true;return false; }
Chao Yu
maintainerQuoted 64 lines · 韩棋
Quoted 50 lines · Qi Han
When the free segment is used up during CP disable, many write or ioctl operations will get ENOSPC error codes, even if there are still many blocks available. We can reproduce it in the following steps:
dd if=/dev/zero of=f2fs.img bs=1M count=65
mkfs.f2fs -f f2fs.img
mount f2fs.imgf2fs_dir-o checkpoint=disable:10%
cdf2fs_dir
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; dd \
if=/dev/random of=$file_name bs=1M count=2); i=$((i+1)); done sync
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; truncate \
-s 1K $file_name); i=$((i+1)); done
sync
dd if=/dev/zero of=./file bs=1M count=20In
f2fs_need_SSR()function, it is allowed to use SSR to allocate blocks when CP is disabled, so inf2fs_is_checkpoint_readyfunction, can we judge the number of invalid blocks when free segment is not enough, and return ENOSPC only if the number of invalid blocks is also not enough?Signed-off-by Qi Han <[email protected]>--- fs/f2fs/segment.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)fs/f2fs/segment.h +11
-0@@ -637,12 +637,29 @@ static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi,return !has_not_enough_free_secs (sbi, freed, needed); } +static inline bool has_enough_free_blks (struct f2fs_sb_info *sbi) +{ +unsigned int total_free_blocks =0 ; +unsigned int avail_user_block_count; + +spin_lock (&sbi->stat_lock); + + avail_user_block_count =get_available_block_count (sbi,NULL , true); + total_free_blocks = avail_user_block_count - (unsigned int )valid_user_blocks (sbi); + +spin_unlock (&sbi->stat_lock);fs/f2fs/segment.h static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi, · line 663
Quoted 10 lines
fs/f2fs/segment.h +4
-0+ +return total_free_blocks >0 ; +} +static inline bool f2fs_is_checkpoint_ready (struct f2fs_sb_info *sbi) {if (likely (!is_sbi_flag_set (sbi,SBI_CP_DISABLED )))return true;if (likely (has_enough_free_secs (sbi,0 ,0 )))return true;Hi, Chao,
Quoted 5 lines
After Zhiguo's reminder, I just saw your previous patch:
f2fs: fix to account dirty data in__get_secs_required(), the current modification may still return true if the segment is found to be insufficient when LFS and CP is closed, should I add the LFS mode restriction here?
Hi Qi,
I guess so, I think we need to add a lfs_mode check condition in has_enough_free_blks(), otherwise this patch will trigger system panic w/ below testcase:
https://lore.kernel.org/fstests/[email protected]/
Thanks,
Quoted 9 lines
Thanks.
Quoted 5 lines
fs/f2fs/segment.h +2
-0+if (likely (has_enough_free_blks (sbi))) +return true;return false; }