From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3B3B3BA222 for ; Thu, 14 May 2026 20:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778792119; cv=none; b=RPoerUGuJUuSYP/nQMQTKZ0FEjd4D7Ge57n58hpuZkMzrfHiWPBXyFiSMe1GX2c80C5G139l419gEFj1Jy54NHUSZjtm5MdOdnkuX0KNTpBppsNKAnibS1pBHYR0BLp9Lh7DiWPxnUeI8zK4JYrT61/qMfF5PbtooALxWQciHTU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778792119; c=relaxed/simple; bh=PyOEGvl0noChPnGdWMFUSSHcnsXeTBZhMHA/FnJbsTk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=prp6Ik0nOMVdbcY4GH9OnT4hLCUq7Pwr6kT6CwFcAfudMzcDu5vUt4qUp6AWHsLPdUrmv5EJC4C01m+BTJA38Glho8FTYBNpI5tv8q6wqkSDHbJjH/WPFdAJ+1p8mxsQar+3CY80FklBOGzYXFQhfwyKRyhc0yfFSdvNmMtPH1M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dXMx7BHz; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dXMx7BHz" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-2f3c623322bso14284224eec.0 for ; Thu, 14 May 2026 13:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778792118; x=1779396918; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=M+HrC3wUfomSuttyTiJ1cH0jqcmCnpaZOOcbBOvYx+Y=; b=dXMx7BHzFzepNDWiC8Kvl4hiOvNx6haJu7mTyiIDgkj/63NdSjtVnVy4f6te1hey7d +gGGJEpoUCxRMfgD8UgSlHKDgIH47qTDzFoN780hAqoGEvL5BGN6NGzMktVwjthrC1Ml BY3XF5auuAqrdSjHmi+T/aaLW9La+/Lrs99KWoSZlnx1n2C98NrUtBPfB+OO+tzHP4tr pxygj7U+Ya0EEUoSWOMaSR27Xh2YWN53eKzVmftDwQQfutiNOqXXz+lydI8j7wHIZGWa mNnY7bZ8H7Qlx+wNE8dVX+3UcTPjmCYQlEP72q/y7YQSkvIV9FWF10expq9Zlyt9UVoC JC2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778792118; x=1779396918; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=M+HrC3wUfomSuttyTiJ1cH0jqcmCnpaZOOcbBOvYx+Y=; b=IeGK/NxyxPH4xt8UbWm/EUy/moqR4GxJn/Uozg61jTbi+UNnaNBvGEhzTCJajSO8hH 92kNNhzdO0kN4jA/04xrlL7tUO7QQfP68nQA8RIwzykTeuHB9gUcCIh/5Z9FZm2Cc1ck jqiuUffbdo3XPabmA0egCtzrfkm0Y5Di3nRlDDpEoH/+pIjD3gMvR2ANBAvlZe6SuQXu fbwhiIi0fqVT5tv4cfrbLzvvMBMPKG8rbNUuhLZUKfLT9b6/SgZhCGB3sfETLMNrsADv y+j/OcsjWhTj6lnvqW5b1oDMcI2Gsy+ruzSimiFDSIvw/k+MJfc+7oSOfDB/F4bfhSLb f7zA== X-Gm-Message-State: AOJu0YwNcagX38vUkOqO+r+L7TyOgiTp3yb4W8Rmqq9rT7eztoSmN8/x ZjXzf3X8n5c07/+P8b6MIKTe7FFHdyRNE9y1hJ2P/QyDOyRGSWub9ZBhTaEpeA== X-Gm-Gg: Acq92OFapg/fAOFcgRfT2KDFTrC9CK1dtwMkgqlLjgLyTopkqGsCvCgE+2d48WsPWci 4y6MAUU+ijt+HzCZiejUPpb3Z5F/cK0yu630LS8x0uQLmozKhgulaB+R+5tr/BM09UZ+x76TJB3 75ofoxDz2Vkb7hgXHIRi5PiEOoJvLVJRk1uDCIzbCm2OQdt6vrn6q66EkuMfUD1h6QYtcv8E/1s SYuLeoRFTp0LqrxtCTQswM4TJ1aoCdRPB5YYkpgff/6Vpr7lgUh2HWyUghgT8us7LCbl27xpus3 SFF0z6rqNFUPLrm4hm9cqqyvtW3g2b3dXMHnfPzdF8Wj9nqVWpiZ/Anp3MBnq7G6O2hs+TcwR/I VkJX3FxXENs0R8V2nip8pBl2yRimIdcyjvyifYVTnP4fYtqBvGShBJm9rFEY/H7H0V2iJ9ssOKf MZEpJb8OlvIyLlLZapMgKzdn4T+kN+Ks9mGp8EE3jXCZ7qO4s708DxXcRRwFo97tsIIRyTeCxeT b6sdWAXqTrfLLdeof5BgSJGGLrcL8zZ7MdauI/Zq6zVvocKeQ== X-Received: by 2002:a05:7300:e6c6:b0:2dd:c066:bf7 with SMTP id 5a478bee46e88-303982b11bbmr674972eec.11.1778792117654; Thu, 14 May 2026 13:55:17 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2a00:79e0:2e7c:8:d674:986:3782:2b17]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2e3c0sm5355763eec.3.2026.05.14.13.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2026 13:55:17 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH] f2fs: optimize representative type determination in GC Date: Thu, 14 May 2026 13:55:13 -0700 Message-ID: <20260514205513.1464863-1-daeho43@gmail.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Daeho Jeong 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 --- 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 755df9b6bbaa..3464ca7d5fb1 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1745,9 +1745,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)) { @@ -1846,6 +1845,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.54.0.563.g4f69b47b94-goog