Skip to contentSkip to conversation

f2fs: preserve 64-bit FITRIM minimum lengths

PATCH Applied Hungyu Lin 3 participants 3 messages Oct 31 – Nov 3 F2FS file system

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 f2fs: preserve 64-bit FITRIM minimum lengths

The FITRIM minimum length is a 64-bit byte count. f2fs_ioc_fitrim() narrows it to unsigned int while applying the device granularity, so a minimum of 4 GiB becomes the device granularity. fstrim can consequently discard free extents smaller than the requested minimum.

Use u64 when applying the device granularity. The checkpoint's trim_minlen already retains the 64-bit block count; also widen the discard policy field and its initializer argument so larger minimums are not truncated when passed to the issue and wait paths.

Fixes 4b2fecc84655 ("f2fs: introduce FITRIM in f2fs_ioctl")
---
 fs/f2fs/f2fs.h    | 2 +-
 fs/f2fs/file.c    | 4 ++--
 fs/f2fs/segment.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +1 -1
index f7423b3f6e4a..94ff3852bd1c 100644
@@ -522,7 +522,7 @@ struct discard_policy {
 	bool sync;			/* submit discard with REQ_SYNC flag */
 	bool ordered;			/* issue discard by lba order */
 	bool timeout;			/* discard timeout for put_super */
-	unsigned int granularity;	/* discard granularity */
+	u64 granularity;		/* discard granularity */
 };
 
 struct discard_cmd_control {
fs/f2fs/file.c +2 -2
index e2c0f5083313..93a9c04bca0f 100644
@@ -2729,8 +2729,8 @@ static int f2fs_ioc_fitrim(struct file *filp, unsigned long arg)
 	if (ret)
 		return ret;
 
-	range.minlen = max_t(unsigned int, range.minlen,
-			f2fs_hw_discard_granularity(sbi));
+	range.minlen = max_t(u64, range.minlen,
+			     f2fs_hw_discard_granularity(sbi));
 	ret = f2fs_trim_fs(sbi, &range);
 	mnt_drop_write_file(filp);
 	if (ret < 0)
fs/f2fs/segment.c +1 -1
index 43f400715766..384e0cd5e5b9 100644
@@ -1241,7 +1241,7 @@ static void __check_sit_bitmap(struct f2fs_sb_info *sbi,
 
 static void __init_discard_policy(struct f2fs_sb_info *sbi,
 				struct discard_policy *dpolicy,
-				int discard_type, unsigned int granularity)
+				int discard_type, u64 granularity)
 {
 	struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Hungyu Lin

The FITRIM minimum length is a 64-bit byte count. f2fs_ioc_fitrim() narrows it to unsigned int while applying the device granularity, so a minimum of 4 GiB becomes the device granularity. fstrim can consequently discard free extents smaller than the requested minimum.

Use u64 when applying the device granularity. The checkpoint's trim_minlen already retains the 64-bit block count; also widen the discard policy field and its initializer argument so larger minimums are not truncated when passed to the issue and wait paths.

Quoted 2 lines
Fixes 4b2fecc84655 ("f2fs: introduce FITRIM in f2fs_ioctl")

Thanks,

#2 lore raw
In reply to Hungyu Lin
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:

Quoted 11 lines · On Sat, 31 Oct 2026 23:39:35 +0000 you wrote:

The FITRIM minimum length is a 64-bit byte count. f2fs_ioc_fitrim() narrows it to unsigned int while applying the device granularity, so a minimum of 4 GiB becomes the device granularity. fstrim can consequently discard free extents smaller than the requested minimum.

Use u64 when applying the device granularity. The checkpoint's trim_minlen already retains the 64-bit block count; also widen the discard policy field and its initializer argument so larger minimums are not truncated when passed to the issue and wait paths.

[...]

Here is the summary with links:
- [f2fs-dev] f2fs: preserve 64-bit FITRIM minimum lengths

    https://git.kernel.org/jaegeuk/f2fs/c/471dd2221735

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html