View All R&D Articles

Garbage Collection On An SSD: A Simple Explanation

October 1, 2019

A solid-state drive.

Garbage collection is a process used by solid-state drives (SSDs) to optimize space, improve efficiency, and keep your device working as efficiently as possible. It’s also a common source of confusion for personal computer users — and the name “garbage collection” has something to do with that.

To understand garbage collection, we need to know a bit about how solid-state drives work (and what goes wrong when they stop functioning as expected). We’re presenting this in the simplest possible way, but if you’re interested in a more complex and detailed explanation, check out ExtremeTech’s excellent piece on the subject.

The Big Difference Between Solid-State Drives and Hard Drives

Hard drives and solid-state drives both store data in a binary format, but that’s about where the similarities end. Hard drives use platters coated with a thin layer of magnetic material to store information; read/write heads move over the platters to access data. 

Solid-state drives don’t have moving parts (hence their name). They store data with floating gate transistors. If the floating gate is charged, it reads as a “0,” and if it isn’t charged, it reads as a “1.” Because the drive doesn’t have to move physical read/write heads to access data, an SSD is much, much, much faster than a standard hard drive.

There is, of course, a downside. SSDs read and write data as pages, but they erase data at a much larger block level. Blocks are usually made up of hundreds of pages.

So, why not erase at the page level? On an SSD, erasing data requires a relatively large amount of voltage. While SSDs can write new data quickly, they take much longer to overwrite data, since they need to copy the entire block to another place, erase the original block, then write the contents of the old block along with the new pages. 

Those little floating gate transistors also wear out over time. Eventually, they can’t be trusted to hold a charge, so ideally, your SSD should organize its memory in a way that prevents certain blocks from wearing faster than other blocks. 

How does this relate to garbage collection? Trust us, we’re getting there.

Garbage Collection Helps SSDs Maintain Fast Read/Write Speeds

The goal of garbage collection is to keep as many empty blocks as possible, so that when the SSD needs to write data, it can do so without waiting for a block to be erased.

The SSD’s controller looks for any pages that are no longer useful — pages that the operating system has marked as unnecessary (deleted data, modified data, and the like). It then moves useful pages to new blocks, leaving behind the old, unnecessary pages. The controller then erases the block so that it’s ready for use.

This is a background process, handled by the SSD controller and the operating system. Most newer SSDs also have TRIM, an ATA command that the operating system controls, but we’ll save a detailed explanation of TRIM for another blog. The takeaway is that high-quality SSDs have measures in place to prevent slowdown, even after long periods of consistent use. Garbage collection algorithms are relatively complex, and they’re not perfect, as they sometimes mistake bad data for good data, but they’re necessary for ensuring performance.

In contrast, when you delete a file from a hard drive, the hard drive (usually) just marks the space occupied by the file as “available.” The HDD will eventually overwrite that data, when it gets around to the task, but because overwriting data isn’t any more difficult than writing data, the HDD doesn’t need to worry about garbage collection.

Does Garbage Collection Cause Data Loss?

Garbage collection actually helps to make solid-state drives more reliable. However, it is an intensive process, and as an SSD gets used, it will always become less and less reliable as more floating gates lose their ability to hold charges. 

There’s a myth that SSDs are inherently better than hard drives for all tasks, and that they’re much less prone to failure. While SSDs may resist some types of physical damage better than hard drives — HDDs, after all, have moving components — they can still lose data, and no current data technology is absolutely perfect. Don’t worry about garbage collection breaking your SSD, but don’t trust your SSD with the only copies of your important files. Back up every important device, regardless of how much you trust your media.

If you’ve suffered data loss due to an SSD failure, contact at 1-800-237-4200 to discuss your options.