From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 97D0D39DBDB for ; Fri, 21 Aug 2026 08:29:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787300944; cv=none; b=eBqaYRLBS9Dhg2eUD/rXzo3yayhBs66CypKxphfYyY86pY5iJcpLLUem7plLDf9w739hcfsY6E/bSO1Yl5Y0kVSU5xJv9G10RFXW+H0ZltMgVBTTnBeYdrgdqZRjUEB2DWDNFsNsgMVb/93nibi3eM4d3rrLhm0bCEfLE6qORgc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787300944; c=relaxed/simple; bh=pQPoPH1SuhFjgQZFX4t7BlZVW4qbKx4CLm9iKLdtmUI=; h=From:To:Cc:In-Reply-To:Subject:Date:Message-ID:MIME-Version: Content-Type:References; b=pkuZeikRdNSlOao1lF8BxiUWBTuTjrq+O1hMegnRrAwBni1kgQ4Yulh+4G+X1ccd2/jWrYij5pU8I9OZaP1/SGcv8KokBZo3rCorp8LK1dsIU4RR4qgDiloC/NNooDMqbjt/8brbzRUjzNt9O2AKDEQcOCrTc51//OS5Pe8Wr2s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=jx81fnpO; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="jx81fnpO" Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20260821082851epoutp0341814793f6e7f8c7abfa64b1d86408b3~NxLpVb8Nc0078400784epoutp03p for ; Fri, 21 Aug 2026 08:28:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20260821082851epoutp0341814793f6e7f8c7abfa64b1d86408b3~NxLpVb8Nc0078400784epoutp03p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1787300931; bh=pQPoPH1SuhFjgQZFX4t7BlZVW4qbKx4CLm9iKLdtmUI=; h=From:To:Cc:In-Reply-To:Subject:Date:References:From; b=jx81fnpO/V1yuvUfWXKzxCronfYbIq3QHOSlCPZF4xitEAiytfrtc6VV9shpLkOxi k9dO4H0MfqGTXOMXfI7G+VhY7Tt+vzHMzWo8Z4th6sdsxnnuttftj4bUhSCdp2y3y9 MTbmys//u+e2t0y9Dwiz360+2ixUJLmnrwhXtpRo= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPS id 20260821082851epcas1p3a1f71a5bfc261c55299bfd1144687a47~NxLo5Q-pG2419024190epcas1p3p; Fri, 21 Aug 2026 08:28:51 +0000 (GMT) Received: from epcas1p3.samsung.com (unknown [182.195.38.114]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4hRD3l0B9Fz6B9mH; Fri, 21 Aug 2026 08:28:51 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20260821082850epcas1p4c3e521eb2d2f637a01d024f02956b442~NxLn5wviM1133911339epcas1p40; Fri, 21 Aug 2026 08:28:50 +0000 (GMT) Received: from youngjingil03 (unknown [10.253.98.35]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20260821082850epsmtip1f83231c2d815fd5cb0a6fc3131b64c9c~NxLn2Q2at0184201842epsmtip1B; Fri, 21 Aug 2026 08:28:50 +0000 (GMT) From: "Yeongjin Gil" To: "'Daeho Jeong'" , "'Chao Yu'" Cc: "'Daeho Jeong'" , , , , "'Yeongjin Gil'" , =?UTF-8?B?J+ygleyEoOuvvCc=?= In-Reply-To: Subject: RE: [f2fs-dev] [PATCH] f2fs: accurately adjust free_sections during free_segment_range Date: Fri, 21 Aug 2026 17:28:49 +0900 Message-ID: <001401dd3147$17b1f300$4715d900$@samsung.com> 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 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQEvuJ6eLZKBOz9KHu5YGh+YwcMYSwLKjcABAhkCCecCpHaX0AE6qsM6AnCkI/e3qXnZ0A== Content-Language: ko X-CMS-MailID: 20260821082850epcas1p4c3e521eb2d2f637a01d024f02956b442 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 101P cpgsPolicy: CPGSC10-711,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260820161308epcas1p4a14d03c7418eb82241f42d668a0e3d45 References: <20260818171412.3201082-1-daeho43@gmail.com> <0e1162de-1ad4-4c24-a5c9-cd05c5b08cc0@kernel.org> <8c21e8cb-00ba-497b-94a8-55219e14653f@kernel.org> > On Thu, Aug 20, 2026 at 6:19=E2=80=AFAM=20Chao=20Yu=20= =20wrote:=0D=0A>=20>=0D=0A>=20>=20On=208/20/26=2002:26,=20Daeho=20Jeong=20w= rote:=0D=0A>=20>=20>=20On=20Tue,=20Aug=2018,=202026=20at=208:57=E2=80=AFPM= =20Chao=20Yu=20=20wrote:=0D=0A>=20>=20>>=0D=0A>=20>=20>>= =20On=208/19/26=2001:14,=20Daeho=20Jeong=20wrote:=0D=0A>=20>=20>>>=20From:= =20Daeho=20Jeong=20=0D=0A>=20>=20>>>=0D=0A>=20>=20= >>>=20In=20free_segment_range(),=20MAIN_SECS(sbi)=20is=20temporarily=20redu= ced=20by=0D=0A>=20>=20>>>=20=60secs=60=20while=20valid=20blocks=20in=20the= =20truncated=20range=20are=20evacuated=20by=20GC.=0D=0A>=20>=20>>>=0D=0A>= =20>=20>>>=20However,=20if=20any=20sections=20within=20the=20truncated=20ra= nge=20were=20already=0D=0A>=20>=20>>>=20free,=20failing=20to=20deduct=20the= m=20from=20FREE_I(sbi)->free_sections=20leads=0D=0A>=20>=20>>>=20to=20an=20= over-estimation=20of=20available=20space=20in=20the=20reduced=20main=20area= ,=0D=0A>=20>=20>>>=20causing=20inconsistent=20free=20section=20accounting.= =0D=0A>=20>=20>>=0D=0A>=20>=20>>=20Can=20you=20please=20show=20me=20an=20ex= ample=20for=20above=20case?=20I=20didn't=20get=20it.=0D=0A>=20>=20>=0D=0A>= =20>=20>=20Here=20is=20a=20concrete=20example=20explaining=20why=20this=20a= djustment=20is=20needed:=0D=0A>=20>=0D=0A>=20>=20Thanks=20for=20the=20detai= led=20explanation.=0D=0A>=20>=0D=0A>=20>=20>=0D=0A>=20>=20>=20Suppose:=0D= =0A>=20>=20>=20-=20Total=20main=20sections:=20MAIN_SECS=20=3D=20100=20(sect= ions=200=20..=2099)=0D=0A>=20>=20>=20-=20Total=20free=20sections:=20free_se= ctions=20=3D=2030=0D=0A>=20>=20>=20-=20We=20want=20to=20shrink=20the=20file= system=20by=2010=20sections=20(secs=20=3D=2010,=20range=0D=0A>=2090=20..=20= 99).=0D=0A>=20>=20>=20-=20Within=20the=20truncated=20range=20(sections=2090= =20..=2099):=0D=0A>=20>=20>=20=20=20=20*=206=20sections=20are=20already=20f= ree=20(free_secmap=20bit=20is=200)=0D=0A>=20>=20>=20=20=20=20*=204=20sectio= ns=20are=20in-use=20with=20valid=20blocks=20that=20need=20to=20be=20migrate= d=0D=0A>=20by=20GC.=0D=0A>=20>=20>=20When=20free_segment_range()=20enters:= =0D=0A>=20>=20>=201.=20MAIN_SECS=20is=20temporarily=20reduced=20from=20100= =20to=2090=20so=20that=20new=20block=0D=0A>=20>=20>=20=20=20=20=20allocatio= ns=20are=20constrained=20to=20sections=200=20..=2089.=0D=0A>=20>=20>=202.= =20The=20actual=20number=20of=20free=20sections=20available=20in=20the=20re= duced=20range=0D=0A>=20>=20>=20=20=20=20=20(0=20..=2089)=20is=20only=2024= =20(30=20-=206=20=3D=2024).=0D=0A>=20>=20>=203.=20Without=20this=20patch:= =0D=0A>=20>=20>=20=20=20=20=20-=20free_sections=20remains=2030=20while=20MA= IN_SECS=20is=2090.=0D=0A>=20>=20>=20=20=20=20=20-=20During=20the=20subseque= nt=20GC=20migrations,=20free=20section=20checks=20(such=20as=0D=0A>=20>=20>= =20=20=20=20=20=20=20has_not_enough_free_secs())=20will=20over-estimate=20a= vailable=20space=0D=0A>=20>=20>=20by=206=0D=0A>=20>=0D=0A>=20>=20But=20free= _segment_range()=20won't=20call=20into=20has_not_enough_free_secs(),=0D=0A>= =20>=20if=20I'm=20not=20missing=20anything.=0D=0A>=20=0D=0A>=20Oh,=20right.= =20I=20missed=20it's=20FG_GC.=0D=0A>=20I=20think=20we=20can=20drop=20this= =20patch.=0D=0A>=20=0D=0A>=20Thanks.=0D=0A>=0D=0AI=20wonder=20if=20the=20fr= ee-section=20adjustment=20could=20still=20be=20relevant=0D=0Ato=20the=20SSR= /LFS=20allocation=20decision=20during=20resize.=0D=0A=0D=0ACould=20you=20pl= ease=20also=20check=20whether=20free_sections=20may=20affect=0D=0Aallocatio= n=20through=20the=20following=20paths?=0D=0A=0D=0A=20=20free_segment_range(= )=0D=0A=20=20=20=20->=20f2fs_allocate_segment_for_resize()=0D=0A=20=20=20= =20=20=20->=20f2fs_need_SSR()=0D=0A=20=20=20=20=20=20->=20new_curseg()=0D= =0A=20=20=20=20=20=20=20=20->=20get_new_segment()=0D=0A=0D=0AAlso,=20when= =20a=20current=20segment=20becomes=20full=20during=20block=20migration:=0D= =0A=0D=0A=20=20free_segment_range()=0D=0A=20=20=20=20->=20f2fs_gc_range()= =0D=0A=20=20=20=20=20=20->=20do_garbage_collect()=0D=0A=20=20=20=20=20=20= =20=20->=20f2fs_allocate_data_block()=0D=0A=20=20=20=20=20=20=20=20=20=20->= =20need_new_seg()=0D=0A=20=20=20=20=20=20=20=20=20=20=20=20->=20f2fs_need_S= SR()=0D=0A=20=20=20=20=20=20=20=20=20=20=20=20->=20new_curseg()=0D=0A=20=20= =20=20=20=20=20=20=20=20=20=20=20=20->=20get_new_segment()=0D=0A=0D=0AIf=20= free_sections=20still=20include=20free=20sections=20in=20the=20range=20bein= g=0D=0Aremoved,=20f2fs_need_SSR()=20may=20choose=20LFS=20allocation=20inste= ad=20of=20SSR.=0D=0ASince=20get_new_segment()=20searches=20only=20within=20= the=20temporarily=20reduced=0D=0AMAIN_SECS=20range,=20it=20may=20fail=20to= =20find=20a=20free=20section.=0D=0A=0D=0ACould=20you=20please=20confirm=20w= hether=20this=20case=20also=20needs=20to=20be=20handled?=0D=0A=0D=0AThanks,= =0D=0A>=20>=0D=0A>=20>=20Not=20sure,=20maybe=20you=20mean=20other=20threads= =20will=20call=0D=0A>=20>=20has_not_enough_free_secs(),=20are=20you=20worri= ed=20about=20that=20we=20may=20miss=0D=0A>=20chances=20to=20call=20fggc=20e= arlier=20in=20below=20cases:=0D=0A>=20>=0D=0A>=20>=20f2fs_balance_fs=20->= =20has_enough_free_secs=20->=20f2fs_gc?=20I=20guess=20it=20will=0D=0A>=20>= =20blocked=20on=20gc_lock.=0D=0A>=20=0D=0A>=20>=0D=0A>=20>=20>=20=20=20=20= =20=20=20sections=20in=20the=20active=200=20..=2089=20range.=0D=0A>=20>=20>= =20=20=20=20=20-=20If=20free_segment_range()=20fails=20midway=20(e.g.=20-EA= GAIN),=0D=0A>=20free_sections=0D=0A>=20>=20>=20=20=20=20=20=20=20accounting= =20becomes=20inconsistent.=0D=0A>=20>=0D=0A>=20>=20Why=20free_sections=20ac= counting=20becomes=20inconsistent=20if=0D=0A>=20>=20free_segment_range()=20= fails=20midway?=0D=0A>=20>=0D=0A>=20>=20Thanks,=0D=0A>=20>=0D=0A>=20>=20>= =20With=20this=20patch:=0D=0A>=20>=20>=20-=20We=20count=20the=206=20already= -free=20sections=20in=20the=20truncated=20range=20(90=20..=0D=0A>=2099)=20a= nd=0D=0A>=20>=20>=20=20=20=20deduct=20them=20from=20free_sections=20upon=20= entering=20(30=20-=206=20=3D=2024),=0D=0A>=20perfectly=0D=0A>=20>=20>=20=20= =20=20matching=20the=20actual=20free=20sections=20in=20the=20active=20range= =200=20..=2089.=0D=0A>=20>=20>=20-=20On=20exit,=20the=20deducted=20amount= =20is=20restored,=20keeping=20free_sections=0D=0A>=20consistent=0D=0A>=20>= =20>=20=20=20=20throughout=20the=20entire=20resize=20lifecycle.=0D=0A>=20>= =20>=0D=0A>=20>=20>=20Hope=20this=20clarifies=20the=20scenario=21=0D=0A>=20= >=20>=0D=0A>=20>=20>=20Thanks,=0D=0A>=20>=20>=0D=0A>=20>=20>>=0D=0A>=20>=20= >>=20BTW,=20it=20needs=20to=20rebase=20this=20patch=20on=20dev-test=20branc= h.=0D=0A>=20>=20>>=0D=0A>=20>=20>>=20Thanks,=0D=0A>=20>=20>>=0D=0A>=20>=20>= >>=0D=0A>=20>=20>>>=20Fix=20this=20by=20calculating=20the=20number=20of=20a= lready-free=20sections=20in=20the=0D=0A>=20>=20>>>=20truncated=20range=20un= der=20segmap_lock,=20deducting=20them=20from=0D=0A>=20>=20>>>=20free_sectio= ns=20upon=20entering=20free_segment_range(),=20and=20restoring=20them=0D=0A= >=20under=20segmap_lock=20on=20exit.=0D=0A>=20>=20>>>=0D=0A>=20>=20>>>=20Si= gned-off-by:=20Daeho=20Jeong=20=0D=0A>=20>=20>>>= =20Signed-off-by:=20Sunmin=20Jeong=20=0D=0A>=20>= =20>>>=20---=0D=0A>=20>=20>>>=20=20=20fs/f2fs/gc.c=20=7C=2015=20+++++++++++= +++-=0D=0A>=20>=20>>>=20=20=201=20file=20changed,=2014=20insertions(+),=201= =20deletion(-)=0D=0A>=20>=20>>>=0D=0A>=20>=20>>>=20diff=20--git=20a/fs/f2fs= /gc.c=20b/fs/f2fs/gc.c=20index=0D=0A>=20>=20>>>=20787133ee2eb2..f3a6fc6d08a= e=20100644=0D=0A>=20>=20>>>=20---=20a/fs/f2fs/gc.c=0D=0A>=20>=20>>>=20+++= =20b/fs/f2fs/gc.c=0D=0A>=20>=20>>>=20=40=40=20-2200,8=20+2200,9=20=40=40=20= int=20f2fs_gc_range(struct=20f2fs_sb_info=20*sbi,=0D=0A>=20>=20>>>=20=20=20= static=20int=20free_segment_range(struct=20f2fs_sb_info=20*sbi,=0D=0A>=20>= =20>>>=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20unsigned=20int=20secs,=20bool=20dry_run)=0D=0A>= =20>=20>>>=20=20=20=7B=0D=0A>=20>=20>>>=20-=20=20=20=20=20unsigned=20int=20= next_inuse,=20start,=20end;=0D=0A>=20>=20>>>=20+=20=20=20=20=20unsigned=20i= nt=20secno,=20next_inuse,=20start,=20end,=20end_secno;=0D=0A>=20>=20>>>=20= =20=20=20=20=20=20=20struct=20cp_control=20cpc=20=3D=20=7B=20CP_RESIZE,=200= ,=200,=200=20=7D;=0D=0A>=20>=20>>>=20+=20=20=20=20=20unsigned=20int=20freed= _secs=20=3D=200;=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20int=20gc_mode,=20g= c_type;=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20int=20err=20=3D=200;=0D=0A>= =20>=20>>>=20=20=20=20=20=20=20=20int=20type;=0D=0A>=20>=20>>>=20=40=40=20-= 2210,6=20+2211,7=20=40=40=20static=20int=20free_segment_range(struct=0D=0A>= =20f2fs_sb_info=20*sbi,=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20MAIN_SECS(s= bi)=20-=3D=20secs;=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20start=20=3D=20MA= IN_SECS(sbi)=20*=20SEGS_PER_SEC(sbi);=0D=0A>=20>=20>>>=20=20=20=20=20=20=20= =20end=20=3D=20MAIN_SEGS(sbi)=20-=201;=0D=0A>=20>=20>>>=20+=20=20=20=20=20e= nd_secno=20=3D=20GET_SEC_FROM_SEG(sbi,=20end);=0D=0A>=20>=20>>>=0D=0A>=20>= =20>>>=20=20=20=20=20=20=20=20mutex_lock(&DIRTY_I(sbi)->seglist_lock);=0D= =0A>=20>=20>>>=20=20=20=20=20=20=20=20for=20(gc_mode=20=3D=200;=20gc_mode= =20<=20MAX_GC_POLICY;=20gc_mode++)=20=40=40=0D=0A>=20>=20>>>=20-2221,6=20+2= 223,14=20=40=40=20static=20int=20free_segment_range(struct=0D=0A>=20f2fs_sb= _info=20*sbi,=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20sbi->next_victim_seg=5Bgc_type=5D=20=3D=20NULL_S= EGNO;=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20mutex_unlock(&DIRTY_I(sbi)->s= eglist_lock);=0D=0A>=20>=20>>>=0D=0A>=20>=20>>>=20+=20=20=20=20=20spin_lock= (&FREE_I(sbi)->segmap_lock);=0D=0A>=20>=20>>>=20+=20=20=20=20=20for=20(secn= o=20=3D=20MAIN_SECS(sbi);=20secno=20<=3D=20end_secno;=20secno++)=20=7B=0D= =0A>=20>=20>>>=20+=20=20=20=20=20=20=20=20=20=20=20=20=20if=20(=21test_bit(= secno,=20FREE_I(sbi)->free_secmap))=0D=0A>=20>=20>>>=20+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20freed_secs++;=0D=0A>=20>=20>>>= =20+=20=20=20=20=20=7D=0D=0A>=20>=20>>>=20+=20=20=20=20=20FREE_I(sbi)->free= _sections=20-=3D=20freed_secs;=0D=0A>=20>=20>>>=20+=20=20=20=20=20spin_unlo= ck(&FREE_I(sbi)->segmap_lock);=0D=0A>=20>=20>>>=20+=0D=0A>=20>=20>>>=20=20= =20=20=20=20=20=20/*=20Move=20out=20cursegs=20from=20the=20target=20range= =20*/=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20for=20(type=20=3D=20CURSEG_HO= T_DATA;=20type=20<=20NR_CURSEG_TYPE;=20type++)=20=7B=0D=0A>=20>=20>>>=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20err=20=3D=20f2fs_allocate_segment= _for_resize(sbi,=20type,=0D=0A>=20>=20>>>=20start,=20end);=20=40=40=20-2245= ,6=20+2255,9=20=40=40=20static=20int=0D=0A>=20free_segment_range(struct=20f= 2fs_sb_info=20*sbi,=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20f2fs_bug_on(sbi,=201);=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20=7D= =0D=0A>=20>=20>>>=20=20=20out:=0D=0A>=20>=20>>>=20+=20=20=20=20=20spin_lock= (&FREE_I(sbi)->segmap_lock);=0D=0A>=20>=20>>>=20+=20=20=20=20=20FREE_I(sbi)= ->free_sections=20+=3D=20freed_secs;=0D=0A>=20>=20>>>=20+=20=20=20=20=20spi= n_unlock(&FREE_I(sbi)->segmap_lock);=0D=0A>=20>=20>>>=20=20=20=20=20=20=20= =20MAIN_SECS(sbi)=20+=3D=20secs;=0D=0A>=20>=20>>>=20=20=20=20=20=20=20=20re= turn=20err;=0D=0A>=20>=20>>>=20=20=20=7D=0D=0A>=20>=20>>=0D=0A>=20>=0D=0A>= =20=0D=0A>=20=0D=0A>=20_______________________________________________=0D= =0A>=20Linux-f2fs-devel=20mailing=20list=0D=0A>=20Linux-f2fs-devel=40lists.= sourceforge.net=0D=0A>=20https://lists.sourceforge.net/lists/listinfo/linux= -f2fs-devel=0D=0A=0D=0A