Solved How Often Do You Trim Your SSD ?

Solved issue
Just a footnote to the above, the larger the SSD, the bigger the TBW rating.
So the 4TB ones have 2400 TBW rating. That's 2.4PB. That thing will outlive us. Under normal usage. Unless you have a tendency to write 50GB to it daily.
 


does trim ONLY delete data not being used?

Some reading for you...
https://ssdsphere.com/trim/
https://www.newsoftwares.net/blog/truth-does-trim-securely-delete-data/
Has it ever snipped-snipped something you treasure?

No never not what it does.
1714023210143.gif
 
I read the whole thread now, and found one or two things I wasn't sure if they were true. Then I researched the whole thing for about two hours and started a giant reply, which I then turned into a blogpost. Hope thats ok ;)

In reply to the thread though:

If we don’t perform TRIM regularly we won't be able to reclaim used space on the Drive over time which means the SSD will slow down and die

Trimming your SSD does not "free up space".
NAND flash, unlike HDD's, needs its blocks to be "cleared" (deleting the data) before you can write them again. with hdd's you can just write over it, but with SSDs the SSDs controller has to delete the block, and then you can use it.
This collides with how most filesystems work - they just delete the "metadata" about "where the file is" and then you can write to this space again.
Trimming your SSD instructs your SSD to actually overwrite those blocks. A systemd timer is setup by default on Debian and Ubuntu (there I checked) to run "weekly", which means Monday 00:00am, which executes this action (runs a fstrim). Debian expects your system to be mostly idle at mon 00:00am.
If you write to untrimmed blocks, your ssd will have to delete the block and THEN write the data. this leads to the write action needing more time. hence you do this regularly during idle hours.

So I conducted a little experiment running this command manually over several days.

If you dont generate and delete VAST amounts of data in short time periods, this should not be required.

Of cause it depends what I do on the computer.

yes

Above shows the amount of freed space

s/freed/processed

I checked with df on several servers I manage, and there is no freed space.

LOL nobody told me about trim is it like defrag?

no its not

Does this only work with SSD's or is it good for HDD's also?

with HDDs you can overwrite blocks directly without having to delete them first (having as in the SSDs controller does that for you)

No...never defrag an SSD it will kill it very fast. 1713676839653.gif

never is incorrect, as the linux distro maintainers set this to one week by default (see /usr/lib/systemd/system/fstrim.timer on debian based distros)

yes you can Trim an external HDD...I just did but don't need too.

man fstrim first line: "This is useful for solid-state drives (SSDs) and thinly-provisioned storage."

Not sure what it actually did on your ssd.

also man mount -> search "-o discard": "If set, causes discard/TRIM commands to be issued to the block device when blocks are freed. This is useful for SSD devices and sparse/thinly-provisioned LUN"

OnCalendar=daily

If you run a VERY high write / delete system, yes, maybe.

If you ever needed to recover deleted files, like with testdisk or photorec, those can't recover deleted files that have been trimmed away.

Correct. Trimmed blocks on SSDs are gone.

the important thing is to provision 10-20% of SSD to not get used.

Correct, due to over provisioning. as this has not to much to do with trimming an ssd I did not write about it or research it much further, but, among not trimming your ssd, it is another cause of write amplification (a write operating taking more time than it should.

I have it set to to the default which is as often as I trim my nails, once every week.

yolo :)))

SSD over-provisioning has been a thing for a while:

On this I'm not 100% sure but from what I understand the unused space is mostly used for wear leveling.

without you I would probably completely forgot to trim my SSD!

You CAN forget about it as the systemd timer described above does that for you

over provisioning

when nand blocks die, your SSD will "replace" their addresses with the spare ones. Also your ssd tries to keep the number of write operations similar for all blocks, so that your ssd's blocks age at a similar pace. thats all magic your ssd controller does for you under the hood, not a kernel thing.


