How SSDs work

Solid-state drives have become one of the most sought-after PC upgrades. But how do they work?

Not only that, forcing electrons back and forth over the substrate causes the material to deteriorate. Eventually it deteriorates so much that the electrons do pretty much what they want to and the cell breaks down, no longer able to store a definable state.

For an SLC cell that takes around 100,000 programming/erasure cycles, but then again it only has to store two states. For an MLC cell, which stores four possible states, the rate of breakdown is much faster at about 10,000 cycles.

In reality, cells aren't programmed or erased singly. They are programmed (and read) in pages of 4KB and erased in blocks of typically 128 pages (or 512KB). Doing it like this simplifies the circuitry and the controller immensely, and file systems typically read and write in 4KB blocks anyway.

Given that erasing is more destructive to a cell than programming it, this means that erasing is done less often than programming. However, there's a catch. If you think about it, this discrepancy between programming and erasing means that a page is only writable once.

Writing a page will set some of the bits in that page to 0, and the only way to get them back to 1 again is to erase them. So, before you can write to a page again, you have to erase the whole block containing the page.

Actually, to be more specific, you have to read all the active pages in the block (except the one you want to overwrite), erase the block, and then write all the active pages back, followed by the new version of the page you wanted to write in the first place.

Figure 2

FIGURE 2: Diagram of how an SLC cell responds to increasing voltage. An MLC cell will have four peaks

As you can imagine, this read-erase-write process takes a long time compared to writing a page for the first time. In fact, it's comparable to writing to a traditional hard disk.

Overwriting data

So what happens when you want to overwrite a page with some new data? The answer is that the original page is marked as 'invalid' and the new version of the page's data is written in another page entirely (making sure the links to the data's position are updated). Want to update that data again? Mark the old page as invalid, write the data to a new empty page.

If you like, a page has three states: empty (it's erased), used (it contains data) and invalid (it used to contain data, but that data is now out of date and can be discarded the next time the block containing the page is erased).

You might think this is a ridiculous way of using storage efficiently, but consider it from this angle: a block can only be erased 10,000 times before it can no longer be used. It turns out that the benefits of using NAND flash (fast, tough, silent) outweigh the problem of only having 10,000 shots at using some memory.

Consider it from the level of the whole disk drive. Many people never fill up their drive. There's always plenty of room on it. An SSD controller can take advantage of that fact by writing to every page on the SSD before taking the drastic step of erasing a block.

This, incidentally, is the reason for the observations in the early days that a brand new SSD was always faster than an SSD that had been used for a while: the new drive had plenty of empty pages, and so writes happened at full speed. After a while, every page on the drive had been used, so some writes went through the read-erase-write cycle and slowed the overall speed of the drive drastically.

However, there is another wrinkle to the whole SSD story. A drive controller doesn't know anything about a file system - that's the operating system's job. The OS thinks of the drive as a linear array of pages, with the page indexes known as LBAs (logical block addresses). It then builds a hierarchical file system over that array by having files as a sequence of pages (for example, LBA 17, followed by 42, then 167, then 23) and folders as special files that contain an array of 'file entries', with each entry containing a file name and the starting LBA.

The SSD controller is in charge of maintaining the mapping between an LBA number and the actual page of flash memory in the SSD. It seems simple enough, except that when you delete a file, the OS just marks it as deleted in the file system. That's why file undelete tools work - the file hasn't been physically deleted, the data is still on the drive. It's fast because no data gets written to the SSD.

If the file had just one flash page, that page wouldn't be marked as invalid. As far as the SSD is concerned, the page is still being used.

At some later time the OS will reuse a page that it knows has deleted data and write to it. At that point the SSD will do its usual work and mark the page as invalid and use another empty page.

This is where TRIM comes in. Solid state drive manufacturers recognized the problems of deleted files and having deleted pages hanging around. They came up with an API, known as TRIM, that allowed the OS to tell the drive that a file had been deleted and that such and such LBAs are now invalid and can be reused. The drive could then, at the time of the file delete operation, mark all affected pages as invalid and then perform a read-erase-rewrite operation on the blocks concerned.

Maybe not every time, but only if the proportion of invalid pages in the block reached a certain critical threshold. This would mean that file deletions would take longer, but this extra work would help during file write operations, which is where the user would prefer the speed.

Currently Windows 7 supports TRIM, whereas Mac OS X only does for certain Apple-badged drives.

Idle garbage collection

Another option that some SSDs support is known as idle garbage collection. In essence, what happens is that during moments of little to no drive activity, the controller goes through the blocks on the SSD and performs the read-erase-rewrite cycle on sufficiently 'dirty' ones (again, provided that the number of invalid pages in a block has reached some threshold value).

Since this happens during idle times, the SSD is, in essence, cleaning up the drive ready for those times that you really need lots of empty pages ready to use. It's believed that Apple MacBooks use this system in some form or other (apart from those that now support TRIM, of course).

As you've seen, SSDs are as fascinating as they are fast. By all means, get an SSD, but we would recommend making sure you're using Windows 7 first. That way, you know you're using the drive to its best advantage.

-------------------------------------------------------------------------------------------------------

First published in PC Plus Issue 308. Read PC Plus on PC, Mac and iPad

Liked this? Then read Best SSD: 12 top solid state drives reviewed

Sign up for TechRadar's free Week in Tech newsletter
Get the oddest tech stories of the week, plus the most popular news and reviews delivered straight to your inbox. Sign up at http://www.techradar.com/register

Follow TechRadar on Twitter * Find us on Facebook