f2fs: avoid needless checkpoint in f2fs_trim_fs
authorJaegeuk Kim <jaegeuk@kernel.org>
Fri, 30 Dec 2016 00:58:54 +0000 (16:58 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 22 Feb 2017 21:16:36 +0000 (13:16 -0800)
The f2fs_trim_fs() doesn't need to do checkpoint if there are newly allocated
data blocks only which didn't change the critical checkpoint data such as nat
and sit entries.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c

index 1a9ba69a22bae44035ea7e254568f341e3e79186..917b5c5053aecaaf0a965834759f72ba94132213 100644 (file)
@@ -1248,14 +1248,15 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        f2fs_flush_merged_bios(sbi);
 
        /* this is the case of multiple fstrims without any changes */
-       if (cpc->reason == CP_DISCARD && !is_sbi_flag_set(sbi, SBI_IS_DIRTY)) {
-               f2fs_bug_on(sbi, NM_I(sbi)->dirty_nat_cnt);
-               f2fs_bug_on(sbi, SIT_I(sbi)->dirty_sentries);
-               f2fs_bug_on(sbi, prefree_segments(sbi));
-               flush_sit_entries(sbi, cpc);
-               clear_prefree_segments(sbi, cpc);
-               unblock_operations(sbi);
-               goto out;
+       if (cpc->reason == CP_DISCARD) {
+               if (NM_I(sbi)->dirty_nat_cnt == 0 &&
+                               SIT_I(sbi)->dirty_sentries == 0 &&
+                               prefree_segments(sbi) == 0) {
+                       flush_sit_entries(sbi, cpc);
+                       clear_prefree_segments(sbi, cpc);
+                       unblock_operations(sbi);
+                       goto out;
+               }
        }
 
        /*