I guess this one is more of a consumer thing, as in datacenters / cloud you don't really care if a SSD dies, ceph manages this for you and you just replace the SSD. If your laptop's ssd smokes off and you dont have backups, yes.

I think this might have been more for older generations of SSDs. Do backups and you can have swap on your laptop on SSD. Do backups if you dont :p

If in doubt just manage the https://www.howtogeek.com/449691/what-is-swapiness-on-linux-and-how-to-change-it/ a bit. If you run free -m and you use swap at all, then download more ram. I have no box that uses swap and my monitoring alerts me if they do. Using swap means you need more ram - in my world at least (hosting and unless suspend to disk, correct).

The controlling technology is in the firmware of the ssd and helps even out the wearing on the cells. The ssds can be conceived to have their own little OSs managing the storage in conjunction with the user's OS.

gave you a thumbsup for the whole post

A 500GB SSD...install Mint (2.9GB) space now on Drive about 460GB because formatting takes up space

I might missunderstand you, but if you mean formatting as in creating a GPT and a filesystem, then (almost) no. If you mean the OS no idea what mint installs by default ;) thats another topic ofc.

If you're not running a server but a personal workstation then what's the reason to keep your system up for so long?

its called "collecting uptime" and its to increase your level of coolness x)

My dumb box turned off yesterday, forgot to attach the charger after a meeting. meh. cant join.

Jokes aside. Reboot your boxes to apply kernel upgrades and dont collect more than a week of uptime. configure your low-importance servers to reboot automatically on kernel upgrades https://askubuntu.com/questions/1401765/reboot-automatically-when-kernel-is-upgraded or setup a monitoring alert for your needs-100%-uptime servers so you can manually do it.

Modern hardware has reached the point where I'm satisfied with the performance and my devices are lasting longer.

you need a gpu to run a LLM locally now :p There will ALWAYS be something xD But yes I kinda agree with you lol

Here is the blogpost about why linux fstrim runs weekly by default, and how it helps increase SSD write performance.
 
If you dont generate and delete VAST amounts of data in short time periods, this should not be required
I'm honestly skeptical about trimming being helpful too, but to me the trimming still makes sense if you are a "normal" computer user:

NAND flash memory, the storage medium in SSDs, has a finite number of Program/Erase (P/E) cycles. Each P/E cycle slightly degrades the quality of the NAND cells, eventually leading to their failure. TRIM helps reduce the number of unnecessary P/E cycles by allowing the SSD to erase only the blocks that are genuinely unused. According to manufacturer data, enabling TRIM can extend the lifespan of an SSD by up to 30%.

this seems to be saying that trimming reduces the general amount of writing activity on the hard drive. Overall, the hard drive will most likely out-live your motherboard, but why would you want to take that risk? I assume a lot of people do cloud storage now adays, so trim might not be worth your time.

This discussion is incredibly interesting to me.
 
TRIM helps reduce the number of unnecessary P/E cycles by allowing the SSD to erase only the blocks that are genuinely unused

From how I understood this, this is incorrect.

You delete a file, but the filesystem doesnt overwrite the file, it just deletes the "table of contents entry" for it.
the data remains on the ssd blocks for now. Next time you want to write to that block, the ssd needs to first clear it and then it can write to it.
Hence you trim, to delete all unused blocks during low ressource usage times (as in your webserver db is not busy at night).
This way, next time you want to write to those blocks you can do so directly, without clearing them first.
This is what trimming is for.

this seems to be saying that trimming reduces the general amount of writing activity on the hard drive.

trimming is for SSDs not hard drives (but I assume thats what you meant, just to make sure)

It doesn't reduce the amount of writing on it. it just clears those blocks when you "have time for it". Next time you want to write things fast you can do so, because the blocks are already cleared.

Overall, the hard drive will most likely out-live your motherboard

I highly doubt that

but why would you want to take that risk?

Which risk? Trimming is only triggering a process when you have time instead of waiting for your OS to want to write to those blocks by itself. It simply improves write speed.

