Skip to content

Commit 84b5bb8

Browse files
Qi HanJaegeuk Kim
authored andcommitted
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. Signed-off-by: Qi Han <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 4356306 commit 84b5bb8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

fs/f2fs/segment.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,30 @@ static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi,
654654
return !has_not_enough_free_secs(sbi, freed, needed);
655655
}
656656

657+
static inline bool has_enough_free_blks(struct f2fs_sb_info *sbi)
658+
{
659+
unsigned int total_free_blocks = 0;
660+
unsigned int avail_user_block_count;
661+
662+
spin_lock(&sbi->stat_lock);
663+
664+
avail_user_block_count = get_available_block_count(sbi, NULL, true);
665+
total_free_blocks = avail_user_block_count - (unsigned int)valid_user_blocks(sbi);
666+
667+
spin_unlock(&sbi->stat_lock);
668+
669+
return total_free_blocks > 0;
670+
}
671+
657672
static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi)
658673
{
659674
if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
660675
return true;
661676
if (likely(has_enough_free_secs(sbi, 0, 0)))
662677
return true;
678+
if (!f2fs_lfs_mode(sbi) &&
679+
likely(has_enough_free_blks(sbi)))
680+
return true;
663681
return false;
664682
}
665683

0 commit comments

Comments
 (0)