Answer: Why it can take Disk Cleanup so long

Cliff S

Missing my GIF avatars:(
Pro User
Messages
2,467
Location
Bamberg Germany
I've been noticing lately a lot of people have been asking "Why is disk cleanup taking so long???". Some people seen to think Windows just deletes them right away or marks the file for deletion, but there is a little more involved than that, especially for kernel changes such as the updates on Patch Tuesday. Files in use must be flagged, replaced, copied, moved delayed to a temp file, written, and renamed. I'm sure many have seen this term: PendingFileRenameOperations. This must happens to all "in use" files be it drivers, windows defender, and Windows Updates(which should be kept awhile incase of needed rollback or uninstallation) no matter how small or large, it can be a lot and for the cpu(be it a B960 or an i7) it takes time to do.

I finally found a bit of code HERE that shows what happens:

///
/// Consts defined in WINBASE.H
///
internal enum MoveFileFlags
{
MOVEFILE_REPLACE_EXISTING = 1,
MOVEFILE_COPY_ALLOWED = 2,
MOVEFILE_DELAY_UNTIL_REBOOT = 4,
MOVEFILE_WRITE_THROUGH = 8
}


///
/// Marks the file for deletion during next system reboot
///
///
The current name of the file or directory on the local computer.
///
The new name of the file or directory on the local computer.
///
MoveFileFlags
/// bool
/// MoveFileEx function (Windows)
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll",EntryPoint="MoveFileEx")]
internal static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName,
MoveFileFlags dwFlags);

//Usage for marking the file to delete on reboot
MoveFileEx(fileToDelete, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);The file is marked for deletion in registry in following location
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerPendingFileRenameOperations

I hope this helps and if anyone else can correct or add to this it would be appreciated.
 
What's confusing is why it takes just as long doing it on SSD ?
The only difference an SSD makes compared to a HDD is the reads into RAM are faster and the writes back to the disk; once in RAM(which is even faster) the CPU still needs to process everything put the new values back in RAM and then it all must be placed in the correct folders. When I first installed windows 8.1 on the HDD that came with my Lenovo the updated it, then upgraded to 8.1 update I had some 120 updates. But then (here I feel I was smart) I made my recovery usb then migrated to my 840 pro ssd. After I set up RAPID Mode(a super speed boost that uses that new algorithm that some University created a couple of years ago) and installed, what I needed to install, I then cleaned everything up using disk cleanup. I started it 3 hours before going to work and had to set my machine to not sleep. when I came home it was finished. Reboot! Now when I do the Update cleanup(1 week after Patch Tuesday), it only takes about 1 coffee, or maybe a shower and shave to finish, then I optimize my disk using Samsung Magician). It goes fast as long as Maintenance doesn't kick in(which is also very CPU active)
Go to Task Manager > Details> click CPU, then run Disk Cleanup as administrator, while it's running right click cleanmgr.exe and analyze wait chain to see a little of what is going on in the background and what is waiting for CPU time.It doesn't matter how powerful your cpu is, it has to do with the threads and what order the process need to be done.I don't have process explorer but I bet it would give a better view of what's going on. That with an ssd has really very little to do with it, just like media and data files(even USING programs) have no speed increase on an ssd, only the opening of a program( which then loads into RAM) is speed up, or copying/transferring files.
 
Just started diskcleanup, took only 2 minutes to open and another 2 to get to system files cleanup. Less than 2 minutes to find Updates and get ready to clean. Now I'll see how long that would take. 56MB of updates to clean.
Update.
Just finished, 11 minutes for cleaning part. Wander if it has something to do with last updates, used to take almost an hour before ?
 
All I know is it took over 2 hours to complete Windows Update Cleanup. :(
Last time I ran it was 2 weeks ago, usually I wait 1 week, but I just did to time it and it only took 2 minutes after the reboot it did leave 7MB in windows update, but when I wait 1 week it's usually 0MB for me. It probably has to do with the pendingfilerename operation and timestamping. I just downloaded Process Explorer too. But with that I'm just a beginner so I'll only use it to "view and not do" till I go to MajorGeeks and study their Using sysinternals geek school.
 
Just installed about 100 updates on 8.1 and they took about 7GB space.
But soon after i was done with installation, "System Modules Installer Worker" became active again in task manager. This time it wasn't checking for/installing any updates. It was cleaning up and i didn't touch disk cleanup at all. :)
It went on for about 2.5 hours using about 20% of CPU and gave 4GB space back.
And still in Disk cleanup, there are still 500MB left to reclaim if i want.
I don't remember 7 being so generous.
 