I assume a lot of people do cloud storage now adays, so trim might not be worth your time.

There is a systemd timer that does trimming weekly by default. You don't have to do anything for that.
 
In reply to the thread though:
@blunix... I think you are doing "quotes" the harder way. It seems that you are click-and-dragging to copy the text you want, then right-click and copy, then you have to open the Quotes dialog in the editor controls above, then paste in there... extra steps and clicks that aren't needed. Also, another negative aspect is that we do not know who you are quoting, and I'd prefer to see that.

The easier way is to click-and-drag to highlight the text you want to quote, and when you do that, a "Reply" button appears right way... just click the Reply button and it all will paste itself down into your reply editor with less effort, and it will show us who you are quoting.

Thanks! :)
 
Where are *.timer unit files on Debian, and the one that controls TRIM function, how is it called?

I linked a blogpost at the bottom of my long post, look there. It shows the systemd timer that triggers the weekly trimming in the post, as well as the systemd service said timer triggers. This blogpost also contains a link to another blogpost that explains systemd timers in great detail.
 
Last edited:
@blunix... I think you are doing "quotes" the harder way. It seems that you are click-and-dragging to copy the text you want, then right-click and copy, then you have to open the Quotes dialog in the editor controls above, then paste in there... extra steps and clicks that aren't needed. Also, another negative aspect is that we do not know who you are quoting, and I'd prefer to see that.

The easier way is to click-and-drag to highlight the text you want to quote, and when you do that, a "Reply" button appears right way... just click the Reply button and it all will paste itself down into your reply editor with less effort, and it will show us who you are quoting.

Thanks! :)
Yes, I omitted that - sorry to decrease readability. I read through the entire post, which by now is quite long, and forgot to put the usernames in the long reply of mine.

I quoted about 20 replies in this thread, hence the reply thing didnt work that way

In reply to the thread though:

with that particular sentence I meant "i am replying to the enire thread". My goal was to try to correct some misunderstandings after investing time into researching the topic in depth, like the suggestion that trimming frees up space.
 
hence the reply thing didnt work that way

It can, presumably. As you go from page to page, it happily caches your comment for you as a draft comment.

So, you should be able to 'properly' quote someone as you go from page to page to page, It saves a draft so that when you move to a new page it should retain your current work and you can then add to it.

The draft thing is pretty neat. You can start a comment and come back to it later if you want.
 
I quoted about 20 replies in this thread, hence the reply thing didnt work that way
Ah, but it does work that way. You can start a reply with that method, or you can begin a reply from scratch. But in your ongoing reply, just open up a clean spot with empty lines, put your cursor in the middle of it, and then you can use that method to add all the extra quotes you want. I'll demo a couple below...

Just a footnote to the above
Working from the top down is easiest.

Thanks for the reading material
Just adding one after another.

But where it gets tricky is if you save your post and come back to edit it again later. I do this often. What happens then is that you open the post you want to edit... and when you quote new material it appears in a brand new post instead of the open one you are editing. In this case, put your cursor in the new post, use CTRL+A to Select All (which is only your newly quoted text), CTRL+C to Copy, then put your cursor into the the post you are editing... and paste. It does take a little getting use to, but it works.

Also, by quoting like this and including the person being quoted... they will be notified that you have quoted them. This is a good thing too. I'm sure you've seen this before, as when I quoted you in my previous post.
 
@KGIII I quoted multiple people so i wrote the reply in an editor

ah ok funky. quoting multiple people does work. didnt know that. ok next time then! thx for the heads up
 
From how I understood this, this is incorrect.

You delete a file, but the filesystem doesnt overwrite the file, it just deletes the "table of contents entry" for it.
the data remains on the ssd blocks for now. Next time you want to write to that block, the ssd needs to first clear it and then it can write to it.
Hence you trim, to delete all unused blocks during low ressource usage times (as in your webserver db is not busy at night).
This way, next time you want to write to those blocks you can do so directly, without clearing them first.
This is what trimming is for.



