There is a rather lengthy discussion on the topic here:
Can anyone else verify if defrag is messed up again? Or did MS change the way trim works? Scheduled task is running defrag and trim on my two SSD drives every seven days (weekly). On Win 10 this seemed to only happen monthly but ever since I upgraded to 11 it happens like clockwork every seven...
www.elevenforum.com
Below is just a cut / paste from my post #13 in that thread. Following that cut / paste I have a few additional comments for clarification:
For an SSD, a quick review of what a trim operation actually does:
When data is deleted from a drive, you are not actually removing that data, you are simply deleting the pointers to the areas on the disk where that data is held. For a traditional HD, that's just fine. When you later write to those freed up areas of the disk, there is no performance penalty. You simply write to those areas of the disk the same as always (except in the case of SMR disks, but that's a whole other ball of wax). However, on an SSD, blocks must be erased before they can be written to again. A trim operation will erase areas of the SSD that were previously in use but have now been freed up, doing so in the background so that when the time comes to use those blocks again an erasure does not need to be performed first. A "RETRIM" operation to your SSD is the OS (Windows 11) informing the SSD of all the areas of the disk that should be considered empty. These hints to the SSD will trigger a TRIM operation for areas that the SSD was not already aware that should have been TRIMed.
I want to stress the importance of having a properly trimmed SSD, because the performance problems can be amplified far more than you might initially think. Note that even if you are going to write only 1 byte of data to a block that has not been trimmed, the ENTIRE block must be erased first and the entire block needs to be rewritten. If there are a lot of untrimmed blocks, this can make an ENORMOUS difference in performance.
If you have a lot of free space on your SSDs and you don't write large amounts of data, then less frequent optimization may be just fine. The drive will try to write to trimmed blocks first, however, there are limits to this as other considerations such as wear leveling algorithms come into play as well.
Also, bear in mind that there is absolutely no negative to performing a trim / retrim more frequently. Only blocks that need to be trimmed will be trimmed, doing so more frequently simply means that you will tend to accumulate fewer untrimmed blocks between runs keeping your drive at peak efficiency. Those blocks are going to have to be trimmed at some point in the future anyway. Note too that a retrim only informs a drive of areas that it should consider to be unused. Usually, when everything is running normally, a trim operation is performed as soon as blocks are freed, but if something interferes with this (unexpected shutdown for example), that's when a retrim helps. Because that does not happen often, a retrim usually results in little disk activity anyway, so again, more frequently retrimming has no negative impacts.
---------------
Additional comments:
Normally, a TRIM is triggered as soon as data is deleted from an SSD. This tells the SSD to erase those blocks (when free time is available) so that they are free for immediate writing. If a TRIM were not performed on these, an erase would need to be performed first, severely impacting performance.
However, let's say that you delete 100GB of data from your SSD and immediately afterward an unexpected shutdown of the system takes place. Now those erase operations don't get performed. This is where the scheduled optimization on an SSD comes into play. The optimization sends "hints" (a Re-TRIM) to the SSD saying "these are all the blocks, that I as the operating system know to be unused". The SSD can then check to see if there are any blocks that it had not already erased. If any blocks were missed, it will then perform an erase operation on those blocks.
Note that it is the responsibility of the OS to inform the SSD what blocks are considered unused. The SSD cannot be intelligent enough to understand the inner workings of every possible OS and filesystem, only the OS knows in full gory detail everything that should be considered unused (that is up until a block is actually erased and marked as unused by the SSD).
I hope that this helps to clarify things.