Should I defragment my SSD?

I have just learned that one should "Never defragment your SSD". But I have no idea if that is true.

I believe that Windows 10 was automatically scheduled to finish defragmentation on my SSD, but I cancelled it. Would it cause any problems for defragmentations done before?

The SSD is still not partitioned, because I cannot see the SSD drive in My Computer folder, only in system hardware manager. What are the correct steps I should take to install Windows on an SSD (it's my first SSD)?


Solution 1:

Let Windows do its job. Once per month it does a real full defrag, also on a SSD, to optimize the internal meta data.

The short answer is, yes, Windows does sometimes defragment SSDs, yes, it's important to intelligently and appropriately defrag SSDs, and yes, Windows is smart about how it treats your SSD.

Here is a reply from Microsoft:

Storage Optimizer will defrag an SSD once a month if volume snapshots are enabled. This is by design and necessary due to slow volsnap copy on write performance on fragmented SSD volumes. It’s also somewhat of a misconception that fragmentation is not a problem on SSDs. If an SSD gets too fragmented you can hit maximum file fragmentation (when the metadata can’t represent any more file fragments) which will result in errors when you try to write/extend a file. Furthermore, more file fragments means more metadata to process while reading/writing a file, which can lead to slower performance.

As far as Retrim is concerned, this command should run on the schedule specified in the dfrgui UI. Retrim is necessary because of the way TRIM is processed in the file systems. Due to the varying performance of hardware responding to TRIM, TRIM is processed asynchronously by the file system. When a file is deleted or space is otherwise freed, the file system queues the trim request to be processed. To limit the peek resource usage this queue may only grow to a maximum number of trim requests. If the queue is of max size, incoming TRIM requests may be dropped. This is okay because we will periodically come through and do a Retrim with Storage Optimizer. The Retrim is done at a granularity that should avoid hitting the maximum TRIM request queue size where TRIMs are dropped.

So install Windows on the SSD and forget it. Windows will do everything on its own.

Solution 2:

I have just learned that one should "Never defragment your SSD". But I have no idea if that is true.

A little knowledge is dangerous. Never defragmenting your SSD is probably a good idea if your system is utterly clueless to what an SSD is - say Windows XP. And if SSDs were fragile snowflakes likely to wear out and melt in the harsh heat of normal usage - I have a detailed answer to why that isn't true. It is pretty hard to 'wear out' a drive in normal usage. It might be handy to unlearn this.

Let's take into account that if your application was killing SSDs or even doing heavy writes, like Spotify did, people would flip. And quite often the people who write OSes are smart.

I'm referencing this blog post from Scott Hanselman heavily for the rest of this answer. Magicandre's answer references this too, but I kind of took away different lessons from it. It's worth a read for the details. I'm taking a few liberties with how I'm representing the information. I'd start with this

I think the major misconception is that most people have a very outdated model of disk\file layout, and how SSDs work.

SSDs do fragment and these fragments need to be kept track of. At a fundamental level defragging SSDs helps your file system run efficiently, even if it's different from how a spinning rust drive would. The post I referenced points out volume snapshots would be slow without defragmentation.

SSDs also have the concept of TRIM. While TRIM (retrim) is a separate concept from fragmentation, it is still handled by the Windows Storage Optimizer subsystem and the schedule is managed by the same UI from the User's perspective.

TRIM is good. Trim saves on writes since it's a mechanism for marking blocks as read without erasing them, and erasing them as needed.

Whoever told you to never defragment a drive has no idea that modern OSes are designed for SSDs and that the necessary housekeeping processes are rolled in.

While it's tempting to assume you know better, in this case the people who wrote the OS have optimised things for you. Keep calm, and let Windows defragment your drive.

Solution 3:

For completeness' sake:

Fragmentation depends on the filesystem(FS), not on the disc or OS.

This means that answer to your question does not really need to ask for Windows*; SSD is special case - it works differently than an ordinary disc.

An FS is a way of organizing your files on the disc. The most common Windows formats are NTFS and FAT32. The most commonly used FSs on Linux are ext3/ext4, but there are many others (zfs, xfs, jfs, ReiserFS, btrfs, and more).

A disc is divided into blocks. You can imagine it as a long tape on which you can write some data. When you write something onto the disc, you use these blocks. Obviously you want related files to be written next to each other, and a single file to be written in a single block, so you don't have to jump around the tape. When things are all scattered around, that's what we call fragmentation. Defragmentation organizes them.

Obviously how you organize things (FS) determines how well they are organized (whether there is fragmentation). If you organize your files from the start, you won't have fragmentation. That's what happens in some filesystems (e.g. the ext family). These filesystems organize your files on the fly (before writing), so that you don't have to defragment them except under special circumstances when there wasn't any other choice but to to introduce a little disorder.

For more information about ext4 and how it prevents fragmentation, you can refer to this page

Now an SSD works differently; it's not a tape. You can get instant access everywhere. The whole point of defragmentation is that you organize your files neatly, so that you don't have to jump around. There's no way to jump around in an SSD. You don't care whether you have to get to the other end of the tape back and forth; there's no tape.

However, there are other ways of optimizing an SSD. See this topic for clarification.

*Almost; filesystem choice is correlated with OS. Most Linux users use different FS than Windows or OS X users.

Solution 4:

The existing answers are great, but I have some things to supplement them...
I defragment my SSD and disable automatic TRIM, but for totally different reasons than mentioned:

  1. I want to be able to recover files or partitions if & when I accidentally delete something.
    No, it doesn't happen often, but the few times it's happened, it's been quite frustrating to not be able to recover things that I would have been able to recover on a hard drive, even when I tried to recover them immediately after deletion.

  2. I expand, shrink, and even move partitions around every few months, and defragmenting and consolidating files makes this operation far faster and less risky. You'd think you can trust partition managers nowadays, but as late as December 2015, I've run into errors (corruption) on plain move/resize operations. And the smarter partition managers try to avoid running on volumes that are heavily fragmented before any damage is done (and usually, though not always, succeed).

  3. I use Linux sometimes, and I've gotten burned by its corruption of NTFS volumes as lately as a year or so ago. This isn't due to fragmentation specifically, but seeing that it can't even handle unfragmented files properly, I'm on the defensive and trying to present as clean of a volume as possible to it (and even then, I avoid writes most of the time).

The sad part about #2 and #3 is, people who haven't seen these problems with their own eyes always think I'm nuts and am making this all up, or that my system must be broken somehow. But I've reproduced these quite a few times on multiple systems, and as someone who has written his own NTFS readers, I know a thing or two about file systems and kernel programming... with NTFS being at the center. So I know bugs when I see them. Nobody believes me, but I warn people anyway, given that I've seen these happen with my own eyes -- so, if you mess with partitions or use Linux at all, I recommend you keep your drives defragmented. YMMV.

Oh, and don't forget to run TRIM manually every once in a while when you don't need to recover anything. Although if I'm being honest I have yet to see any benefit from it...

Solution 5:

You can defragment your ssd. Should you? Certainly not very often but there are a few cases where it can be beneficial to do it rarely.

a) You have a Samsung Evo 840 affected by the slow read of old files bug. Defragmenting will effectively rewrite them and they wont be old files any longer.

b) While the effects of fragmentation on SSDs are extremely minor, the controller still has to reassemble files that are spread out over many flash chips. The performance impact of this is very small, but again defragmenting should reorganise the files and make them easier for the controller to reassemble.

c) If you have anything close to a modern ssd an occasional defrag will not affect it's life time enough to matter. In 2018 a hw tech site did a test of ssd endurance and the Samsung evo 840 500GB which uses 2d tlc (which has very bad endurance) failed at around 600 TB of writes. Anything better is likely using 3d tlc (called vnand by some companies) which has a lot more endurance. Bigger models also have more cells to write to which further increases endurance. And if you have a large pro drive endurance is a complete non issue (in the test I mentioned before the Samsung pro 512 GB lasted for 9 PB of writes... larger/newer models should last even more). These numbers are practically impossible to reach unless you are trying on purpose. Writes used to kill (cheap ones anyway, expensive models used slc which has a lot of endurance too) ssds back when it was a new technology, capacities were small, controllers stupid, ....