Have you ever noticed that when you go into Windows to optimize your drives, it says retrim for SSD? What exactly is being cut off and why is it needed? Is it the same as defragmentation, or something completely different? (this is different).
All such good questions deserve detailed answers, so in this article we will look at all this.
What is SSD pruning?
SSD pruning is a process that helps maintain the performance of a solid—state drive over time. Pruning works by periodically erasing blocks of data that are no longer in use. Cropped data is not always deleted immediately, as a complex process decides when exactly this will happen. But when this happens, it not only frees up disk space, but also helps the SSD to work better and longer.
Simple, right? However, what is actually happening is a little more complicated — read on to find out!
Digging into the insides of your SSD
To understand why SSDs don’t delete files when you click a button, we need to take a quick look at how they work. We have already disassembled solid-state drives before, and you will see that there is not so much inside them.
The sample below refers to a relatively old SATA model (Samsung 850 Pro), but even the latest solid-state drives do not differ much in terms of the components that make up the disk.
The chip in the middle is the processor that manages all instructions, data flow, encryption and other algorithms. Above it is a small amount of DRAM, which acts as a cache of instructions and data, and also stores a table of data locations on disk.
To the right and below the processor are two NAND flash memory modules – these are the chips in which all the data is stored, and it is in them that we need to understand.
Deep inside these chips are billions of tiny components called floating-gate and floating-gate semiconductor field-effect transistors. Since this name does not quite fly off the tongue, this technology is usually called charge-trapped flash memory (CTF), and it is the most commonly used system for storing data in modern solid-state drives.
Each CTF acts as a separate storage unit, known as a memory or bit cell, to which three electrical tracks are connected. CTFs are grouped together, first as a long column (row) containing 32 to 128 cells.
Cells in a row have a common trace (bit string), which is used to read the data stored in them. Those that are on the same line with each other (known as a page) are all connected to another common track (a string of words). The row and base selection strings are used in conjunction with the word strings to determine whether the process of reading, writing, or erasing is taking place.
An array of rows and pages forms a so-called block. The sizes of pages and blocks vary greatly: the first have a size of only 4 KB, and the second — 512 KB, although much depends on the manufacturer and model.
One NAND flash memory crystal will consist of thousands of blocks, and the flash memory modules themselves may contain several crystals. These vast, complex networks of tracks and transistors make up every flash memory device, from multi-dollar USB drives to enterprise-grade multi-terabyte solid-state drives.
NAND flash memory is weird
Pages and blocks are important because all memory cells in this structure have the same substrate — a piece of semiconductor material, such as silicon or gallium arsenide, on which all transistors are built.
To erase data from any cell, it is necessary to use a high negative voltage, causing any electrons stored in the KTP to flow into the substrate. Unfortunately, this means that the erase process clears every cell in the block, not just one of them.
Another oddity of NAND flash memory is that memory cells cannot be programmed with new data until all cells are cleared. In other words, solid-state drives never write new data directly on top of old ones, as traditional hard drives do. And where erasure should be performed at the block level, writing to them is performed at the page level, which means that SSD programming is much faster than erasure.
The process of programming and erasing also damages memory cells every time, wearing out the layer inside the transistor that stores the charge. To increase the service life of the chips, the processor controlling them cycles through all the blocks until each of them is used once before returning to the beginning (so to speak).
So yes, NAND flash memory is definitely weird – writes fast, erases slowly, damages itself when performing any operation!
To scatter garbage
Now let’s get back to understanding what SSD pruning is. To do this, take an imaginary SSD with pages of 4 KB and blocks of 256 KB, that is, 64 pages per block. What happens if you want to delete a single file that takes up 3056 KB on your SSD?
This file will take up 764 pages — 11 complete blocks and one with 60 of the 64 pages used. How can we delete this file without risking affecting the last 4 pages, as they may contain data for another file? It seems we are completely stuck!
Salvation initially comes in the form of the TRIM command. All data remains on the drive until an explicit instruction is received to do something about it. Files and folders that have been deleted by the operating system are marked as unnecessary, and when executing the TRIM command, the table stored in the SSD DRAM (or in the NAND flash memory itself, if there is no DRAM on the disk). ) is then updated to reflect this.
Note that not all solid state drive manufacturers use the term TRIM, but Windows uses it, so we’ll stick with that term. The data is not erased immediately after sending the TRIM command — this happens either when the disk is idle, or when it writes some data to the block next time. Which method to use depends on the manufacturer: consumer-level models handle the erasure in standby mode, while enterprise-level models usually do this when writing.
The data marked for deletion is erased when the NAND flash firmware starts a process called garbage collection. This involves reading a block, and any pages that need to be saved are copied to the cache, and then written to a completely empty block. Then the previous page, along with the pages marked for deletion, is erased.
In some ways, this process for solid-state drives is the same as disk defragmentation for traditional hard drives, but it’s not the same thing.
Is cropping the same as defragmentation?
SSD pruning and defragmentation are not the same thing. Defragmentation is a process that is used to optimize the performance of hard drives (HDD) by reordering the data on the disk so that it is stored continuously. This increases the efficiency of the drive by reducing the time required to read and write data.
On the other hand, pruning is specific to solid-state drives and is used to maintain disk performance over time. The use of solid-state flash drives means that they have a limited number of write cycles. When data is deleted from the SSD, the space it occupies does not immediately become available for reuse. Instead, the disk firmware marks the space as “invalid” and does not overwrite it until the pruning process is completed. This process helps prevent disk fragmentation and slowing down.
Garbage collection has a beneficial effect on SSD life and overall performance, and TRIM just makes it better (sometimes these two terms are used interchangeably). This is because without this command, the garbage collector will just constantly move all the pages, compacting partially filled blocks to keep the newly erased blocks available for programming, but this means that unwanted pages will also be moved, which will lead to a waste of time and increased wear. memory cells. Since TRIM explicitly specifies which pages are now unwanted, they can be left untouched during garbage collection and deleted as needed.
Sending Clippers
TRIM is automatically issued by Windows when you permanently delete a file (that is, delete it from the trash), but it does not happen instantly. It is added to the queue and processed when the SSD is ready for it.
However, this queue has a maximum size, and if it is full, some of these TRIM requests will be deleted. By default, Windows plans to re-run TRIM commands on a regular basis (calling it re-cropping).
You can make this happen, but we don’t recommend you to do it. But if you insist, go to File Explorer, right-click the drive, select Properties, and then go to the Tools tab. Finally, click on the button labeled “Optimize”. If there are no solid-state drives on your PC, optimization simply starts the usual disk defragmentation, but for NAND flash memory devices, pressing this button repeatedly issues the TRIM command. You can’t actually force the disk to do anything, so don’t worry about running it too often.; the drive will take care of itself perfectly!
However, this queue has a maximum size, and if it is full, some of these TRIM requests will be deleted. By default, Windows plans to re-run TRIM commands on a regular basis (calling it re-cropping).
You can make this happen, but we don’t recommend you to do it. But if you insist, go to File Explorer, right-click the drive, select Properties, and then go to the Tools tab. Finally, click on the button labeled “Optimize”. If there are no solid-state drives on your PC, optimization simply starts the usual disk defragmentation, but for NAND flash memory devices, pressing this button repeatedly issues the TRIM command. You can’t actually force the disk to do anything, so don’t worry about running it too often.; the drive will take care of itself perfectly!
Now you know what TRIM is and how it is useful for your SSD.