From: Hungyu Lin <dennylin0707@gmail.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Chao Yu <chao@kernel.org>,
linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Hungyu Lin <dennylin0707@gmail.com>
Subject: [PATCH] f2fs: preserve 64-bit FITRIM minimum lengths
Date: Sat, 31 Oct 2026 23:39:35 +0000 [thread overview]
Message-ID: <20261031233935.9600-1-dennylin0707@gmail.com> (raw)
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")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
fs/f2fs/f2fs.h | 2 +-
fs/f2fs/file.c | 4 ++--
fs/f2fs/segment.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index f7423b3f6e4a..94ff3852bd1c 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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 {
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index e2c0f5083313..93a9c04bca0f 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -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)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 43f400715766..384e0cd5e5b9 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -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;
--
2.43.0
reply other threads:[~2026-10-31 23:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261031233935.9600-1-dennylin0707@gmail.com \
--to=dennylin0707@gmail.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®