How Does TRIM Inform an SSD of Unused Data Blocks?
The TRIM command is a communication mechanism between an operating system's file system and a solid-state drive that identifies which data blocks are no longer in use. By sending this information to the drive's controller, the operating system prevents the SSD from needlessly preserving deleted data during internal maintenance. This process keeps write speeds consistent and reduces unnecessary wear on the flash memory cells.
Why SSDs Need the TRIM Command
Traditional hard disk drives (HDDs) can overwrite existing data directly in place, so the operating system does not need to notify the drive when a file is deleted. Instead, the file system simply marks those sectors as available in its own allocation table.
Solid-state drives store data in NAND flash memory, which operates differently. While NAND flash can read and write data at the page level (typically 4 KB to 16 KB), it can only erase data in much larger blocks (often several megabytes). Because a page cannot be overwritten without first erasing its entire block, the SSD controller must copy any still-valid pages to a new block before erasing the old one. Without TRIM, the SSD has no way of knowing which pages belong to deleted files, forcing it to copy and preserve useless data.
How the TRIM Process Works
When a file is deleted or a partition is formatted, the operating system's file system updates its metadata to mark those logical block addresses (LBAs) as free. If TRIM is enabled, the OS then issues a TRIM command to the SSD controller containing a list of those specific LBA ranges.
Upon receiving the TRIM command, the SSD controller updates its internal Flash Translation Layer (FTL), which maps logical addresses from the OS to physical pages on the NAND flash chips. The controller marks the corresponding physical pages as invalid.
Integration with Garbage Collection
Marking pages as invalid does not erase them immediately. Instead, it prepares them for the SSD's background garbage collection process:
- Identifying valid data: During idle periods, garbage collection scans blocks that contain a mix of valid and invalid pages.
- Relocating active pages: Only the remaining valid pages are copied to a fresh, empty block.
- Erasing the old block: The original block—now containing only invalid data—is erased, making all of its pages available for new writes.
Because the invalid pages are already known, the SSD avoids copying deleted data, which significantly lowers write amplification and leaves pre-erased blocks ready for incoming write operations.
Protocol Support Across Interfaces
The exact command name varies depending on the storage interface, though the underlying function is the same:
- SATA: Uses the
DATA SET MANAGEMENTcommand with the TRIM attribute. - NVMe: Uses the
Dataset Managementcommand with the Deallocate attribute. - SCSI / SAS: Uses the
UNMAPcommand.
Modern operating systems such as Windows, macOS, and Linux support these commands natively and issue them either immediately upon file deletion or on a scheduled basis.