From nobody Mon Dec 1 22:05:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14161302175 for ; Fri, 28 Nov 2025 09:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764321917; cv=none; b=clgtjKfK0qJY3WoCiDcyM3059v/2kgrMro7tLJ8aXF52BNYt3jiwQeiqSD+VjgiSgqJUtBPWSvEHvouyEM9OHKOVMskItzH5nkObo+6GAxy48qW0fadTumUFwHmvwJPw+Er66P/rICOQ2Q4u0199g9Xsxf4qpy1JbaoYH5taLng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764321917; c=relaxed/simple; bh=QwDyFbcLSb1sukYfwD0cJ2NJv7pmxdU8vjSc2z+8laA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dG+RlQQcGGLylfi5AvNfxmwouEScq8BrDJSmwwl02ihQnC7dnQWfv4Pw3H8Y1ZuZraeDtN6EGpA4YMu7JqCyWtah1sBxKUukLxw/Tr0yUNAdUhc97NIo06C+NxVAsU9pDvzxH8s9jM3dD2h5GsIlFa72Q059HjenqPOX9tf0W4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XxPtV50b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XxPtV50b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EC03C4CEF1; Fri, 28 Nov 2025 09:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764321916; bh=QwDyFbcLSb1sukYfwD0cJ2NJv7pmxdU8vjSc2z+8laA=; h=From:To:Cc:Subject:Date:From; b=XxPtV50b7r90A/uRvONglOCs+b8Ubzf40+hdwpuy6FwGytI8Mbn2s+YJMMtu3tXTY MFEpUYTM4FLA5uvEVoy7X9j9TJXLn89qLt9i/9ct/k7CAacw1OL6Cnn6BqKotBtAAl ycc+03uEMeSBI5BRtkucQkNJ8SVle3GWExDBwOkgx44JtxGG/c39qVh+qsirfAsOk8 TWfsRcEi6gnoj5XMBkZ1ebLfiBrsOG2N0FgRBFWCm7dg1ynHDX+y1K8+qC6z/7ISjl sHlhWDtnUG9zK5oO8+B4WltL4TN9SiJBI8w7m7+M7Of+fVIovS5bJPOYklgSLnRLAV NspkfV8qppDIQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , stable@kernel.org Subject: [PATCH] f2fs: fix to not account invalid blocks in get_left_section_blocks() Date: Fri, 28 Nov 2025 17:25:07 +0800 Message-ID: <20251128092507.1607278-1-chao@kernel.org> X-Mailer: git-send-email 2.52.0.487.g5c8c507ade-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" w/ LFS mode, in get_left_section_blocks(), we should not account the blocks which were used before and now are invalided, otherwise those blocks will be counted as freed one in has_curseg_enough_space(), result in missing to trigger GC in time. Cc: stable@kernel.org Fixes: 249ad438e1d9 ("f2fs: add a method for calculating the remaining bloc= ks in the current segment in LFS mode.") Fixes: bf34c93d2645 ("f2fs: check curseg space before foreground GC") Signed-off-by: Chao Yu --- fs/f2fs/segment.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 51eecb861a78..b08f18274440 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -612,10 +612,12 @@ static inline int reserved_sections(struct f2fs_sb_in= fo *sbi) static inline unsigned int get_left_section_blocks(struct f2fs_sb_info *sb= i, enum log_type type, unsigned int segno) { - if (f2fs_lfs_mode(sbi) && __is_large_section(sbi)) - return CAP_BLKS_PER_SEC(sbi) - SEGS_TO_BLKS(sbi, - (segno - GET_START_SEG_FROM_SEC(sbi, segno))) - + if (f2fs_lfs_mode(sbi)) { + unsigned int used_blocks =3D __is_large_section(sbi) ? SEGS_TO_BLKS(sbi, + (segno - GET_START_SEG_FROM_SEC(sbi, segno))) : 0; + return CAP_BLKS_PER_SEC(sbi) - used_blocks - CURSEG_I(sbi, type)->next_blkoff; + } return CAP_BLKS_PER_SEC(sbi) - get_ckpt_valid_blocks(sbi, segno, true); } =20 --=20 2.49.0