Windows 8/8.1 erroneously running defrag on SSDs?

Jovec

Senior member
Feb 24, 2008
579
2
81
Let's get more eyes on this. I wandered down this path while trying to identify the source on a huge number of writes to one of my new SSDs. I suggest reading the original blog post (not mine) for more info, as well as a work-around you may wish to implement should you agree with the point in that blog and this thread.

-----

Windows 8.1 Pro (and presumably all version of 8/8.1) appears to be running defrag on SSDs when certain conditions are met, those being:
1) Windows views the SSD fragmentation as being 10% or greater and
2) Defrag is run as part of Automatic Maintenance.

or 3) Defrag has never been run before

Here is the result on a fresh Win 8.1 Pro system, fully patched via Windows Update (including 8.1 Update 1). The dfrgui.exe was launched first, and Automatic Maintenance was started from Action Center. You can see that the SSD (in this case, an 840 Evo) goes through 5 passes of defrag and is then trimmed.

ssd-defrag.gif


You can also see this via the Windows Event Viewer, by filtering for app Defrag and event id 258 or by running the following command from Powershell.

Code:
Get-EventLog -LogName Application -Source "microsoft-windows-defrag" | sort timegenerated -desc | fl timegenerated, message

Which gets output similar to this when defrag has been run on the SSD via Maintenance and Windows views the drive fragmentaton as greater than 10%:
Code:
6/10/2014 3:45:10 AM
The storage optimizer successfully completed retrim on (C:)

6/10/2014 3:45:10 AM
The storage optimizer successfully completed defragmentation on (C:)

or like this when it hasn't and Windows views the drive fragmentation as less than 10%:
Code:
5/18/2014 12:01:57 AM
The storage optimizer successfully completed retrim on (C:)

In both cases Windows is not explictly asking for a defrag. It identifies the drive as an SSD and wants to run trim, but the scheduled task that is called by Automatic Maintenance passes a $ parameter that appears to cause the problem. Again, see the original blog post for more details.

Microsoft has stated that this log message is erroneous and that defrag isn't being run on SSDs. Scott Hanselman, who works for Microsoft and contacted the appropriate MS department about this, tweeted out "I just talked to that team. Bad message but no actual defragging happens." He also posted that "Windows doesn’t defrag SSDs. Full stop. If it reports as an SSD it doesn’t get defraged, no matter what. This is just a no-op message. There’s no bug here, sorry." I'm not trying to single him out. I don't know him, his position, nor his understanding of the issue at hand. However I believe the visual proof from the animated gif above and the difference in LBAs being written between a defrag and trim shown below dispute those statements, or at least deserve clarification.

I next performed a secure erase on the drive, reinstalled Win 8.1 Pro, and patched it via Windows Update. I used Samsung Magician to pull smart info for the drive, noting the total LBAs written (3713756846).
ssd-defrag-1.PNG



I then started Automatic Maintenance and observed Dfrgui.exe showing the SSD being defragged. When it was finished, I refreshed Magician and noted the LBAs written (3724914820).
ssd-defrag-2.PNG



I again performed a secure erase, reinstalled Win 8.1 Pro, and patched it. Using Magician, the total LBAs written were 3801909858.
ssd-defrag-3.PNG



Next I launched Dfrgui.exe and started the Optimize process from there, where the drive is only trimmed. Refreshing Magician, and the LBAs written show 3802312332.
ssd-defrag-4.PNG



In the first case, when Automatic Maintenance is run and Defrag appears to actually attempt to defrag the SSD, the difference in LBAs written before and after the process is 11,157,974. In the second case, where the SSD appears to have only been trimmed, the difference in LBAs written before and after the trim process is 402,474, which is ~27 times fewer than in the defrag case.

With #LBAs * 512 = bytes written, the erroneous defrag writes ~5.3GB to the disk and the trim writes ~0.19GB

Yes, I realize the irony in that the testing is causing more writes than the "problem" at ~40GB or so per reinstall. I'd be interested in seeing results from an in-use system rather than from a fresh install, where the SSD will appear more fragmented and presumably require more writes during the defrag. I'm using the fresh install method to force the SSD defrag to run.
 
Last edited:

KingFatty

Diamond Member
Dec 29, 2010
3,034
1
81
Wow very nice and thorough investigation/work there, kudos!

Are you somehow able to bring this work/post to the attention of *ANYONE* at microsoft? I think you are really proving them wrong, and it's very juicy in that they have gone way out on a limb, so this will make them look stupid for having to recant/change their story.
 

G73S

Senior member
Mar 14, 2012
635
0
0
If Windows 8/8.1 do a norma.l defrag on an SSD instead of a TRIM command, then simply run winsat formal in an elevated command prompt and try to defrag again you will notice it is not doing a defrag this time but just a TRIM command
 

G73S

