Skip to content

Commit c1660d8

Browse files
bbkzzJaegeuk Kim
authored andcommitted
f2fs: add has_enough_free_secs()
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 <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent bd90c5c commit c1660d8

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

fs/f2fs/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18721872
if (gc_type == FG_GC) {
18731873
sbi->cur_victim_sec = NULL_SEGNO;
18741874

1875-
if (!has_not_enough_free_secs(sbi, sec_freed, 0)) {
1875+
if (has_enough_free_secs(sbi, sec_freed, 0)) {
18761876
if (!gc_control->no_bg_gc &&
18771877
sec_freed < gc_control->nr_free_secs)
18781878
goto go_gc_more;
@@ -1886,7 +1886,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18861886
ret = f2fs_write_checkpoint(sbi, &cpc);
18871887
goto stop;
18881888
}
1889-
} else if (!has_not_enough_free_secs(sbi, 0, 0)) {
1889+
} else if (has_enough_free_secs(sbi, 0, 0)) {
18901890
goto stop;
18911891
}
18921892

fs/f2fs/segment.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -412,27 +412,28 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
412412
* We should do GC or end up with checkpoint, if there are so many dirty
413413
* dir/node pages without enough free segments.
414414
*/
415-
if (has_not_enough_free_secs(sbi, 0, 0)) {
416-
if (test_opt(sbi, GC_MERGE) && sbi->gc_thread &&
417-
sbi->gc_thread->f2fs_gc_task) {
418-
DEFINE_WAIT(wait);
419-
420-
prepare_to_wait(&sbi->gc_thread->fggc_wq, &wait,
421-
TASK_UNINTERRUPTIBLE);
422-
wake_up(&sbi->gc_thread->gc_wait_queue_head);
423-
io_schedule();
424-
finish_wait(&sbi->gc_thread->fggc_wq, &wait);
425-
} else {
426-
struct f2fs_gc_control gc_control = {
427-
.victim_segno = NULL_SEGNO,
428-
.init_gc_type = BG_GC,
429-
.no_bg_gc = true,
430-
.should_migrate_blocks = false,
431-
.err_gc_skipped = false,
432-
.nr_free_secs = 1 };
433-
f2fs_down_write(&sbi->gc_lock);
434-
f2fs_gc(sbi, &gc_control);
435-
}
415+
if (has_enough_free_secs(sbi, 0, 0))
416+
return;
417+
418+
if (test_opt(sbi, GC_MERGE) && sbi->gc_thread &&
419+
sbi->gc_thread->f2fs_gc_task) {
420+
DEFINE_WAIT(wait);
421+
422+
prepare_to_wait(&sbi->gc_thread->fggc_wq, &wait,
423+
TASK_UNINTERRUPTIBLE);
424+
wake_up(&sbi->gc_thread->gc_wait_queue_head);
425+
io_schedule();
426+
finish_wait(&sbi->gc_thread->fggc_wq, &wait);
427+
} else {
428+
struct f2fs_gc_control gc_control = {
429+
.victim_segno = NULL_SEGNO,
430+
.init_gc_type = BG_GC,
431+
.no_bg_gc = true,
432+
.should_migrate_blocks = false,
433+
.err_gc_skipped = false,
434+
.nr_free_secs = 1 };
435+
f2fs_down_write(&sbi->gc_lock);
436+
f2fs_gc(sbi, &gc_control);
436437
}
437438
}
438439

fs/f2fs/segment.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,17 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi,
643643
return !curseg_space;
644644
}
645645

646+
static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi,
647+
int freed, int needed)
648+
{
649+
return !has_not_enough_free_secs(sbi, freed, needed);
650+
}
651+
646652
static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi)
647653
{
648654
if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
649655
return true;
650-
if (likely(!has_not_enough_free_secs(sbi, 0, 0)))
656+
if (likely(has_enough_free_secs(sbi, 0, 0)))
651657
return true;
652658
return false;
653659
}

0 commit comments

Comments
 (0)