Skip to contentSkip to conversation

fs/ntfs3: end trim runs at fully allocated bitmap windows

PATCH New Hungyu Lin 1 participant 1 message Nov 3

Subsystems (2)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 fs/ntfs3: end trim runs at fully allocated bitmap windows

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")
---
 fs/ntfs3/bitmap.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/ntfs3/bitmap.c +9 -1
index 60b362f388d960558cd8ea65680df266e26dabd5..8875e6feff9c9715933545dc2fc173a191302ddc 100644
@@ -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

Signature · 1 line
2.43.0