* [PATCH] fs/ntfs3: end trim runs at fully allocated bitmap windows
@ 2026-11-03 6:05 Hungyu Lin
0 siblings, 0 replies; only message in thread
From: Hungyu Lin @ 2026-11-03 6:05 UTC (permalink / raw)
To: almaz.alexandrovich; +Cc: ntfs3, linux-kernel, stable, Hungyu Lin
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-03 6:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 6:05 [PATCH] fs/ntfs3: end trim runs at fully allocated bitmap windows Hungyu Lin
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®