What is TRIM exactly?

Flash memory devices (what's used for today's SSDs) can't write arbitrary data at any moment; before writing on a cell (typically 4KB) has to be erased first. Unfortunately, the erase operation is very slow; that's why flash devices were so much slower than magnetic drives, despite having no moving parts.

Modern SSDs hide the erasing time by maintaining a set of pre-erased cells, that means that a write command won't immediately overwrite existing data, instead the drive's controller picks an erased cell, remaps it, and writes with the new data. That (and several write-thought cache strategies) gives the drive a huge speedup, greatly surpassing magnetic drives.

To ensure that there's always a set of preerased cells, any time a cell isn't needed, the drive schedules it for background erasure and adds to the list of fee cells.

Unfortunately, existing filesystems didn't bother to tell the drive when a sector was free. The drive was supposed to be just a dumb repository of bits, after all. Deleting a file or any other operation that marks a sector as free from the filesystem's point of view was only a mark on some metadata structure. The sector itself wasn't touched. Even if the filesystem cleared it by writing zeros over it, the drive couldn't know if that meant the sector was free, or if the user wanted some zeros on a file. After a time, the drive wouldn't have any free cell to erase before writing; and performance degraded tragically.

The TRIM instruction was quickly drafted and adopted by most filesystems currently maintained. It's a simple signal that the filesystem uses to tell the drive that the content of a sector isn't important anymore. As soon as all sectors mapped on a cell are free, the SSD controller unmaps the cell and schedules it for erasure. If the host read those sectors, the SSD wouldn't bother fetching from Flash, it immediately responds with zeros; but the most important effect is to keep the list of preerased cells always replenished.

Still, most SSDs expose a smaller capacity than the physical size of the Flash memory, sometimes as low as 75%. That allows it to keep some unused cells even on a 100% full system, so that (over)writing used sectors is still fast.


TRIM was introduced so an Operating System (the File System within the OS) could communicate to an ATA storage medium that a sector is no longer being used by the file system. This has nothing to do with writing to the disk.

TRIM does not guarantee the sector is zeroed on the media. It does guarantee when the file system requests a read from that sector that zeroes are returned (note that because the SSD knows the sector should be zeroes that it will return them regardless of what is actually stored in the media; it may be possible to recover data from a disk that has simple been trimmed, though typically SSDs actually do erase the memory).

File systems do tend to distribute their writes (for a variety of reasons, every thing from attempting write leveling, to garbage collection, to randomizing storage locations, and more). Because of this, if the media is unaware of which sectors the file system is not using, simply writing zeroes does not necessarily mean the sector is unused, then it must assume eventually that the whole disk is in use.

For SSDs this assumption means that a sector must be erased at write time, decreasing write speed; instead of erasing the memory location at the time the file is deleted. Similary for virtual disk files in virtualization systems, the dynamic disk file will eventually encompass the full capacity of the virtual disk. If the virtualization system implements TRIM then it will know when a sector is no longer being used, and hence that the dynamic disk does not need to keep track of that location.