TRIM is a command the operating system sends to an SSD to say which blocks no longer hold data after files are deleted, so the drive can erase them in the background instead of copying stale data around. On Windows, fsutil behavior query DisableDeleteNotify showing = 0 means TRIM is on (the default for NTFS); on Linux, run sudo fstrim -av or enable the weekly fstrim.timer.
This article covers why SSDs need it, how to confirm it is working on Windows and Linux, and how to run it manually.
Why SSDs need TRIM
Flash memory can't be overwritten in place. Frankie, Hughes and Kreutz-Delgado's 2012 analysis puts it plainly: flash pages "cannot be directly overwritten, but must first be erased before they can be programmed again", and the smallest unit that can be erased is a block that typically holds 64, 128 or 256 pages. So when you change a file, the SSD writes the new data to a fresh page and marks the old page invalid.
Eventually the drive runs short of fresh pages and has to clean up (garbage collection): pick a block, copy its still-valid pages somewhere else, then erase the whole block. Every copied page is an extra write the drive does on its own, which slows writes and uses up flash endurance. The ratio of actual writes to requested writes is called write amplification.
The problem is that the drive doesn't know which data the file system has deleted. When you delete a file, the file system only updates its own records; to the SSD those pages still look valid, so garbage collection keeps copying them. TRIM closes that gap. The paper's model shows that marking deleted data invalid lowers write amplification and effectively behaves like extra spare capacity (over-provisioning).
The same idea goes by other names: Windows calls it delete notification, SCSI and thin-provisioned storage call it UNMAP, and Linux calls it discard.
Check that TRIM is enabled on Windows
Open Command Prompt or PowerShell and run:
fsutil behavior query DisableDeleteNotify
Example output on Windows 11:
NTFS DisableDeleteNotify = 0 (Allows TRIM operations to be sent to the storage device)
ReFS DisableDeleteNotify = 0 (Allows TRIM operations to be sent to the storage device)
The setting is a "disable" flag, so read it backwards: 0 means TRIM is on, 1 means it is off. Microsoft's documentation states that TRIM is enabled by default on NTFS unless an administrator disables it, and that ReFS v2 has it off by default. If NTFS shows 1, turn it back on from an administrator prompt; no restart is needed:
fsutil behavior set DisableDeleteNotify 0
This setting only allows Windows to send TRIM. Whether the drive receives it also depends on the drive reporting TRIM support. To see what Windows thinks your drives are:
Get-PhysicalDisk | Select-Object FriendlyName, MediaType, BusType
Example output:
FriendlyName MediaType BusType
------------ --------- -------
WD_BLACK SN770 2TB SSD NVMe
CT1000P5PSSD8 SSD NVMe
How Windows runs TRIM automatically
Windows sends TRIM as files are deleted, and also runs a scheduled maintenance task that re-sends TRIM for all free space (a "retrim"). On this test machine the task is \Microsoft\Windows\Defrag\ScheduledDefrag and it runs defrag.exe -c -h -o -$: all volumes (-c), normal priority (-h), and "the proper optimization for each media type" (-o), which for an SSD with TRIM support means retrim rather than defragmentation.
Microsoft's defrag documentation adds two details worth knowing. The task typically runs weekly, but for SSDs the traditional optimization and retrim are done once per month, and changing the schedule doesn't change that. And the task won't wake the computer or run on battery, so a laptop that is always unplugged or asleep at maintenance time may go a while between retrims.
Run TRIM manually on Windows
From an administrator PowerShell window:
Optimize-Volume -DriveLetter C -ReTrim -Verbose
-ReTrim "generates TRIM and Unmap hints for all currently unused sectors of the volume". It is safe to run on an SSD; it does not move or defragment data. The equivalent from Command Prompt is defrag C: /l ("performs retrim on the specified volumes"). The graphical route is the Optimize Drives app (search for "defrag" or "optimize" in the Start menu), where administrators can also change how often the scheduled task runs.
Check and run TRIM on Linux
First check whether the device supports discard at all:
lsblk --discard
The DISC-GRAN column shows the discard granularity. The kernel's sysfs documentation states that "a discard_granularity of 0 means that the device does not support discard functionality", so zeros in that column mean TRIM can't reach the device. You can read the same value directly with cat /sys/block/nvme0n1/queue/discard_granularity.
To trim a mounted file system by hand:
sudo fstrim -v /
sudo fstrim -av # all mounted file systems that support discard
-v prints how many bytes were passed down for discarding. The man page notes this is an upper bound; the device may discard less.
Periodic TRIM with fstrim.timer
The usual approach on systemd-based distributions is to trim on a schedule instead of on every delete. util-linux ships an fstrim.timer unit described as "Discard unused filesystem blocks once a week" (OnCalendar=weekly), which runs fstrim --listed-in /etc/fstab:/proc/self/mountinfo --verbose --quiet-unsupported. Check it and enable it if needed:
systemctl status fstrim.timer
sudo systemctl enable --now fstrim.timer
For how to read that status output, see systemctl commands.
Periodic fstrim vs the discard mount option
The alternative is mounting with -o discard, which sends a discard each time blocks are freed. For ext4, the kernel documentation marks nodiscard as the default and says discard "is off by default until sufficient testing has been done". The fstrim man page warns that frequent trimming or the discard option "might" shorten the life of poor-quality SSDs and that once a week is enough for most desktops and servers. The weekly timer is the safer default.
When TRIM doesn't reach the drive
- USB enclosures and docks. TRIM only works if the enclosure's bridge chip passes it on. On Linux, zeros in
lsblk --discardfor the USB device mean it isn't getting TRIM. - Hardware RAID. Whether TRIM reaches the member drives depends on the controller. Check its documentation.
- Virtual machines. The guest's virtual disk has to support discard, and the host has to pass it on to the physical drive or thin-provisioned image. Microsoft notes that
-ReTrimcan "recover unused capacity on thinly provisioned drives", which is why it matters for VM disk files too.
What TRIM won't fix
TRIM keeps write performance steady and reduces internal writes; it doesn't repair a failing drive or make a full drive fast. An SSD that is nearly full has little free space for garbage collection whatever the TRIM setting, so leaving some free space helps more than any setting change. If a drive is slow or throwing errors, check its health first (see how to check SSD health), and for how SSDs compare with hard drives in the first place, see SSD vs HDD vs NVMe.
Frequently asked questions
- Does TRIM wear out an SSD?
- No. TRIM itself only tells the drive which blocks are free; it reduces the data the drive copies internally during garbage collection, which lowers write amplification. The fstrim man page does warn that trimming very frequently, or mounting with the discard option, might shorten the life of poor-quality SSDs, and suggests once a week is enough for most systems.
- Can deleted files be recovered after TRIM?
- Don't count on it. After TRIM, the drive treats those pages as invalid and its garbage collection can erase them at any time, so undelete tools that work on hard drives are unreliable on SSDs. Keep backups instead.
- Does TRIM work over USB?
- Only if the USB enclosure's bridge chip passes the command through to the drive, and not all of them do. On Linux, lsblk --discard shows zeros in the DISC-GRAN column when the device does not support discard.
- Should I defragment an SSD?
- No manual defragmentation is needed. On Windows, leave the scheduled optimization on: for SSDs it mainly runs retrim, and Microsoft documents that traditional optimization of SSDs happens at most once per month regardless of the task schedule.
Sources
- Microsoft Learn: fsutil behavior (DisableDeleteNotify)
- Microsoft Learn: Optimize-Volume
- Microsoft Learn: defrag (scheduled task and SSD policy)
- Linux kernel docs: ext4 mount options (discard)
- Linux man-pages: fstrim(8)
- util-linux: fstrim.timer unit file
- Linux kernel: sysfs-block ABI (discard_granularity)
- Frankie, Hughes, Kreutz-Delgado (2012), Analysis of Trim Commands on Overprovisioning and Write Amplification in SSDs (arXiv:1208.1794)