View previous topic :: View next topic |
Author |
Message |
Goverp Advocate
Joined: 07 Mar 2007 Posts: 2202
|
Posted: Sat Mar 26, 2022 11:56 am Post subject: Does TRIM work at device, partition, file or other level? |
|
|
My laptop shares its SSD with linux and W*nd*ws. The linux partition is F2FS, which does its own things about handling erased blocks. I found that Windows defragmenter (or whatever it's called in Windows 10) issues a TRIM on SSDs (and by default on my system scheduled TRIM was disabled). My ignorance and this got me wondering...
Does TRIM act at a device level, in which case the Windows TRIM would affect the F2FS partition and vice-versa, or is it at a lower level such as partitions? I presume the SSD firmware doesn't read the partition table(s); at a minimum it could be BIOS or GPT, and there are weirder things out there. Or is it down the the filesystem or OS? _________________ Greybeard |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54799 Location: 56N 3W
|
Posted: Sat Mar 26, 2022 12:19 pm Post subject: |
|
|
Goverp,
The answer to both parts of the question is yes. :)
The trim command tells the drive which blocks in the filesystem are no longer required.
There is even a fstrim command, that can trim all mounted filesystems.
What drive does with the information and when the drive does it is a closely guarded secret.
If the drive takes notes, nothing may happen straight away.
If the drive takes it as a command, it will erase the erase blocks holding trimmed write blocks right away. Erase blocks are bigger than write blocks, so some used write blocks may need to be copied.
This is called 'write amplification', as the drive copying data around to free an erase block to be able to erase it.
Hence use fstrim in a cron job rather than the discard option as it may help drive life.
Now it gets murkier.
Most modern SSDs do wear levelling, including the erase blocks that never change. This means that internally, SSDs do not have any concept of a partition as a contiguous range of blocks because both erase blocks and write blocks get moved around, to preserve the partition fiction.
Rotating rust HDD started that with sector and track sparing and relocating failed sectors, since there, a partition contiguous range of blocks, except where sector sparing has been used.
I have one SSD that does trimming/erasing at startup. The next reboot, following a fstrim -av, it takes 15 min for the root filesystem to become available.
I don't know that what its doing, just that there is a good correlation between the two events. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
logrusx Advocate
Joined: 22 Feb 2018 Posts: 2660
|
Posted: Sat Mar 26, 2022 1:07 pm Post subject: |
|
|
Strictly speaking, it works on the partition level. It informs the underlying firmware what blocks of the partition are considered no longer unnecessary by the file system, so that the firmware can do its thing spreading the wear level evenly across the chip. That means partitions are completely detached from physical regions on the drive.
Trimming can be configured either online or "offline". I put the quotes around offline because it's not really offline, it's just that you or your crontab must run the fstrim command.
Online trimming can be configured in fstab, if the fs supports it. In relationship to the other thread I think I noticed F2FS provided such an option.
Swap partitions perform online trim by default and don't need manual configuration or running fstrim.
I hope that information is useful to you. Just a few months ago I had to search for it too, but most of the discussion happened on IRC so I guess it's lost.
Most of the relevant information I found on Wikipedia, but there were quite a few other sources I don't remember, which contained relevant information not found on Wikipedia.
Regards,
Georgi |
|
Back to top |
|
|
Goverp Advocate
Joined: 07 Mar 2007 Posts: 2202
|
Posted: Sun Mar 27, 2022 11:20 am Post subject: |
|
|
Thanks folk.
In summary, Windows partitions will be trimmed by Windows "Disk optimizer" either if it runs on schedule or if it's run manually. Linux partitions will be trimmed if something's configured to trim them, and the Windows and Linux trimming are completely independent. (FWIW, I let F2FS do whatever it wants. I assume, possibly naively, that it will do the best thing.) _________________ Greybeard |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|