Share on facebook
Share on twitter
Share on linkedin

What’s the TRIM for an SSD? How is it working?

What’s the TRIM?

The Trim Instrument, also known as disabling delete notify, is a technology developed by Microsoft in conjunction with major SSD vendors. It belongs to the ata8-acs2 specification. It was officially issued at the 2008 conference and was added to Windows 7.Win 7 finds SSDs in the system and makes targeted adjustments and optimizations, such as disabling disk defragmentation, ReadyBoost (flash acceleration), and SuperFetch (super prefetching).

What’s the purpose of Trim?

For traditional mechanical hard drives, when deleting a file on the disk under Windows, the system will only mark the track on which the file is located, marking the track as having no data record, rather than “deleting” in the real sense. The next time the write operation is performed on the track, the system will empty the original data on the track before writing, which is less efficient (the advantage is that data recovery is possible).

On Windows7 systems, this process becomes much easier after launching the Trim command on SSD that supports the Trim instruction. At this time, in the data deletion operation of SSD, the NTFS file system does not send delete instructions to SSD, and the solid-state disk issues new Trim operation instructions, telling it that the relevant pages can be safely erased. After receiving this instruction, the SSDs are not in a hurry to perform the erase operation but wait until there is a write operation again because the relevant area can be reused, so it does not take time to erase the original data. Its speed is much faster than directly reading and writing the hard disk to mark the deleted area, which not only improves the reading and writing efficiency but also greatly reduces the loss of the solid-state hard disk.

In Windows 7, Trim command requests are not limited to delete operations, but are also fully integrated with partition and volume level commands, file system commands, and system restore functions.

How to turn on/off the TRIM?

In fact, Windows 7 default Trim instruction is on, if you want to query the current Trim instruction status, we can go to the command prompt interface under administrator authority, enter “fsutil behavior QUERY DisableDeleteNotify”, and then get feedback on the relevant query status. Here, the prompt is “DisableDeleteNotify = 0”, that is, the Trim directive is enabled; the prompt is “DisableDeleteNotify = 1”, which means that the Trim directive is not enabled.

It is not the operating system that provides Trim instruction support, all SSD can enjoy the benefits of Trim technology, which also requires solid-state firmware support to achieve. Basically, the popular solid-state disk master chip manufacturers have provided firmware that supports Trim, but some manufacturers have developed garbage collection technology that does not rely on the operating system. By collecting flash memory blocks that are no longer in use and adding a load balancing algorithm, it can prevent the speed of solid-state disk from falling after long-term use, and prolong the service life of flash memory. The process is completed completely in the solid-state disk.

P.S.: Technical details

Mechanical hard drives can directly overwrite old areas, but it doesn’t work when it comes to NAND flash memory. When all the flash memory is full, there are no free (never written) blocks to use, and the speed slows down.

In solid-state flash memory, data storage is generally stored in page (page) as the smallest unit (typically 4KB), while 128page form a Block (block). Data can be read and written in 4KB-sized pages, but can only be deleted in 512KB (128page) block size. SSDs are fast when reading data or writing to an unused page, but overwriting data is more complex and requires many steps to complete.

When all the free blocks of the SSD are used, there is a write operation, and it can only overwrite data to areas that were previously marked as deleted by the operating system. This is also the beginning of the speed decline.

To overwrite the file system of a 4KB page, first, copy the entire 512KB block into the cache. Then, delete the 4KB page from the cache and replace it with the new data. Next, empty the entire 512KB area of the flash memory and write the new data back from the cache. If you need to overwrite a lot of blocks at the same time, “for example, a series of random write operations for small files or simply writing a large file to SSD”. You will make your SSD cache overload quickly, and then your write speed will drop significantly, and the early SSD with a small cache will even delay by nearly 1 second, so SSD manufacturers began to add large external cache on the main controller, which to some extent solved the problem of slow random writes, but could not solve the problem of the slow speed of SSD overwrites.

What exactly did the Trim command do?

In short, this problem is caused by the fact that the operating system and the file system cannot communicate with the master of SSD to delete files. If there is data that has not been cleaned before, all written pages have to clear the block before rewriting, which will seriously affect the writing speed.
There are two ways to fix this problem:

  1. The first is to run the garbage collector (GC) (on a regular basis, which is a bit like sorting. When SSD is idle, all valid pages are scanned and merged into a block containing all valid pages, while those invalid pages and blocks will be completely cleared.
  2. The second and better way is to let the system tell SSD that the data is gone when the data is deleted, and let SSD erase the blocks occupied by the data immediately, which is what the Trim command does.

When a file is deleted in a system that supports Trim, the operating system sends a command to SSD, to let him know that the page in which the data is located can be written directly, which is tantamount to changing control from the operating system to the SSD host controller firmware. SSD will also copy the whole block containing deleted data to the cache, empty the block and write valid data back to the page. The difference is that the delay time is advanced from the time when the data is overwritten to the time when the data is deleted. (at this time, you are not sensitive to speed. If you delete a large piece of data, you can watch the hard disk light flash wildly within a few seconds after you delete it.). Naturally, the speed of SSD will come back, because you have empty blocks available when you write. SSD, which is controlled by barefoot, has a program called Wiper, which scans all the pages that have been deleted in the past (like Trim, manually), making SSD look like a new one. In fact, the program makes a valid data backup before erasing all deleted data. Because the unique algorithm of the program corresponds to the master control, the master of other countries does not support it, because it is not a real Trim command (not a command issued by the system), so it can support old systems such as XP.

So we can say that Trim’s real secret to keeping the pace from falling is to get rid of what needs to be done in advance. But this will have to be done sooner or later, so it will hardly affect the original number of writes (lifespan) of SSD.

For GC, because it is moving, sorting, merging old pages into new blocks, deleting invalid old blocks, it will sacrifice the number of writes (lifespan).
But there are advantages and disadvantages for GC to support RAID,.

Leave a Comment

Your email address will not be published. Required fields are marked *

Let's Have A Chat

Learn How We Served 100+ Global Device Brands with our Products & Get Free Sample!!!

Email Popup Background 2