The detailed analysis of SSD Trim
Solid-state disk is called as SSD. Compared with traditional mechanical disk--HDD, there is not much difference in usage, except for different storage media (NAND Flash). There is still an industry standard for its new functions.
The standard of hard disk has a long history of revolution. Taking SATA hard disk as an example, it is loaded with ATA command set. SAS hard disk, which is commonly used in enterprises, is loaded with SCSI command set. SSD hard disk, the new popular product, is equipped with NVMe command set.
1:History
At the end of 2007, different commands began to be used to distinguish SSD from HDD, and command standard of Trim was made in the ATA8-ACS2(additional command set) standard. Trim is a separate command designed for SSD.
Afterwards, the Trim command is extended to Queued Trim in SATA 3.1 spec, and achieve the concurrent operation of multiple Trim and IO.
Because of SATA, Trim is broadly known by people. The equivalent commands are called UNMAP in SCSI, and are called Deallocate in NVMe. They refer to the same function.
The word "Trim" has a special meaning in the SSD domain. "Trim of Nand Flash" refers to various hidden parameter settings on Flash.
Data Set Management Command covers a series of administrative commands related to data types. However, the“series”is just Trim in ACS2, and the rest is not made now.
The NVMe protocol finally has more than one attribute, in addition to describing the LBA space is "Deallocate," there are other attributes, such as the description of the LBA interval latency, the prompt of read-write frequency, and so on.
With the Trim command, you also need upper-layer applications to use the command.
At the end of 2008, Trim was first supported in the Linux kernel version of 2.6.28. Subsequently, Windows 7 began to fully support the Trim function of SSD in October 2009, and Trim began to be widely known. While Mac OS maintained his pride, it began to support Trim until 10.6.8 in mid-2011, which only supported SSD of Apple(OEM), and expanded to third party SSD until 10.10.4.
2:Cause
Each "file" is a set of pointers, which point to the LBA space where the file content is stored actually. The file pointer is stored in the “directory”.
When you delete a file, you actually delete the file pointer, and the data is discarded. Then the space can be taken up by other files.
As shown in the figure, file 1 is deleted and file 3 replaces some of its space.
However, in the SSD environment, this operation of file system brings a lot of burden.
Those who are familiar with SSD are supposed to know that SSD needs garbage recycling. In LBA space, the data left by file 1 is not garbage, and it is still valid for SSD! Only when LBA is duplicated, the part of green covered by red in the figure above is the garbage data that is meaningful to SSD -- LBA has a new value, and the old one can be recycled.
Although you can see that SSD is not at full condition in the system manager, the file data that has been deleted by the file system will still be handled by garbage recycle bin, which causes lot of unnecessary write amplification (WA).
To solve this problem, the Trim command comes into being.
3:significance
The Trim command is used to tell SSD that "the data for a certain section of LBA is no longer useful to me, and just handle it." The implication is: "it's best if you don't move it around and just throw it away."
Simply put, the function of Trim is to tell SSD what is deleted after the Host deleted files, so you can release the storage space to wait for the next write operation. If there are no Trim instructions of Trim, SSD won’t know the data is invalid, and it has to migrate data when doing data arrangement, thus reducing the speed and shortening the life of the NAND Flash wipe. The Trim function greatly improve the usage efficiency of the SSD and user experience in the system, and the operating systems above Microsoft Windows 8 provide a better environment for TLC SSD applications.