[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20241018100150.2852132-1-chao@kernel.org>
Date: Fri, 18 Oct 2024 18:01:50 +0800
From: Chao Yu <chao@...nel.org>
To: jaegeuk@...nel.org
Cc: linux-f2fs-devel@...ts.sourceforge.net,
linux-kernel@...r.kernel.org,
Chao Yu <chao@...nel.org>,
Daniel Rosenberg <drosen@...gle.com>,
Qi Han <hanqi@...o.com>
Subject: [PATCH RFC] f2fs: revalidate empty segment when checkpoint is disabled
If checkpoint is off, let's set segment as free once all newly
written datas were removed, it fixes below case:
dd if=/dev/zero of=f2fs.img bs=1M count=64
mkfs.f2fs -f f2fs.img
mount -o checkpoint=disable:10% f2fs.img mnt
dd if=/dev/zero of=mnt/file bs=1M count=19
sync
rm mnt/file
dd if=/dev/zero of=mnt/file bs=1M count=9
dd: error writing 'mnt/file': No space left on device
Cc: Daniel Rosenberg <drosen@...gle.com>
Reported-by: Qi Han <hanqi@...o.com>
Signed-off-by: Chao Yu <chao@...nel.org>
---
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 = get_valid_blocks(sbi, segno, false);
ckpt_valid_blocks = get_ckpt_valid_blocks(sbi, segno, false);
+ /*
+ * 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 == 0 && ckpt_valid_blocks == 0) {
+ __remove_dirty_segment(sbi, segno, DIRTY);
+ __set_test_and_free(sbi, segno, false);
+ goto out_lock;
+ }
+
if (valid_blocks == 0 && (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) ||
ckpt_valid_blocks == usable_blocks)) {
__locate_dirty_segment(sbi, segno, PRE);
@@ -859,7 +870,7 @@ static void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno)
/* Recovery routine with SSR needs this */
__remove_dirty_segment(sbi, segno, DIRTY);
}
-
+out_lock:
mutex_unlock(&dirty_i->seglist_lock);
}
--
2.40.1
Powered by blists - more mailing lists