Senior member
Mar 14, 2012
635
0
0
I've seen people not read the OP, but not even reading the title properly is something else. Dang.
yeah I didn't read the post, not even one word, due to how long it is.

But I replied based on the title of the thread :)
 

sm625

Diamond Member
May 6, 2011
8,172
137
106
My windows 7 did it to me when I installed onto my Samsung SSD830. Had to disable it myself. Shrug. I think they broke it on SP1.
 

G73S

Senior member
Mar 14, 2012
635
0
0
My windows 7 did it to me when I installed onto my Samsung SSD830. Had to disable it myself. Shrug. I think they broke it on SP1.
Windows 7's defrag doesn't EVER do trim, it only defrags. It's the defragger in Windows 8 that was updated to do TRIM commands instead of defrag only when it detects its an SSD
 

Techhog

Platinum Member
Sep 11, 2013
2,834
2
26
yeah I didn't read the post, not even one word, due to how long it is.

But I replied based on the title of the thread :)

The title is trying to say that the fact that it was defragging is an error.
 

stlc8tr

Golden Member
Jan 5, 2011
1,106
4
76
I've seen that blog post referenced a few times in various places. Since it seems believable and the workaround is easy, I ended up doing what it says to do.

It would be nice if MSFT could post a rebuttal to the claims if they are really that sure the claims are wrong but as long as there is a workaround, it's not that big of a deal.
 

SSBrain

Member
Nov 16, 2012
158
0
76
I'm surprised so few people talk about this. It's a real Windows 8/8.1/8.1 Update problem that Microsoft won't acknowledge. I've seen it occurring often on my systems and the only way to work around it is by disabling the scheduled optimization for all SSDs.

If Windows 8/8.1 do a norma.l defrag on an SSD instead of a TRIM command, then simply run winsat formal in an elevated command prompt and try to defrag again you will notice it is not doing a defrag this time but just a TRIM command

This won't fix anything. It's a bug in the scheduled optimization feature included in Windows 8.

stlc8tr said:
It would be nice if MSFT could post a rebuttal to the claims if they are really that sure the claims are wrong but as long as there is a workaround, it's not that big of a deal.
Problem is, it happens every once in a while, takes a long time to occur and there's no immediate indication that the system is defragging the SSD besides SSD load getting 100% and writes increasing by tens if not hundred of GBs all at once for apparently no reason at all. Most people won't notice, thus won't report.
 
Last edited:

mikeymikec

Lifer
May 19, 2011
17,711
9,577
136
Win81 normally says "x% optimised" rather than " x% fragmented" with a boot SSD in my experience, and running optimisation seems to take about 5 seconds (and at no point does it mention fragmentation). I've seen this on multiple builds I've done with Samsung 840 PROs.

On my PC, Win7 SP1 hasn't ever tried to defrag my Samsung 840 PRO (boot SSD), it also disabled SuperFetch for me. I did a clean install using an SP1 disc.

PS - I'm not saying the OP is wrong or anything like that, just relating my experiences.
 
Last edited:

SSBrain

Member
Nov 16, 2012
158
0
76
Win81 normally says "x% optimised" rather than " x% fragmented" with a boot SSD in my experience, and running optimisation seems to take about 5 seconds (and at no point does it mention fragmentation). I've seen this on multiple builds I've done with Samsung 840 PROs.

On my PC, Win7 SP1 hasn't ever tried to defrag my Samsung 840 PRO (boot SSD), it also disabled SuperFetch for me. I did a clean install using an SP1 disc.

PS - I'm not saying the OP is wrong or anything like that, just relating my experiences.

"x% fragmented" only appears when file system fragmentation reaches 10% and the bugged optimization scheduler automatically engages SSD defragmentation. When the proper conditions arise, this process starts when Windows performs its "system maintenance". In all other cases, when you manually click "optimize" or type on the command line "defrag /L", a "retrim" will be performed and a quick "x% trimmed" will be displayed in the Optimize Drives window. In other words, manual free space trim will properly occur.

As I and the OP stated, it takes several conditions for the defragmentation to occur and not everybody might be able to realize this.

SSD defragmentation also automatically occurs in background (again, during the next "system maintenance") the first time you install an SSD on your PC, regardless of the file system fragmentation level. This implies that right after you install Windows (regardless if it's 8/8.1/8.1 update) your SSD will be automatically defragmented.
 
Last edited:

corkyg

Elite Member | Peripherals
Super Moderator
Mar 4, 2000
27,370
238
106
Why isn't Win 8.1's defrag function not turned off if you have a SSD? It is controllable in Admin Tools.
 

SSBrain

Member
Nov 16, 2012
158
0
76
Why isn't Win 8.1's defrag function not turned off if you have a SSD? It is controllable in Admin Tools.

Please read carefully the blog post in the OP to understand what exactly happens. It's not that simple/obvious.