SSD Defragmentation: What Happens in Windows

1198

In SSDs, is it better to disable defragmentation in Windows or let the operating system handle it?

Even today, many recommend disabling SSD defragmentation in Windows by typing Defragment and optimize drives in the search box of the operating system then disabling any intervention on solid-state drives from the Change settings section. Could Windows not recognize an SSD and refrain from performing defragmentation? The short answer is: yes, Windows correctly recognizes SSD drives and does not apply traditional defragmentation as in the case of hard drives; at least it does not do it systematically. As a rule, it is unnecessary to make any configuration changes to the Defragment and Optimize Drives system function.

Let’s start by saying that, in general, defragmenting an SSD’s contents is useless and counterproductive because it subjects the drive to several avoidable read and, above all, write operations. If used correctly, SSD lifespan has become less of a concern than in the past: see Is SSD lifespan a parameter to worry about? However, this does not exempt from applying an effective backup management policy.

SSD Defragmentation: What Happens in Windows - Image 1

In general, Windows does not perform defragmentation of SSDs: it can activate it once a month if the Previous Versions feature is enabled on the drive. This tool allows you to automatically create a copy of the drive contents to restore the contents of a file or folder as they appeared in the past (very useful function in case of rash changes to files or following the deletion of important objects).

Previous Versions is closely tied to the System Restore utility: if the latter is disabled, Previous Versions will not allow you to restore any previous versions of files and folders.

We have repeatedly noticed that Windows 10 disables System Restore by default (and therefore also Previous Versions ): when you upgrade the operating system to a more recent release, the previously enabled System Restore feature is disabled.

We said that an SSD is automatically defragmented by Windows only once a month if the Previous Versions feature is activated (also known as Shadow Copy, Volume Snapshot Service, Volume Shadow Copy Service, or, again, VSS ). This is important because, on fragmented SSDs, copying data to images managed by Previous Versions may be slower and adversely affect the entire drive’s performance.

More frequently, however, the Defragment and Optimize Drive utility proceeds by sending a series of TRIM commands ( retrimming) to the SSD controller. When a file is deleted from the solid-state drive, TRIM marks as deleted those pages of the memory that no longer contain useful data and whose contents can be removed. Once the information on the memory pages to be deleted has been received from the TRIM command, the SSD controller will then remove the data following the manufacturer’s criteria at the firmware level.

The TRIM commands are not immediately sent to the controller but placed in a queue that is disposed of by Windows before it reaches the maximum accessible size (exceeding this threshold, further TRIM requests would be discarded).

Try to open PowerShell (press the Windows + X key combination choose the Windows

PowerShell entry) then issue the following command:

Get-EventLog -LogName Application -Source “microsoft-windows-defrag” | sort timegenerated -desc | fl timegenerated, message

Using the variousPowerShell cmdlets and its pipeline, you can extract information on the various defragmentation and optimization operations performed on the SSD drives and hard drives connected to the System in use.

SSD Defragmentation: What Happens in Windows - Image 2

In our case, we have a traditional hard disk as drive D: and an SSD with the identification letter C: on which the operating system and applications are installed.

As you can see in the figure’s example, Windows has proceeded to systematically defrag only the hard disk. Simultaneously, the SSD is normally subjected to retrimming with the defragmentation that takes place once a month ( Previous versions and System Restore are activated on both storage media).

As a general rule, it is best not to use software designed to defragment hard drives on SSDs: Imagine that the SSD controller has optimized all the NAND cells’ data. The running software has no visibility on this operation, so it could detect a certain fragmentation at the file system level: for this reason, the result could be counterproductive. The view of the data at the file system level that the operating system has does not match the positioning of the same information at the physical level on the SSD.

If anything, after installing the Windows 10 May 2020 Update (version 2004), you could temporarily disable the optimization of SSD drives because, otherwise, due to a recently introduced bug, it could occur at every restart of the operating system instead of on periodic basis.