Breaking News
Home » SSD Guides » Beginners Guide » Garbage Collection and TRIM in SSDs Explained – An SSD Primer

Garbage Collection and TRIM in SSDs Explained – An SSD Primer

‘Garbage Collection in SSDs’ is a contributed article that was submitted by LSI and authored by Kent Smith, Senior Director of Product Marketing, Flash Components Division, LSI Corporation. It’s importance cannot be understated for anyone venturing into today’s world of SSDs.

Garbage collection (GC) is a fundamental process with all solid state drives (SSDs), but it can be implemented in different ways that can impact the overall SSD performance and endurance. In this article, we’ll look at how GC works, how it can be implemented, and how it relates to the TRIM command and over provisioning.

Unlike hard disk drives (HDDs), NAND flash memory cannot overwrite existing data  they must first erase old data before writing new data to the same location. With SSDs, GC is the name for the process of relocating existing data to new locations and allowing the surrounding invalid data to be erased. Flash memory is divided into blocks, which is further divided in pages. Data can be written directly into an empty page, but only whole blocks can be erased. Therefore, to reclaim the space taken up by invalid data, all the valid data from one block must be first copied and written into the empty pages of a new block. Only then can the invalid data in the original block be erased, making it ready for new valid data to be written.

The process is illustrated in Figure 1. Column one shows pages A-D are written to block X. Sometime later that data is changed, so pages A-D are written and the original pages A-D are marked invalid (shown in column two). At the same time, additional data is written to pages E-H. Column two shows these changes and now block X is full, but is holding space for now invalid data (A-D) which cannot be reclaimed until the whole block is erased.

To achieve this objective, the valid data in block X must be moved to a new block so that the original block can be erased to start over. Column three shows the data from pages A-D as well as E-H being written to a new block (Y), so the space from block X can be reclaimed by erasing it. The writes from this step are not from the host system and are the source for increased write amplification in an SSD, meaning the flash in the SSD is being written more than what came from the host originally. Since flash memory has a limited number of erase and write cycles this operation should be minimized when possible, but it is still a necessary part of an SSD’s operation.

Figure 1: The garbage collection process.     Source: Wikipedia

Note that wear leveling typically occurs during GC, as data is written to a variety of new blocks in order to spread wear around over the breadth of the SSD. Since there are a limited number of writes the flash can sustain over its lifetime, if data was always written to the same block, its life of write cycles would be exhausted prematurely compared to all other blocks. This continued early block retirement would eventually reduce the available capacity of the drive and prevent it from performing at its full capability. Ideally, all of the blocks of the SSD need to be worn at the same rate throughout the life of the drive.


 In an HDD system, the Operating System (OS) can simply request that new data be written to the same location where the older, now invalid data, is stored, and the HDD will directly overwrite the old data. In an SSD, however, the page must first be erased before it can be written to locations previously holding data the SSD cannot directly overwrite existing data as stated earlier.

 The OS understands the files, their structure, and the logical locations where they are stored, but does not understand the physical storage structure of the storage device. In any storage system, the storage device doesn’t know the file structure it simply knows that there are bytes of data written in specific sectors. The storage system, whether SSD or HDD, returns the data from physical locations when the OS asks for data in the corresponding logical locations.

 When the OS deletes the file, it simply marks the space used for that data as free in its logical data table. With HDDs, the OS does not need to tell the storage device anything about the deletion because it would simply write something new into that same physical location in the future. In the case of an SSD, it only becomes aware that the data is deleted (or invalid) when the OS tries to write to that location again. At that time the SSD marks the old data as invalid and it writes the new data to a new physical location. It may also perform GC at that same time, but that varies between SSD architectures and other conditions at that moment.

About Les Tokar

is a technology nut and Founder of The SSD Review. His early work includes the first consumer SSD review along with MS Vista, Win 7 and SSD Optimization Guides. Les is fortunate to, not only evaluate and provide opinion on consumer and enterprise solid state storage but also, travel the world in search of new technologies and great friendships.Google+

Check Also

SanDisk Ultra II 240GB-Main

Black Friday SSD Sales 2015 – SanDisk Ultra II @ $0.21/GB and More!

