Windows 8 and 8.1 Forums


Answer: Why it can take Disk Cleanup so long

  1. #1



    Trying to Sith things out
    Bamberg Germany
    Posts : 2,213
    Windows 10 Pro 64 bit

    Answer: Why it can take Disk Cleanup so long


    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.

      My System SpecsSystem Spec

  2. #2


    What's confusing is why it takes just as long doing it on SSD ?
      My System SpecsSystem Spec

  3. #3



    Trying to Sith things out
    Bamberg Germany
    Posts : 2,213
    Windows 10 Pro 64 bit


    Quote Originally Posted by CountMike View Post
    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.
      My System SpecsSystem Spec

  4. #4


    Harrisonburg, Va.
    Posts : 10,488
    Windows 8.1.1 Pro with Media Center


    All I know is it took over 2 hours to complete Windows Update Cleanup.
      My System SpecsSystem Spec

  5. #5


    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 ?
      My System SpecsSystem Spec

  6. #6



    Trying to Sith things out
    Bamberg Germany
    Posts : 2,213
    Windows 10 Pro 64 bit


    Quote Originally Posted by David Bailey View Post
    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.
      My System SpecsSystem Spec

  7. #7


    How-To Geek - For Geeks, By Geeks. has some stuff about them too.
      My System SpecsSystem Spec

  8. #8



    Trying to Sith things out
    Bamberg Germany
    Posts : 2,213
    Windows 10 Pro 64 bit


    Quote Originally Posted by CountMike View Post
    How-To Geek - For Geeks, By Geeks. has some stuff about them too.
    Thanks I meant How-to-Geek. oops!
      My System SpecsSystem Spec

  9. #9


    Posts : 36
    Windows 8.1 Enterprise x64


    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.
      My System SpecsSystem Spec

  10. #10



    Trying to Sith things out
    Bamberg Germany
    Posts : 2,213
    Windows 10 Pro 64 bit


    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".
      My System SpecsSystem Spec

Page 1 of 3 123 LastLast
Answer: Why it can take Disk Cleanup so long

Similar Threads
Thread Forum
Disk Cleanup hangs trying to do 'Windows Update Cleanup'.
I'm running 8.1 with all updates on, supposedly. In Control Panel, Troubleshooting, System & Security, Fix Problems with Windows Update, Advanced, Run as Administrator: It says it fixed the problem (whatever that may be). I rerun it. It says it fixed the problem. This goes on ad infinitum. It...
Windows Updates & Activation
Disk Cleanup Stuck With Windows Update Cleanup With SSD
Well, as the title suggests, I'm having an issue with Disk Cleanup with a new SSD I recently purchased. In all my years with HDDs I never had this problem. I've been running Windows 8.1 with an HDD for over a year now with no such problem so this is quite new & odd to me. The Windows Update Cleanup...
Performance & Maintenance
win 8 disk cleanup
When I ran my disk clean up for the system, it reflected "Windows update cleanup" at 106 mb. I feel sure it is left overs from my recent upgrade to win 8. To be sure though, is it ok to "erase" in the System clean up? walex
Performance & Maintenance
Disk Cleanup Method
I tried the instructions here--- https://www.eightforums.com/tutorials/44274-windows-update-cleanup-windows-8-a.html I followed the instructions for Win 8 & the cleanup took less than a minute. Hope someone finds this useful. :)
Windows Updates & Activation
Disk Cleanup Not Deleting Files
I recently ran a Disk Cleanup as part of my regular maintenance on my new computer. It had over 2.18GB of files to cleanup. That seemed a little high considering I run it every week to 2 weeks. It said it deleted all the files. I ran the Scan Disk again to be sure and it still had 2.18GB of files....
Performance & Maintenance
Disk Cleanup Fail
Hi guys, This seems to be a common problem but the solutions are pretty lame and don't do anything. When I run disk cleanup (system files) I get 6.60GB under System queued windows error reporting. Of course disk cleanup just hangs (at least it was still hanging after an hour and a half). I...
Performance & Maintenance
Disk Cleanup Question
I was going through doing a disk cleanup and ran across the options to delete "Debug Dump Files" and System error memory dump files" boh of wich hold 758MB ...are these safe to delete during disk cleanup or should I leave them alone? Probably a dumb question on my part but never hurts to ask. ...
Performance & Maintenance
Eight Forums Android App Eight Forums IOS App Follow us on Facebook