]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: add has_enough_free_secs()
authorYangtao Li <frank.li@vivo.com>
Thu, 13 Apr 2023 16:59:51 +0000 (00:59 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 18 Apr 2023 16:05:54 +0000 (09:05 -0700)
Replace !has_not_enough_free_secs w/ has_enough_free_secs.
BTW avoid nested 'if' statements in f2fs_balance_fs().

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/gc.c
fs/f2fs/segment.c
fs/f2fs/segment.h

index ba5775dcade658f64c99ed4ef193a42e72320a77..a6a0dc471b74785e1e9acb39969d4b418845a461 100644 (file)
@@ -1872,7 +1872,7 @@ retry:
        if (gc_type == FG_GC) {
                sbi->cur_victim_sec = NULL_SEGNO;
 
-               if (!has_not_enough_free_secs(sbi, sec_freed, 0)) {
+               if (has_enough_free_secs(sbi, sec_freed, 0)) {
                        if (!gc_control->no_bg_gc &&
                            sec_freed < gc_control->nr_free_secs)
                                goto go_gc_more;
@@ -1886,7 +1886,7 @@ retry:
                        ret = f2fs_write_checkpoint(sbi, &cpc);
                        goto stop;
                }
-       } else if (!has_not_enough_free_secs(sbi, 0, 0)) {
+       } else if (has_enough_free_secs(sbi, 0, 0)) {
                goto stop;
        }
 
index 82430f80c5da735d0018fce9627f4dd385917a65..c35476b3c0753d6290b4614b7a833687cb5abb17 100644 (file)
@@ -412,27 +412,28 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
         * We should do GC or end up with checkpoint, if there are so many dirty
         * dir/node pages without enough free segments.
         */
-       if (has_not_enough_free_secs(sbi, 0, 0)) {
-               if (test_opt(sbi, GC_MERGE) && sbi->gc_thread &&
-                                       sbi->gc_thread->f2fs_gc_task) {
-                       DEFINE_WAIT(wait);
-
-                       prepare_to_wait(&sbi->gc_thread->fggc_wq, &wait,
-                                               TASK_UNINTERRUPTIBLE);
-                       wake_up(&sbi->gc_thread->gc_wait_queue_head);
-                       io_schedule();
-                       finish_wait(&sbi->gc_thread->fggc_wq, &wait);
-               } else {
-                       struct f2fs_gc_control gc_control = {
-                               .victim_segno = NULL_SEGNO,
-                               .init_gc_type = BG_GC,
-                               .no_bg_gc = true,
-                               .should_migrate_blocks = false,
-                               .err_gc_skipped = false,
-                               .nr_free_secs = 1 };
-                       f2fs_down_write(&sbi->gc_lock);
-                       f2fs_gc(sbi, &gc_control);
-               }
+       if (has_enough_free_secs(sbi, 0, 0))
+               return;
+
+       if (test_opt(sbi, GC_MERGE) && sbi->gc_thread &&
+                               sbi->gc_thread->f2fs_gc_task) {
+               DEFINE_WAIT(wait);
+
+               prepare_to_wait(&sbi->gc_thread->fggc_wq, &wait,
+                                       TASK_UNINTERRUPTIBLE);
+               wake_up(&sbi->gc_thread->gc_wait_queue_head);
+               io_schedule();
+               finish_wait(&sbi->gc_thread->fggc_wq, &wait);
+       } else {
+               struct f2fs_gc_control gc_control = {
+                       .victim_segno = NULL_SEGNO,
+                       .init_gc_type = BG_GC,
+                       .no_bg_gc = true,
+                       .should_migrate_blocks = false,
+                       .err_gc_skipped = false,
+                       .nr_free_secs = 1 };
+               f2fs_down_write(&sbi->gc_lock);
+               f2fs_gc(sbi, &gc_control);
        }
 }
 
index ac2e35170f2d0175cc7803c1978d804b8e0feb38..2ca8fb5d0dc4db3f69d09ea6704b54cd5bd51da1 100644 (file)
@@ -643,11 +643,17 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi,
        return !curseg_space;
 }
 
+static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi,
+                                       int freed, int needed)
+{
+       return !has_not_enough_free_secs(sbi, freed, needed);
+}
+
 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_not_enough_free_secs(sbi, 0, 0)))
+       if (likely(has_enough_free_secs(sbi, 0, 0)))
                return true;
        return false;
 }