In Computer!Total Issue 4/2010, we tested five SSDs with TRIM support. For the sake of simplicity, we assumed locations in the test as the place where an SSD can store data. Actually, so-called 'pages' and 'blocks' are used for this. In this article we take a closer look at how pages, blocks and their relationship with TRIM work.
TRIM is a command that ensures that an SSD maintains optimal write performance. The operation of TRIM can only really be understood if you know the structure of an SSD. An SSD stores information in 'pages', which are grouped in a 'block'. To understand these concepts, you should first consider the composition of the Multi Level Cell (MLC) SSDs as tested in Computer!Totaal 4/2010. An MLC SSD consists of billions of memory cells, each of which can store several bits. An ordered collection of these cells is called a page and is the smallest unit to store or read back a file in an SSD. A page usually has a size of 4 KB. So if you save a file of 1 KB, this file will take up 4 KB on the SSD.
A block is an important unit for an SSD, because it is the smallest collection of pages that an SSD must read in order to delete data. A block consists of 128 of these pages and has a size of 512 KB. Now an SSD works like x number of memory modules in a RAID setup. This means that a file is spread across multiple memory modules for maximum read speed. Windows 'talks' to the SSD via Logical Block Addressing (LBA), keeping track of which blocks are in use and which are available. Because an SSD works with pages, the SSD controller must translate the LBA commands. The Windows command to overwrite a file is translated by an SSD (if possible) to write to an empty page. If there are no empty pages, then pages must be emptied first.
Delay in writing
A problem occurs when there are not enough empty pages available to store a file, when there is more than enough space available according to the Windows index. After all, a file is never actually deleted when the command is given. This only happens when the space occupied by the file in question is overwritten by new data. A problem with this is that an SSD cannot directly overwrite pages containing parts of files that are no longer in use. An SSD must first read blocks and place them in its own cache, because data can only be deleted there. The cached pages are emptied and then the entire block of empty pages is restored to the SSD, after which these pages are available for new data. This slows down the writing process by a factor of three or more.
The savior for these situations is TRIM. This is a command that Window 7 sends to the SSD during a wipe. This command tells the SSD's controller which pages can actually be deleted and puts the SSD to work by reading blocks and emptying the pages that are filled with files (which Windows says may be overwritten). In this way, an SSD remains in optimal condition by having enough empty pages in stock and a write job can always be performed optimally. We'll show you step-by-step what happens when an SSD writes and deletes files and how TRIM ensures that there are always enough pages free.
1. Blank SSD
Imagine we have an SSD with a storage capacity of exactly 1 block. An empty block of 512 KB on the SSD consists of 128 empty pages of 4 KB.
2. Write file
We want to write a file of 12 KB, which fills 3 pages of 4 KB (blue).
3. Write another file
We then want to save another 8 KB file (purple). In total we have put 20 KB into use. So we still have 512 KB – 20 KB = 492 KB free, or 123 free pages.
4. Delete file
We are now going to delete the 8 KB file (purple). According to Windows, our SSD still has 512 KB - 12 KB = 500 KB available. However, our SSD still registers 123 empty pages and 2 pages of data that can be deleted.
5. Write file
We are now writing 4 KB (green). The two pages containing "data to delete" information are skipped by the SSD. First the empty pages are filled.
6. TRIM at work
With support for TRIM, Windows 7 sends the TRIM command along with a delete action. This way the controller of the SSD knows that this data can actually be deleted. When the SSD has nothing to do for a while, the SSD will move the complete block of 512 KB, part of which has been designated as delete by the TRIM command, to the cache memory. Here the file deleted by the TRIM command (purple) will actually be deleted.
7. Pages will be deleted
Now the 2 pages can be emptied and the whole block can be put back. You can probably imagine when you are going to delete a file of 10 MB, we have to delete a total of 2560 pages. If these are then also divided over different blocks, then a lot of data has to be read. Even though a block contains only 4 KB of the file, 512 KB must be read in to delete the 4 KB portion. TRIM ensures that this happens at times when you are not using the SSD.
8. Free space again
Now the 2 pages are ready to be written again.
9. Write file to free space
If a file of 12 KB is now saved, there are enough pages free to save the file (orange).