trimming is for SSDs not hard drives (but I assume thats what you meant, just to make sure)

It doesn't reduce the amount of writing on it. it just clears those blocks when you "have time for it". Next time you want to write things fast you can do so, because the blocks are already cleared.



I highly doubt that



Which risk? Trimming is only triggering a process when you have time instead of waiting for your OS to want to write to those blocks by itself. It simply improves write speed.



There is a systemd timer that does trimming weekly by default. You don't have to do anything for that.
All i was saying is that if trimming did work that way, then i guess you could save your SSD (SSDs serve the same purpose as hard drives, stop confusing things!). But since trimming doesn't reduce the amount of writing, it seems worthless in a non-server scenario.

And yes, mobos tend be the first to go, at least that is my experience. I have used multiple boards and multiple hard drives, i have only had one hard drive fail so bad i couldnt read or write to it anymore. None of my SSDs have gone bad yet. I did knock an external HDD off a table once though, not a good result.
 
@Vimmer

then i guess you could save your SSD

erasing blocks before being able to write them in NAND flash happens if you trigger it in advance (trimming) or not. It has nothing to do with extending the ssd's lifetime. its purely a way to improve write performance by cleanup up during low-ressource-usage hours.

SSDs serve the same purpose as hard drives

in server environments SSDs are used for read/write intensive usecases, while HDDs are used for either cases where this is not required and money needs to be saved or vast quantities of data need to be stored.

it seems worthless in a non-server scenario.

depends a bit, generally yes. If you have write-intensive usecases (video editing maybe?) it might be worth it.

However its not really a choice thing, as it is done weekly anyways, and unless you disable the systemd timer it is done by default.

mobos tend be the first to go

In physical servers (of which I manage a reasonably large number) "drives" die about every 3 years, while RAM tends to die "pretty much never" and I don't recall ever having to ask the "hardware guy in the datacenter" to give me a new mainboard (which means a new server) - but maybe there are differences with consumer products, with which i'm not much familiar.
I have some VERY old thinkpads here and they turn on 100% reliable. On some of them I had to change the BIOS battery (thats nerd language for its OLD). On all of them I had to change the drives at some point due to to many S.M.A.R.T. errors (both hdd's and ssd's)
 
Last edited:
In physical servers (of which I manage a reasonably large number) "drives" die about every 3 years, while RAM tends to die "pretty much never" and I don't recall ever having to ask the "hardware guy in the datacenter" to give me a new mainboard (which means a new server) - but maybe there are differences with consumer products, with which i'm not much familiar.
Laptop motherboards tend to have bad ventilation, and motherboard components bear the heat from a lot of the other components. With any setup, id guess chance of what goes bad first is equal, but according to my research, power supplies and motherboards tend to be the worst.
 
I trim my ssd anytime its hair grows too long. then I put a bowl over it and trim.
 
Laptop motherboards tend to have bad ventilation, and motherboard components bear the heat from a lot of the other components.

In my experience, this isn't as true today. A modern laptop stays amazingly chill - even under load.

Long-term gaming might change that. I can't speak to that. I can point out that a fairly modern laptop is even cool to the touch.
 
I read the whole thread now, and found one or two things I wasn't sure if they were true. Then I researched the whole thing for about two hours and started a giant reply, which I then turned into a blogpost. Hope thats ok ;)

In reply to the thread though:

Trimming your SSD does not "free up space".

Really is that so...did you test this like I did...easy to copy and paste from somewhere.
What's this...could this be freed space on my SSD surely not...
1714102175710.png

Alternatively, we can run a TRIM manually by using the fstrim command:

$ sudo fstrim -v /
/: 22.2 GiB (23802130432 bytes) trimmed
The output is the amount of freed space. Also, the -v option provides a more detailed and informative output.

From this article...https://www.baeldung.com/linux/trim-ssd

People can say whatever they like but it's the proof that counts more than quotes.
1714102921912.gif
 

Members online


Top