From nobody Tue Nov 26 11:49:40 2024 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 7D45417D378 for ; Fri, 18 Oct 2024 10:02:01 +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=1729245721; cv=none; b=cUKSRTDqzjy35qMOFy8hL4Xyihepnd7IInW13EE1oF3E+OaFjpp8D2U9Zw2/gG9cTT6+iM7MCJQ3X2u3U5TwlOS5ycPn8foboXt3BusCHYLPq0EyV0mWKl+bywyX9jDy1bLdxjTIqg89/0SHk1DOhidLEz6AFQ0QHISBX0DqP94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729245721; c=relaxed/simple; bh=c95i7yQ7yvMxmF9U7mJUoxODymNVPbilqum2Qcc3rII=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=W1gUfHFLaY2YtGoHEgTiDo5v7BZzFW+zvkzqdN9knLz98scPg6jMBxSiQyRmAhmI7Ft730SUNMZYncd3gHHCzui+SJ7YZayQ1piSzlxPXTPM8wli4KO914wqzEaMCvd5jPQpmOPqaOEwzG0tr3dEg9mC430rtcRd4N+/EsM/vnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RH2EWPAE; 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="RH2EWPAE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C1E6C4CEC3; Fri, 18 Oct 2024 10:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729245721; bh=c95i7yQ7yvMxmF9U7mJUoxODymNVPbilqum2Qcc3rII=; h=From:To:Cc:Subject:Date:From; b=RH2EWPAE9cL7/kwE7/Kfm6Y/IhDxlxqTorp7dqmS937GwQmXH5DkJWB8wI/FTlShx PsMCDYFG+xMAbSUmUh/97FmXycbi3V3fYf2T60Apsclk+f+catDhbxyoijKtGoFib2 FhFglyLy+xrGhVHssLWKhC2H4IuWhLFAUNTNoOF1TYibJD7CU29hyIFJRDLXLa7gMX yD1Epk4CKUHh4Em4PhH3dKXgkCabk9SYhrEgpQLZU3cgURPRKO06Tt1XmfNgKMmRLy q4LyLmrn3lpL0QPbyQui9QE6FB+GriciKX63cW3N3VZW3JCh6uSFNr8w6ZOVwPLXVH g1+MwAnJXpqfA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , Daniel Rosenberg , Qi Han Subject: [PATCH RFC] f2fs: revalidate empty segment when checkpoint is disabled Date: Fri, 18 Oct 2024 18:01:50 +0800 Message-Id: <20241018100150.2852132-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 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" If checkpoint is off, let's set segment as free once all newly written datas were removed, it fixes below case: dd if=3D/dev/zero of=3Df2fs.img bs=3D1M count=3D64 mkfs.f2fs -f f2fs.img mount -o checkpoint=3Ddisable:10% f2fs.img mnt dd if=3D/dev/zero of=3Dmnt/file bs=3D1M count=3D19 sync rm mnt/file dd if=3D/dev/zero of=3Dmnt/file bs=3D1M count=3D9 dd: error writing 'mnt/file': No space left on device Cc: Daniel Rosenberg Reported-by: Qi Han Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index e172b3d0aec3..4f480bfc9618 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -849,6 +849,17 @@ static void locate_dirty_segment(struct f2fs_sb_info *= sbi, unsigned int segno) valid_blocks =3D get_valid_blocks(sbi, segno, false); ckpt_valid_blocks =3D get_ckpt_valid_blocks(sbi, segno, false); =20 + /* + * If checkpoint is off, let's set segment as free once all newly + * written datas were removed. + */ + if (is_sbi_flag_set(sbi, SBI_CP_DISABLED) && + valid_blocks =3D=3D 0 && ckpt_valid_blocks =3D=3D 0) { + __remove_dirty_segment(sbi, segno, DIRTY); + __set_test_and_free(sbi, segno, false); + goto out_lock; + } + if (valid_blocks =3D=3D 0 && (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) || ckpt_valid_blocks =3D=3D usable_blocks)) { __locate_dirty_segment(sbi, segno, PRE); @@ -859,7 +870,7 @@ static void locate_dirty_segment(struct f2fs_sb_info *s= bi, unsigned int segno) /* Recovery routine with SSR needs this */ __remove_dirty_segment(sbi, segno, DIRTY); } - +out_lock: mutex_unlock(&dirty_i->seglist_lock); } =20 --=20 2.40.1