TRIM and garbage collection: keeping an SSD fast over time
Solid-state drives use NAND flash, which must erase whole blocks before rewriting. Garbage collection consolidates valid data and erases stale pages, while TRIM tells the SSD which pages are invalid, making GC more efficient. This article explains both mechanisms and how to verify TRIM support on common operating systems.

Why SSDs need housekeeping
Solid-state drives store data in NAND flash memory, organized into pages for read and write operations and blocks for erasure. As the SNIA SSD overview explains, NAND is programmed in pages and erased in blocks that contain many pages.
Because a block must be erased before its pages can be rewritten, deleting a file does not immediately free its data on the SSD. The operating system marks the space as available, but the SSD retains the old contents until a block can be reclaimed. Over time, many blocks contain a mix of valid and stale pages, and writes become slower as the controller must move data around.
Garbage collection in action
Garbage collection is the background process that reclaims stale pages. The SSD reads the still-valid pages from a block, writes them to an already-erased block, and then erases the old block, making all its pages free. Samsung's SSD FAQ describes this as reading only the pages containing good data and rewriting them to empty blocks.
This process consumes write cycles, because data is moved even when the host is not writing. It also benefits from additional free space, often called over-provisioning. Many SSDs include a reserved area so that garbage collection always has a target block to write into.
TRIM: keeping the SSD informed
TRIM is a command that lets the operating system tell the SSD which pages are no longer in use. When a file is deleted, the OS marks the space as free but does not automatically inform the SSD. In Windows, this mechanism is referred to as file-delete notification, and it is controlled by a setting in the file system behavior. The Microsoft fsutil behavior documentation describes how to query and set that parameter.
Without TRIM, the SSD would continue to treat deleted pages as valid, forcing garbage collection to move them unnecessarily. With TRIM, the SSD can preemptively ignore those pages, which keeps write performance high and reduces unnecessary write amplification.
Checking and enabling TRIM on your system
On Windows, the defrag command includes a retrim option (defrag /l) that reissues TRIM commands to SSDs. The Microsoft defrag documentation also notes that the scheduled maintenance task for SSDs performs retrim and analysis about once per month.
For Linux systems using the ext4 filesystem, the discard mount option tells the kernel to issue TRIM commands automatically. The Linux kernel ext4 documentation describes this feature among the filesystem's options.
On modern NVMe drives, the Windows StorNVMe driver supports the Dataset Management command, which is used for TRIM (Deallocate). The Microsoft StorNVMe documentation lists this command as supported for I/O operations.
| Operating system | Command or setting | What it does |
|---|---|---|
| Windows | fsutil behavior query disabledeletenotify | Shows if TRIM is disabled (1) or enabled (0) |
| Windows | defrag /l | Performs retrim on the specified volume |
| Linux (ext4) | discard mount option | Issues TRIM commands automatically |
| NVMe (Windows) | Dataset Management command | Used by the driver for TRIM (Deallocate) |
Frequently asked questions
What is TRIM?
TRIM is a command that tells an SSD which data blocks are no longer in use, allowing the drive to skip them during garbage collection. It is also called file-delete notification in some operating systems.
Does TRIM cause data loss?
No. TRIM only applies to space that the operating system has already marked as deleted. The SSD uses this information to avoid moving invalid pages, but it does not erase valid files.
How can one check if TRIM is enabled on Windows?
Run the command fsutil behavior query disabledeletenotify at a command prompt. A value of 0 means TRIM is enabled, while a value of 1 disables it.
Why does Windows skip traditional defrag on SSDs?
Traditional defragmentation is unnecessary for SSDs and can cause extra writes. Instead, the scheduled maintenance task performs retrim and analysis, as described in the Microsoft defrag documentation.