That must of been the Automatic Maintenance(one of the best features of windows 8.1 other than File Explorer) cleaning out the language packs that won't be needed and the installers...etc. I keep telling people "let windows take care of windows, and you'll have less problems".
 
That must of been the Automatic Maintenance(one of the best features of windows 8.1 other than File Explorer) cleaning out the language packs that won't be needed and the installers...etc. I keep telling people "let windows take care of windows, and you'll have less problems".
That's it, all those other "cleaners" can make a mess.
 
Hi Cliff, your clarifications on prolonged Disk Cleanup task is convincing. However, I am not sure if it should take over 4 hours that it for my system today. Moreover, I am going to replace my HDD on my HP 15-r063tu Notebook soon, as the HGST 500Gb HDD inside is failing (Short DST fails, and Windows seems to hang of n on, despite reinstalling OS thru Recovery Media a few days back). Some forum members have suggested that I get an SSD (Samsung 850 EVO 250Gb mostly suggested), instead of a regular HDD. I am keen to upgrade RAM from 4Gb to 8Gb as well.
My query is, that I noticed the last time I reinstalled Windows 8.1 64-bit through Recovery Media/Partition, it listed over 100 Critical Updates for Windows and another 120+ "Recommended Updates". In a hurry, I updated all, which was over 2Gb and took many hours to finish. So, when I replace my HDD, and reinstall Win'8.1 afresh, should I just install the Critical Updates for Windows, or should I also update all the Recommended Updates ?
My assumption is that the more Windows Updates I install, the longer it will take whenever I run Disk Clean-up (including System Files Clean-up). And as per your earlier posts, having an SSD instead of a HDD won't speed up this process much.
 
Thanks @Cliff. I have got the RAM upgraded from 4Gb to 8Gb by adding a Corsair 4Gb one of same specs. Has improved speed of opening apps, but not noticeable in booting or shutdown. Of course the Task Manager used to show RAM usage of over 90% when all three web browsers were open - IE. FF, and Chrome. Now thats dropped to about 40% or so. So, switching between programs is much smoother now.
Next, is to replace my failing HGST HDD with a new HDD or SSD. SSDs are much more costly so yet to decide. Compared with a 500Gb 5400rpm 6Mb cache laptop HDD, how much faster would a Samsung 850 EVO SSD with 250Gb capacity would be ?
 
right and??? so it would be faster on an SSD.. and slower on a spinning hard drive..

yes.. ? perhaps I mis-read this posting in general..



ok here is why I said what i said!

And as per your earlier posts, having an SSD instead of a HDD won't speed up this process much.

Sorry I misunderstood, It could be auto-maintenance already to care of it in the mean time.
Thanks @Cliff. I have got the RAM upgraded from 4Gb to 8Gb by adding a Corsair 4Gb one of same specs. Has improved speed of opening apps, but not noticeable in booting or shutdown. Of course the Task Manager used to show RAM usage of over 90% when all three web browsers were open - IE. FF, and Chrome. Now thats dropped to about 40% or so. So, switching between programs is much smoother now.
Next, is to replace my failing HGST HDD with a new HDD or SSD. SSDs are much more costly so yet to decide. Compared with a 500Gb 5400rpm 6Mb cache laptop HDD, how much faster would a Samsung 850 EVO SSD with 250Gb capacity would be ?
Good to here the additional RAM is helping. an SSD would definitely be better if you could wait and save up.
 
Thanks Cliff. Sure, am saving up for an SSD, which I understand is "much faster" than a regular HDD, though it would help if someone can share a comparison chart of the same :-)
 
Average SSD (One of mine)
Velox 70-empty.JPG

Western digital Green 750GB HDD (one of mine )

WD750G HDD.JPG
To say nothing about access time which is about 1000 times faster with SSD.
 
Back
Top