From nobody Mon Sep 28 07:17:10 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 9334833DEFD for ; Tue, 25 Aug 2026 01:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787622789; cv=none; b=CUK+BiREhVdpoFw5B48xss6n62Bj8k+lGqEcrmLFQhSVMOnGUFDNrJNHQnjPaCbajYDsvUqsC11pFepNwSFX/PRHyffmwMIeqqME39ArP6xqB//L65MH1tLpVjYhi0xmUpxIJMUi+nLOs4hEEl23ps+rMNymch/5DCmkFZQz8RI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787622789; c=relaxed/simple; bh=jXDGijM1as3n6zotAUrKe6KiqlZyTL1tQUlOYk/3aq0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Hj6yE0xv4tI6iyZMKvcV5FqOYIFLO04sqfzcAVrr1paOnb6DfngVv949rjnI2vqP5+ITielPnlPW5Cl2PQ+F5NaX8V+GUZClMCJfMAVfLPdm/B3WiDy4eCEVkIxsCZJJEbpxbLWx+TZ+5CnDNJGO7Q/lSVDDUEG02dBvrPXAgzw= 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=nytisMmG; arc=none smtp.client-ip=209.85.216.47 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="nytisMmG" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-38e08baf860so4729874a91.2 for ; Mon, 24 Aug 2026 18:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787622788; x=1788227588; 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:content-type; bh=7ksJHKJAw5R8WRBPibc1ESESDe+ccf9OaKGAn1jN9/4=; b=nytisMmGbONt73itc1dkw8JS4BhlLGYPHf7HKQdkR89iyE9Lx0/JtdvhsM41btnsm4 ow5zuHR2R6Ux177rIN/phzo1I5b5tu344f62T2QcJ8itLgXJm/AYv8aagHcByN3Ri/qJ K9G8DOlYa0Off3IusVaU9OFVVH4/5jBVexSBHhCFpZgj/rhheSnY6XoGR5vqJ8S6vaCJ 30+EPb9GpIX7Gv7E7driYsgqHqLKnKJtVWefNywf0BGjXhnbQXLOWLBKQjqw8CpuypxY qSm9cSgrTiu0VIQJLJAjuIEvuZ/7WbYUFuglpOLzVxXZM7K6wT0qA2ivHFuH9coZtkd6 +BoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787622788; x=1788227588; 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:content-type; bh=7ksJHKJAw5R8WRBPibc1ESESDe+ccf9OaKGAn1jN9/4=; b=OuwRbQSXUlMGm36+hfcoCI3RBajJsXOO900GcyuTBjvLwQgKspSDXBzLpcZTUCqbfx Dn5ykTAxueoZ5GqTA/EhnMBdwfqnP+NJ5AcEbEtrEz2oFALp51bLo0zsoja+GBTKPwb8 SZ0ctLDVVVix6OhmHvA/8xavGGl000tDXaO6XRhofo+norIVUoQzQgk4KlVbGkE2C7JV +1pFyZHMmnIT8lCi2h9QuTNvAN9N5xFs5LWYeRAJIddRqQm3x8YIXawvVRUAFoUSRLVG 6tDtfiaGPw83pko+ZaH1BXpVAjib7DBKpu+kxVDi5zhMQYNcd0GuyfnddQkashJUYfWd a8iQ== X-Gm-Message-State: AFuF++kUm6csX7lbkImdqKZc2SQ6Ry8GkCIFl6qdkKaPVnUOeb4ihwkv 2xMHIITyEyzANaITWxzf6R58S83D47WoheA8bku39VbSUE8VgjptQKokGtKo80Y5 X-Gm-Gg: AR+sD11W8AtOgMQqf6MWASAvOj7O3Lgqg7wB+KDFkuIPKiYz6A2M3oBe36P02t2IQmH XGv74YE5FQMI1Lr7qsuwjH0LcUm30G0Q6TUQJekaKTBt8AUt/dQW9RBWsxwzMVQfscgtqV69whh MdLS5c5uokIXi4VxdENqcRX19IdqgFMIDnAuz0vYzdOXUgOAsJjJXdzkqATEfQ+28jfSSZW6wAJ 1CCPB483gVv9rkJl4KtXlV/o8ftIZxhcdm4K2TmOOWhU+WWbO+mvhWGU4oPhC8XZuwxX43/MuWy D7wxlm09rQ0156IuluWeCnhLxF1+vJtDBvxILDUp85TSE4kZ5yu1wyUxF35P+Q1NFg9RHqO0moU Gzt4Bh4HM6wMTD0Y8To3nI6K9qnUsF3vG/ZbbZo+vBg2zwcguCCc6Fryz0p4vuJjn/fXM31RiVm Gq20EgWGT6qNrZbTsVlTn2/PvIcgyfZiIDqL1u1zYIJ7LxFLRK95sO5UjIjqLeAdzMw22cR6duY 6Vx3QCHDvNVNR+qk64W6NRxHlHRswYHFl5rBsoa8XjImkdCGCdng+twPhp5PdOb/ocwotzn5LZM KUWMOKBNoMPo X-Received: by 2002:a17:90b:3911:b0:38e:2860:253f with SMTP id 98e67ed59e1d1-395df2926d9mr39684897a91.12.1787622787801; Mon, 24 Aug 2026 18:53:07 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2a00:79e0:2e7c:8:8d79:bdf4:eb94:2cab]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327f9236166sm30514662eec.28.2026.08.24.18.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 18:53:06 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong , stable@vger.kernel.org, Sunmin Jeong Subject: [PATCH v2] f2fs: accurately adjust free_sections during free_segment_range Date: Mon, 24 Aug 2026 18:53:03 -0700 Message-ID: <20260825015303.2082221-1-daeho43@gmail.com> X-Mailer: git-send-email 2.55.0.860.g4b6b3295ed-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" From: Daeho Jeong In free_segment_range(), MAIN_SECS(sbi) is temporarily reduced by `secs` to restrict block allocation to the safe remaining main area while valid blocks in the truncated range are evacuated by GC. However, FREE_I(sbi)->free_sections tracks the total number of free sections across the whole filesystem. If any sections within the truncated range were already free upon entering free_segment_range(), failing to deduct them from free_sections causes the filesystem to overestimate available free sections in the active, reduced main area. This leads to inconsistent free section accounting during GC data migration and can trigger unexpected allocation failures or assertion errors when space is tight. Fix this by calculating the number of already-free sections in the truncated range, deducting them from free_sections upon entering free_segment_range(), and restoring them on exit. Fixes: b4b10061ef98 ("f2fs: refactor resize_fs to avoid meta updates in pro= gress") Cc: stable@vger.kernel.org Signed-off-by: Daeho Jeong Signed-off-by: Sunmin Jeong Reviewed-by: Chao Yu --- v2: elaborate on the issue in the commit message. --- fs/f2fs/gc.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 787133ee2eb2..f3a6fc6d08ae 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -2200,8 +2200,9 @@ int f2fs_gc_range(struct f2fs_sb_info *sbi, static int free_segment_range(struct f2fs_sb_info *sbi, unsigned int secs, bool dry_run) { - unsigned int next_inuse, start, end; + unsigned int secno, next_inuse, start, end, end_secno; struct cp_control cpc =3D { CP_RESIZE, 0, 0, 0 }; + unsigned int freed_secs =3D 0; int gc_mode, gc_type; int err =3D 0; int type; @@ -2210,6 +2211,7 @@ static int free_segment_range(struct f2fs_sb_info *sb= i, MAIN_SECS(sbi) -=3D secs; start =3D MAIN_SECS(sbi) * SEGS_PER_SEC(sbi); end =3D MAIN_SEGS(sbi) - 1; + end_secno =3D GET_SEC_FROM_SEG(sbi, end); =20 mutex_lock(&DIRTY_I(sbi)->seglist_lock); for (gc_mode =3D 0; gc_mode < MAX_GC_POLICY; gc_mode++) @@ -2221,6 +2223,14 @@ static int free_segment_range(struct f2fs_sb_info *s= bi, sbi->next_victim_seg[gc_type] =3D NULL_SEGNO; mutex_unlock(&DIRTY_I(sbi)->seglist_lock); =20 + spin_lock(&FREE_I(sbi)->segmap_lock); + for (secno =3D MAIN_SECS(sbi); secno <=3D end_secno; secno++) { + if (!test_bit(secno, FREE_I(sbi)->free_secmap)) + freed_secs++; + } + FREE_I(sbi)->free_sections -=3D freed_secs; + spin_unlock(&FREE_I(sbi)->segmap_lock); + /* Move out cursegs from the target range */ for (type =3D CURSEG_HOT_DATA; type < NR_CURSEG_TYPE; type++) { err =3D f2fs_allocate_segment_for_resize(sbi, type, start, end); @@ -2245,6 +2255,9 @@ static int free_segment_range(struct f2fs_sb_info *sb= i, f2fs_bug_on(sbi, 1); } out: + spin_lock(&FREE_I(sbi)->segmap_lock); + FREE_I(sbi)->free_sections +=3D freed_secs; + spin_unlock(&FREE_I(sbi)->segmap_lock); MAIN_SECS(sbi) +=3D secs; return err; } --=20 2.55.0.860.g4b6b3295ed-goog