From: Sasha Levin via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>,
Daeho Jeong <daehojeong@google.com>,
linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH AUTOSEL 6.18] f2fs: optimize representative type determination in GC
Date: Mon, 31 Aug 2026 09:25:57 -0400 [thread overview]
Message-ID: <20260831133314.4125787-329-sashal@kernel.org> (raw)
In-Reply-To: <20260831133314.4125787-1-sashal@kernel.org>
From: Daeho Jeong <daehojeong@google.com>
[ Upstream commit 5dfb768326b95c6dd6554f34dec71b44a01a0bc8 ]
In large section mode, do_garbage_collect() previously determined the
section's representative type by looking only at the first segment of
the section. However, if data was fsynced into an area previously used
as a node section, and this area is recovered during roll-forward
recovery after sudden power off (SPO), GC would incorrectly assume the
section's type based on an empty or obsolete first segment. This caused
the recovered data segment to be misunderstood as being stuck inside a
node section, triggering false inconsistency panics (Inconsistent
segment type in SSA and SIT) and subsequent mount failures.
This patch optimizes do_garbage_collect() to determine the section's
representative type by identifying the first segment that actually
contains valid blocks (valid_blocks > 0) during the main GC loop. This
eliminates false alarms from empty/obsolete leading segments while
maintaining strict section-level type consistency checks for genuine
corruption.
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
The background git searches finished and line up with the earlier
analysis:
- **`origin/master`** has the fix as `5dfb768326b95` ("f2fs: optimize
representative type determination in GC"), merged via the f2fs-
for-7.1-rc1 tag.
- **Current HEAD (v6.18.44)** does not contain it — subject grep on HEAD
returned nothing, and recent `fs/f2fs/gc.c` history shows no sign of
this patch.
That supports the **YES** backport recommendation for this 6.18.y tree:
the bug is still present here, the fix is on mainline, and it applies
cleanly.
fs/f2fs/gc.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 3d41c6348b3c1..e56c7ccecaff5 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1769,9 +1769,8 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
unsigned int end_segno = start_segno + SEGS_PER_SEC(sbi);
unsigned int sec_end_segno;
int seg_freed = 0, migrated = 0;
- unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ?
- SUM_TYPE_DATA : SUM_TYPE_NODE;
- unsigned char data_type = (type == SUM_TYPE_DATA) ? DATA : NODE;
+ unsigned char type;
+ unsigned char data_type;
int submitted = 0, sum_blk_cnt;
if (__is_large_section(sbi)) {
@@ -1870,6 +1869,12 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
migrated >= sbi->migration_granularity)
continue;
+ if (migrated == 0) {
+ type = IS_DATASEG(get_seg_entry(sbi, cur_segno)->type) ?
+ SUM_TYPE_DATA : SUM_TYPE_NODE;
+ data_type = (type == SUM_TYPE_DATA) ? DATA : NODE;
+ }
+
sum = SUM_BLK_PAGE_ADDR(sbi, sum_folio, cur_segno);
if (type != GET_SUM_TYPE(sum_footer(sbi, sum))) {
f2fs_err(sbi, "Inconsistent segment (%u) type "
--
2.53.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next parent reply other threads:[~2026-08-31 13:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260831133314.4125787-1-sashal@kernel.org>
2026-08-31 13:25 ` Sasha Levin via Linux-f2fs-devel [this message]
2026-08-31 13:30 ` [f2fs-dev] [PATCH AUTOSEL 6.18-5.10] f2fs: validate inline dentry name lengths before conversion Sasha Levin via Linux-f2fs-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260831133314.4125787-329-sashal@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=daehojeong@google.com \
--cc=jaegeuk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox