Some time ago to do some of the SSD optimization work, SSD's biggest problem is that after a long time use, IO performance will drop dramatically. The main problem is that in order to prevent the "write amplification" problem, SSD firmware uses a similar log algorithm, when the storage resources are basically depleted, in each write operation firmware can only do garbage collection (garbage collection, GC) operations, This introduces a lot of time-consuming operations, such as the erasure of NAND flash blocks, which results in a sharp drop in IO performance.
To alleviate this problem, it is thought that the garbage collection operation can be advanced, can not wait until the resource exhausted time to do, so as to some extent to avoid the sharp decline in IO performance. However, in any case, resource recycling affects the system's IO performance, and by introducing the trim command, this effect can be discretized, averaging, and very good results.
The trim command is a new command added to the SCSI layer, so the SCSI middle level supports this command, and the firmware of the SSD responds to the command. On the surface, this is just a garbage collection command, but it affects all aspects of the storage-system IO path, and the following is an analysis of the trim command's impact on the IO path:
1, garbage collection is the behavior of the application layer, which cannot be triggered at the block device or SCSI level, but only at the data application layer (usually the file system), and if triggered at the bottom, the upper application will see the wrong data, which is dangerous. Therefore, in order to support the trim command, the file system needs to be modified, for example, EXT3 need to determine which blocks of data can be freed? and need to know when to release? Because the trim command will have an impact on IO performance, the file system should try not to invoke the trim command frequently. In this case, the application layer such as file system is the trigger of the trim command, it is familiar with the behavior of the application, can trigger the SSD Resource Reclaim command at the right time.
2, the IO schedule layer needs to be modified. The traditional IO schedule layer only focuses on read and write requests, and the trim command is a special bio, and if the trim command is treated as a traditional request, there will be a lot of unnecessary trouble, such as the bio of the trim command, which may not be assigned a page. Many of the traditional drivers will be panic. To achieve compatibility, the trim bio and the normal read/write bio cannot be merged at the IO Schedule layer, and the trim command should be filtered out.
3, there are many problems with the soft Raid,trim command, which will cause the raid to work abnormally and the data correctness is problematic. When raid lowercase, RAID needs to get the entire stripe data from the disk. If a local block of data in one stripe in a raid is reclaimed, the data returned by SSD will be different from the original data, and the checksum of the raid stripe will fail, and raid will not recover the data correctly in the event of a system failure. As a result, the trim command will cause soft raid in Linux to not take a local strip write operation, but only in a whole strip of writing.
4, what data will the SSD return for the block after the trim? Different SSD vendors may adopt different strategies. Because SSD firmware receives the trim command, it does not necessarily immediately perform the trim operation, because if a small block of data is released, it can be aggregated until it is aggregated into a NAND flash block before it is really released, or it will introduce data migration issues. Based on the above considerations, access to a block after the trim, the return of what data will be related to the design, I think the simplest is to return the original data or 0, and there is a certain randomness, and access to the data block properties related. The randomness of this return data will affect the data correctness of the IO path and require attention.
In this list of some of the trim command considerations, Linux Open Source community is also doing this development, we can discuss together, speak freely!
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/database/storage/