Commit 94afce7d authored by Byungki Lee's avatar Byungki Lee Committed by Zheng Zengkai
Browse files

f2fs: write checkpoint during FG_GC

stable inclusion
from stable-v5.10.137
commit ec769406d06d5006c40554c4640f6e584ab6ae26
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I60PLB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=ec769406d06d5006c40554c4640f6e584ab6ae26



--------------------------------

[ Upstream commit a9163b94 ]

If there's not enough free sections each of which consistis of large segments,
we can hit no free section for upcoming section allocation. Let's reclaim some
prefree segments by writing checkpoints.

Signed-off-by: default avatarByungki Lee <dominicus79@gmail.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: default avatarWei Li <liwei391@huawei.com>
parent 467192df
Loading
Loading
Loading
Loading
+23 −15
Original line number Diff line number Diff line
@@ -1742,13 +1742,22 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
	if (sync)
		goto stop;

	if (has_not_enough_free_secs(sbi, sec_freed, 0)) {
		if (skipped_round <= MAX_SKIP_GC_COUNT ||
					skipped_round * 2 < round) {
	if (!has_not_enough_free_secs(sbi, sec_freed, 0))
		goto stop;

	if (skipped_round <= MAX_SKIP_GC_COUNT || skipped_round * 2 < round) {

		/* Write checkpoint to reclaim prefree segments */
		if (free_sections(sbi) < NR_CURSEG_PERSIST_TYPE &&
				prefree_segments(sbi) &&
				!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
			ret = f2fs_write_checkpoint(sbi, &cpc);
			if (ret)
				goto stop;
		}
		segno = NULL_SEGNO;
		goto gc_more;
	}

	if (first_skipped < last_skipped &&
			(last_skipped - first_skipped) >
					sbi->skipped_gc_rwsem) {
@@ -1758,7 +1767,6 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
	}
	if (gc_type == FG_GC && !is_sbi_flag_set(sbi, SBI_CP_DISABLED))
		ret = f2fs_write_checkpoint(sbi, &cpc);
	}
stop:
	SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0;
	SIT_I(sbi)->last_victim[FLUSH_DEVICE] = init_segno;