Free 2-Day Delivery!

Garbage Collection and TRIM: Definitions and Explanations

Garbage Collection:

When a file is deleted from a drive, the OS does not delete the actual data blocks from the drive. This is not an issue with hard disk drives, which simply overwrite the unneeded data blocks as needed. However, SSDs must erase the unneeded data blocks before new data can be written. Garbage Collection is a feature of the SSD controller. It works in the background to identify and clear unneeded data blocks. The downside is it increases the write cycles and uses controller processing power, which can reduce performance (slightly) and lifespan (slightly).

TRIM:

TRIM is a command issued by the OS to tell the SSD which data can be overwritten. This helps improve write performance and longevity. In a nutshell, when you delete a file on the SSD, the OS sends a TRIM command to the SSD controller telling it which blocks can be deleted. This reduces controller use and write cycles, which can improve write performance and lifespan.

Over-Provisioning:

Many SSDs implement over-provisioning, which provides a buffer for controller data management. This provides space for the SSD controller to temporarily place un-needed blocks. For example, a drive that is 480GB instead of 512GB uses that extra 32GB as the buffer for over-provisioning. When an SSD uses over-provisioning, TRIM is generally not necessary. If an SSD does not use over-provisioning, we recommend leaving at least 15% of available space on the SSD to allow for proper data management.

How it all works:

Due to the way NAND flash memory handles the distribution of data (think of it as its inventory management system), solid state drives need to implement clever processes in which to discard unwanted data. This is done in order to keep the SSD performing as efficiently as possible.

Solid state drives store data in units called "blocks" and "pages". Pages are stored inside of blocks. However, data can only be read/written at the page level. Data can only be erased at the block level.

Therefore, when a page of data is altered, it is stored as a new page in a new location. The old page is marked as "stale". The "garbage collection" assesses the blocks and identifies which pages are "good". Those pages will copied to new blocks. The original blocks they were taken from are completely erased.

What's left are blocks full of "good" and empty pages as well empty blocks with plenty of fresh pages ready to be written to. Mission accomplished: the "good" data was kept and piled together, and the "garbage" was discarded permanently. This self-regulating process helps the SSD maintain consistent performance and capacity over its lifetime.

Problems can still arise, however, because there is a bit of a disconnect between the SSD and the operating system.

When a set of data is "deleted" via the operating system, it isn't actually deleted from the hard drive. The operating system marks that data as "overwrite-able". The SSD does not see the operating system's file system, however, and as far as it is concerned the data is perfectly valid and not stale. The data contained in these pages sits in hard drive purgatory, as the OS can not overwrite it and the SSD does not see it as garbage and can't discard it. This is not ideal for obvious reasons.

This is why TRIM process was created. It is an ATA command that acts as a mediator between the operating system and SSD. It relays the message that a set of information is being deleted by the operating system, and the SSD will then mark the corresponding page(s) as stale. The SSDs "garbage collection" process can then discard these pages containing deleted files.

ssd-trim

Simply put, garbage collecting and TRIM allow for the most effective use and effient performance of SSDs over their lifespan.

Additional resources:

http://arstechnica.com/gadgets/2015/04/ask-ars-my-ssd-does-garbage-collection-so-i-dont-need-trim-right/

http://arstechnica.com/information-technology/2012/06/inside-the-ssd-revolution-how-solid-state-disks-really-work/3/

http://www.seagate.com/tech-insights/ssd-over-provisioning-benefits-master-ti/

Back to Blog Home