Hello
As you know, Linux has pretty good documentation on what filesystems support trim. Windows does not. Looking at the Wikipedia entry at the time of writing states that "TRIM is known to be supported for ReFS and NTFS, both of which implement a DisableDeleteNotify switch for disabling it.[47] Sources disagree on whether TRIM support exists for other filesystems." I confirmed the DisableDeleteNotify switch doesn't work on exFAT or FAT(32) volumes.
Let's answer TRIM support for other filesystems. (TLDR: Windows does not support TRIM on other filesystems) So how do you test TRIM for exFAT or FAT32?
- Windows (I used Windows 11 23H2)
- Linux (can all be run on live USB. I used Ubuntu 24.04.1 live USB)
- A partition formatted as exFAT or FAT(32) on a drive with deterministic TRIM support
Let's focus on the last requirement. We will need Linux to test TRIM support first. Running lsblk --discard
will print a table with the following columns:
NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
As long as DISC-GRAN is greater than 0 for a disk, it supports TRIM.
However, just because a disk supports TRIM does not require it to immediately change block content. A disk can queue up and remember what blocks have been trimmed and can return the original data in the meantime, or ignore TRIM depending on block size of the SSD (confusing name compared to blocks in any storage. In SSD, a logical block size, for example of size 4 KiB, is called a page. You can read and write to an SSD one page at a time. But you can't erase a page. Instead, a group of pages, called a block, must be erased together before the page can be written again). It can even return different data every time you read the block. On SATA SSDs, you can have non-deterministic TRIM as described above. You can also have Deterministic TRIM (DRAT) which return the same content every time after a block has been erased. A special type of DRAT is Deterministic Read Zero After TRIM (RZAT) which returns a 0 every time a block is read. You can test this with hdparm -I {path to disk} | grep -i trim
For NVMe, a drive with TRIM should support deterministic TRIM according to the standard. The SSD in my laptop does support deterministic TRIM. However, VMWare and Virtualbox do not, so you will need a physical machine to test this out. According to this wonderful StackExchange answer, running the command nvme id-ns {path to NVMe device} -H | grep -A 4 "dlfeat"
will print this output:
dlfeat : 1
[4:4] : 0 Guard Field of Deallocated Logical Blocks is set to 0xFFFF
[3:3] : 0 Deallocate Bit in the Write Zeroes Command is Not Supported
[2:0] : 0x1 Bytes Read From a Deallocated Logical Block and its Metadata are 0x00
The third entry of Bytes Read From a Deallocated Logical Block ... are 0x00 tells us the SSD will zero out trimmed blocks.
Now that we have established how to test out TRIM, let's test TRIM capabilities of Windows. First, I created a file in ExFAT partition. Booting into Linux (or creating the file in Linux to start with), you can run sudo filefrag -s -e {path to file}
The -s flag forces a sync (important if you created the file in Linux to begin with) and -e gives us the extent table (even though exFAT does not support extents, it is not necessary).
It will give you the block size and the physical offset. Get the byte offset by multipllying block size * physical offset in the calculator app. Then, you can install ghex and run `sudo ghex {path to partition}. Then, either with Ctrl + J, you can give the byte offset to get to the location of the file on the partition itself. Finally, we boot back into Windows and delete the file with Shift + Delete. We further run the retrim command to ensure all free space is trimmed:
Optimize-Volume -DriveLetter {drive letter without :} -ReTrim -Verbose
It gave an error, already suggesting Windows does not support TRIM. Booting back into Linux, I went to the same offset in ghex and confirmemd the data is still there. I mounted the exfat partition, ran sudo fstrim -a -v
which frees up all the free space in all mounted filesystems. Then, I cleared the OS cache by rebooting (although I distinctly remember there used to be a command that could clear the cache). I checked in ghex, and it was all zeros. In your case, if your SSD supports deterministic TRIM with a different pattern, it will print that pattern instead.
In conclusion, Windows does not support TRIM for exFAT or FAT32 partitions. Therefore, if your drive supports TRIM, you should be able to TRIM it in Linux by mounting the filesystem and running sudo fstrim -a -v
Finally, if you are using encryption, Bitlocker supports TRIM (so provided you are using NTFS or ReFS). On Linux, dm-crypt/LUKS does not enable TRIM by default due to decreased security: trimmed blocks can reveal empty space and this can provide more information to an attacker. Bitlocker will also reveal free space due to TRIM. However, if you wish to enable TRIM, the instructions for that are here
Sidenote: If you have been running LUKS encryption distro for years, it may be insecure as the defaults improved. You can improve it by following the instructions here
macOS supports TRIM for APFS and HFS+, and for FileVault (old-school Core Storage) based volumes as well as the newer encrypted APFS volumes on Apple SSDs. For other SSDs or some external SSDs, you may need to use trimforce command. Howard Oakley does an excellent job covering this here
Another important point is that USB drives may not support TRIM. Coupled with the lack of TRIM support for exFAT and FAT-based filesystems in Windows and macOS, you could get write amplification even for the less common USB drives that support TRIM. The wikipedia entry on TRIM does state "As of 2024, many SSDs had internal garbage collection mechanisms for certain filesystem(s) (such as FAT32, NTFS, APFS) that worked independently of trimming." Therefore, some USB flash drives could manually read the filesystem and trim the empty freespace internally (this is more likely to be true for FAT(32) filesystem than exFAT as it is older and the specification was known well before 2019 unlike exFAT. If a drive does support TRIM, you can always plug it in a Linux system and run
fstrim -a -v