Black Friday is finally here and deals are a plenty! Of course, we at The …

  • Paulalcorn

    wow what a great resource, excellent work Kent, and thanks for contributing!

    • Kent Smith

      Can I say thank you 2 years after the fact? :-)

  • Doug Crowthers

    Great article Les… I have added it to my running thread of “Useful SSD Articles” over at Tom’s Hardware (which included the other four SSD Primers).

  • The Muss

    .. That was useful. Thanks

  • Crunch

    While I agree that it is a good and informative article, let’s remember that this is written by someone who is biased and is not completely impartial. Kent works for LSI, which makes SandForce controllers, which are the controllers (the only controllers) that use DuraWrite technology.

    He tells us how TRIM works in great detail, but offers next to nothing about when and how DuraWrite optimizes an SSD. This is probably because he cannot or will not let anyone in on the technical aspects of DuraWrite, his company’s proprietary technology.

    • Kent Smith

      I certainly would not want people to think that my TRIM explanation has any bias, so I will be as transparent as I can here. I think you do agree that the TRIM details here are pretty clear and I should reiterate that the explanation of its operation is orthogonal to DuraWrite data reduction technology.

      If you want more information on DuraWrite, I do mention it in at least six of my blog posts and a few of them get into some details explaining how TRIM and DuraWrite will both help the performance of an SSD.

  • Miggins

    Les, I have an Intel 520/240GB and it frequently dumps about 20 x 1024KB “Intel_Trim_File” files in my SSD root directory. Do you know what these are and why they are there and SHOULD they be there? Thanks

    • Les@TheSSDReview

      I don’t know where these are and it is definitely odd. My suggestion is to hit our Forums and get the experts there to assist you with this!

  • Jud

    i have a force sata3 120gb ssd.. i’m running windows 7…

    in windows 8 setup there appears no recognition of my ssd so that it appears i cannot install windows 8 there… why is that… windows explorer sees it… i can write to it and delete files … why can’t i install windows 8 there…?

  • azpan47

    Les, very informative article, thanks.

    “Step3: OS writes new file E to old location and SSD marks old LBA as GC and file E gets written elsewhere.” When the OS tries to read the file E, obviously the SSD returns data from this new location – but how does it keep track of this?

    Also can you explain how overwriting a file works? Does the SSD do the same as step 3 and write the file elsewhere or does it move the block and rewrite it (essentially gc on the fly for that block?)

    • Kent Smith

      All NAND Flash-based SSDs have a flash translation layer that is a map showing all the locations known to the operating system and where in the flash pages they are mapped. This map is stored on the over provisioning space of the SSD and loaded into the controller when it needs to determine where data should be read or written.

  • gsuburban

    This explains much more than I was aware of in the past. Bottom line though is about the same as I recalled from the past, a clean windows install is best. Migration will not perform the same and for a few reasons such as TRIM as one example. Another is disc defragmentation. A clean install does not install windows disc defrag while a migration or image will install windows defrag as the image came from a HDD. Best to start fresh and allow windows, windows 7 or 8 that is, to configure it’s system install for SSD applications.

    I read an article not long ago that suggested Windows 7 and 8 doesn’t support trim. This was from an OCZ SSD review and it stated Microsoft confirmed this so, more elaboration on TRIM and what enables it is likely something that should be written.

    • Kent Smith

      Windows 7 and 8 fully support TRIM. If you post the link to the article that made you think otherwise we can review it and comment.

      • gsuburban

        Since my research, I noticed OCZ is Chapter 11. No longer interested in them so Corsair will be the focus. I was unable to locate the articles I read as my history is gone after 90 days. I can say though, many of the SSD makers have these videos suggesting folks can take an existing HDD system and migrate/transfer that OS onto a new SSD. I read that may not survive or be the best solution for TRIM and many other things. Maybe that’s not accurate as well. We’ll see as my next build is in about 2 weeks.

      • Kent Smith

        Older OSes like XP used a different partition alignment than the more recent Windows 7 and 8. So if you migrate to Windows 7 or 8 I have not seen any problems with alignment any more.

        If an OS is installed on an HDD, then it is defaulted to have TRIM off, but you can reconfigure the OS to turn TRIM on for that new drive once you get is set up. I will say that generally it is better to do a fresh install of the OS on an SSD, but I have personally used a transferred OS from HDD to the SSD and had no problems or issues. The benefit from the SSD is so much above the HDD it is hard to tell the difference from any other possible issue if something is not perfectly configured.

        Let us know how your build goes.

  • 48hours

    The explanation for Fig. 1 is confusing. It needs to be stated that the saving a modified file effectively has OS telling the SSD that the Pages A-B in Block X are invalid.

    • Les@TheSSDReview

      I guess I am a bit confused because that exact statement is present below the center of the three images???

      • 48hours

        The caption says that Page A-D are invalid. The way it is written, there is really no difference between having TRIM or no TRIM. I assume this case is with no TRIM. In this case, when does the OS tell the SSD that data in Pages A-D are no longer valid? Basically, the same caption could be used to explain the case with TRIM.

      • Kent Smith

        The point that A-D being replaced by A’-D’ does not require TRIM is true for that case. That diagram is for the description of garbage collection, not TRIM. The operation of TRIM is covered in Figures 2 and 3. TRIM is required with the OS or user erase a file, but do not replace it directly. In other words, if I edit a file and save a new replacement over the old version, the OS will tell the SSD the new file should be kept instead of the old one.

        In the case of a simple file delete, the OS or user have no direct replacement for that file, but just don’t need it any more. Without TRIM the file will appear valid to the SSD controller until the OS uses those same sectors or pages for a new file. Only then would the SSD controller know the old data is no longer required.

        With TRIM the OS has a way to tell the SSD controller that the file locations can be freed up and no longer tracked during garbage collection.

  • 48hours

    the most right column in Figure 3 is misleading. the new file E is written, but the author moved the location of file D to the empty space and then put the file E in place of file D….this article has many areas that are not quite accurate.

    • Zappa

      I may have not understood it by I think the same on that drawing. I looked at it several times because I think it doesn’t fit completely the explanation.

      • Kent Smith

        Zappa, let me know if my answer to 48hours helps your understanding. If not I am happy to reply further.

      • Zappa

        Thank you, Kent.
        My problem is with SSD Logical View and Physical View, but I just noticed I read this without reading page 1, so if after reading it I don’t get why I don’t see file C being moved both with and without TRIM, I’ll tell in case it’s useful for somebody.
        5AM here :s

    • Kent Smith

      Thanks to Zappa, I was alerted to this question from 48hours that I missed when first posted. I believe the comment is about the “OS Logical View” at the top of the diagram. The physical order or layout of that view is irrelevant to the SSD controller and the explanation of where the data is getting stored.

      As for the other comment that indicates there are other concerns for accuracy, I would love to hear them.

  • mark

    btrfs on Linux does support both RAID and TRIM.

  • E71

    Currently using 4 x Samsung 840 Pro 256GB in RAID 5 with 3ware 9750-8i.

    Was impressively fast over a year ago when I set it up and now things get sluggish at random intervals.

    Haven’t used more than 414GB of 712GB, system’s on 24/7 running Windows 8.

    Buyer’s remorse starting to kick in… yeah, this late. All the while there’s no news on TRIM or alternatives on hardware RAID cards… Disappointing.

    • Zappa

      That raises a question to me.
      Does Over-Provisioning unallocated space provide an advantage to formatted free space? I imagine it does because it is all unallocated so free to use, but formatted free space depends on the GC marks?
      May E71 have not enough unallocated space for over-provisioning? (many say around 20-25%; if you need some of that space you can take it whenever you want).

      And my most haunting question:
      Does really TRIM function less efficiently if you shrink a partition to create unallocated space for Over-Provisioning? Some say it won’t ever work as well as installing Win 7 on a SSD with 20-25% of unallocated space.

      • Kent Smith

        Formatting or unformatted space has no affect on its operation as over-provisioning area. Free space is considered available to the user, so it cannot be part of the native over-provisioning. However, any unused user space that has been TRIM’d is available to the controller as what we call “dynamic over-provisioning.” More over-provisioning will improve any SSD controller.

    • Zappa

      In case something helps (you probably know much better than me but…):
      – Could you notice SSD degradation taking a look at SMART indicators (with Samsung Magician, for example).
      – Did you optimized everything? (except using RAPID tech, which may be trouble and probably is not worth it). Magician simplifies many passes of the optimization guide.
      – Did you remember to reserve 20% of unallocated space for over-provisioning? I think the 840 comes with only 7Gb of “over-provisioning” space by default. Maybe the dynamic over-provisioning is not enough.

      BTW, just slightly related, I read the 500Gb Samsung SSDs are faster when it comes to long data transfers because they have enough NANDs.

  • amerist

    Thank you for that explanation. I feel better about putting the Cindori TRIM Enabler on my wife’s MacBook Air SSD upgraded to a Transcend JetDrive.

    • Benjamin Hojnik

      Wait, you upgraded your wife macbook with a flash drive ??!

      • amerist

        No. SSD not flash. It was a 240GB JetDrive 500 SATA III Internal SSD model TRJD50024010. No problems with the upgrade or the part. Runs like new.

      • Benjamin Hojnik

        Oh, i was not aware that transcend uses jet branding for their apple ssds.


  • Agnostic185

    Thanks for the excellent primer on TRIM Les. If you wouldn’t mind providing input to the following question – it appears the SSD is responsible for translating logical to physical pages – lets assume I made a backup image of the SSD – on catastrophic SSD failure is my ability to restore using my backup image lost – or does the backup image include the SSD’s logical to physical translation?