2

As to what TRIM does to SSDs, is the result the same as with writing zeros to free space? Eg: running cat /dev/zero > zero.file; rm zero.file on the drive?

Majal
  • 826
  • 2
  • 10
  • 19
  • 2
    No; Its not the same. TRIM indicates the data can be wiped. While writing all 0's results in the data being deleted its only being replaced not wiped. There is additional steps in this process but the data being wiped and replaced with 0's are **NOT** the same process. – Ramhound Apr 12 '14 at 02:51

1 Answers1

6

EDIT:

TRIM has already been explained way better than I did here:

What is TRIM exactly?

I found this link in the sidebar to this very question. So, should you need the dumbed-down version of an explanation of TRIM, i have provided it below c:


You have to understand how SSDs work to understand the answer to your question:

For technical reasons, writing and reading from an sd card is fast. The only operation that can be VERY slow is deleting something. Basically, writing and reading can be done in small parts, whereas to delete something, the controller has to apply a comparatively high voltage to the whole area where that something is in. That means it has to take all the data which are surrounding the deleted file, copy it to a different area on the disk, and then finally apply that "delete current" to the area. As you can imagine, that takes a long time. TRIM basically does this process in the background.

If you delete something on a modern OS, you don't really delete the space where the data are written. It just marks the space where the file was as empty by deleting the file's entry in the storage medium's file directory.

If you want to write new data to that file's spot, the area is still not ready on an SSD because deleting didn't really reset the storage to be ready to receive new data, it just marked it as deleted. If the controller would just wait until you need to write something and then start the whole moving data/really deleting process, it would slow down normal operations too much.

So, if you delete something, you can go on with your work, and if something needs to be written to the disk, the controller will just choose a different, already prepared area. Parrallel to this happening, TRIM performs the slow process of actually freeing that deleted file's space by moving the surrounding data and applying the delete voltage.

If you understood this process you can see why it is recommended to not fill SSDs to the brim with data, if you want good performance.

Now, if you write a file containing zeros to an SSD and delete it afterwards, you have basically done the worst thing you could possibly do to it's performance for while. At least until TRIM has done it's magic and reset all those sectors.

[DISCLAIMER] This is obviously a layman's view on the process, i have read all this when i researched SSDs many years ago, when they were new. It should sufficiently answer your question, though.

edit: spelling

keen
  • 391
  • 3
  • 5
  • No. Writing zeros has the same effect as TRIM, as SSD controllers are "smart enough" to regard zero as free space rather than data, just that writing zeros takes longer than TRIM. I have experienced performance improvement after writing zero on more than one SSD drives without TRIM feature. – robbie fan Aug 27 '21 at 07:00
  • @robbie No, practically no SSD controller is smart enough to detect zeroes and treat it like trim. – Remember Monica May 28 '23 at 05:28
  • @RememberMonica At least I have seen writing zero effective on my two SSDs--for one of them (Samsung, year 2015, 512GB), trim is claimed to be supported, but doesn't seem to work properly; writing zero speeds it up. Another is a 2012 Sandisk model, which doesn't support trim, but writing zero helps. One more thing: doing a complete formatting to a disk also writes zeros, and this can speed up the drive if the drive recognizes zeros. – robbie fan Jun 13 '23 at 01:35
  • @robbiefan well, can you share any evidence? A perceived speedup is not evidence for the drive detecting zeros, the writing could simply trigger a garbage collection, or the drive might have gced incidentally. Likewise, some controllers compress data, and this could then, again, look as if the device would do trim when it doesn't. Also, there is a difference between wwriting zeroes and e.g. the write zero or write same commands, which might well be treated differently. In any case, your original claim that writing zeroes is always as effective as trim is actually dangerous, as it worsens wear. – Remember Monica Jun 14 '23 at 21:08
  • @RememberMonica I remember the Sandisk model doesn't have TRIM and doesn't have garbage collection, so it goes slower and slower after being used for a long time (about 5 times capacity overwritten, because I installed a VM on it). Then, I tried quick format--doesn't recover the speed at all. I then did a complete format, which writes zeros. The speed recovered! – robbie fan Jun 16 '23 at 05:47