Garbage Collection and TRIM in SSDs Explained – An SSD Primer

THE TRIM COMMAND

In newer operating systems, e.g., Windows 7, Windows Server 2008 R2, Linux 2.6.33, FreeBSD 8.2, Open Solaris, Mac OS X Lion, the TRIM command enables the OS to notify the SSD that old data is no longer valid about the time it deletes the logical block addresses from its logical table. The advantage of the TRIM command is that it enables the SSD’s GC to skip the invalid data rather than moving it, thus saving time not rewriting the invalid data. This results in a reduction of the number of erase cycles on the flash memory and enables higher performance during writes. The SSD doesn’t need to immediately delete or garbage collect these locations it just marks them as no longer valid.

The difference is illustrated in Figures 2 and 3.

Figure 2: Garbage collection without the TRIM command.

 Figure 2 shows the process without the TRIM command in use. In column one of Figure 2, the SSD user writes four new files to the drive. The OS sees the files in its logical table, and the SSD has both a logical and physical view of the space available, which in the physical view includes over provisioning space that is not part of the drive’s stated’ capacity as known to the OS.

In column two, the user deletes file C, but the SSD does not know the file has been deleted because the TRIM command is not in use. If it does GC at this point, it will move the invalid data in file C because it doesn’t know it’s invalid. In column three, the user writes a new file E, the OS tells the SSD to use the same space it used from the old file C, and the SSD writes the new file to free space while marking the old space from file C as available for GC.

Figure 3: Garbage collection with the TRIM command.

Figure 3 shows the difference with the TRIM command. In this case, the process is the same when the user writes the four original files. When the user erases file C in column two, however, the old file C space is immediately marked as invalid in preparation for GC because the OS uses the TRIM command. The space originally holding file C is now free space to the SSD and becomes available as dynamic over provisioning meaning the SSD has more free space during GC which helps improve the overall SSD performance.

 In column three when the user finally writes file E, the total free space on the SSD is now the same as the drive without TRIM. The difference is that the SSD with TRIM support knows what data is invalid and it can be considered free space during GC and prevents having to move the invalid data to another block.

 This produces three key benefits:

  1. Lower write amplification. Less data is re-written and more free space is available during GC (more space to write equals fewer writes needed);
  2. Higher throughput. With the TRIM command, there is less data to move during GC and the drive runs faster. Throughput is bottlenecked at the flash an SSD is only as fast as it can write to the flash memory. During the time it is doing GC, the drive has to stop some of the data transfer from the host while it moves data around. This is why it’s beneficial for the SSD to know which data is invalid so it doesn’t have to be moved during GC.
  3. Improved endurance, because the drive is writing less to the flash by not rewriting invalid data.

 Note:  Today’s TRIM doesn’t work in most RAID environments because current RAID drivers generally don’t yet support it. Once more RAID manufacturers can make changes in their drivers, the hope is that TRIM will eventually work and benefit most RAID environments as well as non-RAID environments.

SSD QUICK SEARCH