From: Hungyu Lin <dennylin0707@gmail.com>
To: almaz.alexandrovich@paragon-software.com
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Hungyu Lin <dennylin0707@gmail.com>
Subject: [PATCH] fs/ntfs3: end trim runs at fully allocated bitmap windows
Date: Tue, 3 Nov 2026 06:05:56 +0000 [thread overview]
Message-ID: <20261103060556.55571-1-dennylin0707@gmail.com> (raw)
ntfs_trim_fs() keeps a free run pending across bitmap windows. When
the cached free-bit count of a window is zero, the loop skips it without
ending the pending run. Free clusters at the start of a later window
are then added to the old length despite the allocated gap.
For example, two eight-cluster holes separated by fully allocated bitmap
windows can be submitted as one sixteen-cluster discard starting at the
first hole. This discards allocated clusters while leaving the actual
second hole untrimmed.
Finish a qualifying pending run and reset its length before skipping a
fully allocated window. Preserve the minimum-length check and the cached
window optimization, matching the analogous handling in wnd_rescan().
Fixes: 3f3b442b5ad2 ("fs/ntfs3: Add bitmap")
Cc: stable@vger.kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
fs/ntfs3/bitmap.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c
index 60b362f388d960558cd8ea65680df266e26dabd5..8875e6feff9c9715933545dc2fc173a191302ddc 100644
--- a/fs/ntfs3/bitmap.c
+++ b/fs/ntfs3/bitmap.c
@@ -1447,8 +1447,16 @@ int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range)
if (lcn_wnd > lcn_to)
break;
- if (!wnd->free_bits[iw])
+ if (!wnd->free_bits[iw]) {
+ if (len >= minlen) {
+ err = ntfs_discard(sbi, lcn, len);
+ if (err)
+ goto out;
+ done += len;
+ }
+ len = 0;
continue;
+ }
if (iw + 1 == wnd->nwnd)
wbits = wnd->bits_last;
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0
reply other threads:[~2026-11-03 6:11 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=20261103060556.55571-1-dennylin0707@gmail.com \
--to=dennylin0707@gmail.com \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
--cc=stable@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®