35

Just a curiosity question. Disk Cleanup has been spending 100% of one of my cores for quite a while and still going. Seems to be spending a lot of time especially on Windows Update Cleanup.

Can't quite understand why deleting files should be such an intensive activity. Especially since it already spent quite a lot of time calculating what it could delete.

Why does Disk Cleanup take so much time and cpu? What does it do that is so intensive?

Two of four cores maxed out

SushiGuy
  • 111
Svish
  • 41,258

8 Answers8

24

Windows compresses the WinSxS folder by removing replaced updates ad compressing files which can't be uninstalled and which are not used into diffs. This takes a lot of CPU power and thats why you see a high CPU usage.

You can analyze the CPU usage with xperf/WPA to verify this.

5

I can confirm that Windows Updates Cleanup takes almost 100% CPU usage, it's all about WinSxS compression and reintegration of updates:

Windows Cleanup 100% CPU usage

I started cleanup first time after Windows install and it took 2 hours to finish 50%. From graph you can see, that at first lot of reading of small files from disk (second graph), and after 100% CPU usage for compression, and so on.

Arunas Bart
  • 1,766
4

One way to mitigate this problem and speed up the "Windows Update Cleanup" phase of "Disk Cleanup" a bit is to temporarily set a higher priority for the TiWorker.exe process for the duration of the so-called 'cleanup' activity.

In the Task Manager 'Details' pane, find TiWorker.exe and right-click to show a pop-up menu. For 'Set Priority," choose "Above Normal," or even "High." For me, this increased the TiWorker CPU activity--from averaging around 16%--up to its full potential of 25% (on a 4-core machine).

enter image description here

Aside from the miniscule speedup--and possibly good feeling of accomplishment--this provides, there's little that can be done since apparently "Windows Update Cleanup" is coded in a way that, for some unknown reason, proceeds file-by-file, making the overall work horribly disk-bound.

And also, do know that the process is most probably not hung, and will indeed complete someday. To verify this (and to yet further distract yourself during this annoying wait time), you can check the 'Disk Activity' section of Resource Monitor (run "resmon.exe").

1

Raymond Chen of The Old New Thing posted an explanation of this, particularly with respect to the Windows Update Cleanup.

https://devblogs.microsoft.com/oldnewthing/20200922-00/?p=104252

Basically what's going on is a deep clean to remove components that are no longer referenced. This happens on a normal maintenance schedule but the Disk Cleanup bypasses the maintenance window and a self-imposed time limit.

Windows Update Cleanup also checks to see if the system will benefit from compression of system files. The compression algorithm used for this is designed so that decompression is fast but at the expense of using lots of CPU time to do the compression.

The expensive data compression is what is taking up the CPU and contributing to the long times to clean up disk space.

1

Deleting 20 files of 5mb in size will take more time to delete than 10 files of 64mb in size. This is because when system deletes files, it doesn't really delete them (as empty space on a drive can be made of "noise" bits) but just overwrites the front part that says, "A file starts here" with gibberish and then it will happily overwrite that and the following parts later when you want to use the space. In reality, deleting is the same as writing otherwise.

The thing with disk cleanup, is the things it cleans are usually LOTS of small files (internet cookies, temporary files, etc.). As such, it does a lot more writing to the disk than a lot of other things, and can take as much time as installing something new, due to the volume being written to disk.

lilHar
  • 169
0

Another word of warning: part of what takes up the time is that, when cleaning up WinSxS, Disk Clean-up has first to uncompress a lot of files. So disk usage actually increases for the first part of the clean-up!

JonP
  • 103
0

I also wondered this. But I left the disk cleanup running. It took more than 2 days to complete.

TiWorker.exe consumed 53 h CPU. The disk cleanup tool was able to free 33 GB of disk space mainly from C:\Windows\WinSxS. (Windows 2019 virtual machine with 2 cores and 4 GB memory).

-3

Another way to speed up the process is to run the Disk Cleanup for about 5 min. Stop it, then re-start it, and it will whizz through in a jiffy! Also, De-Fragging or Optimizing your HDD/SSD beforehand will speed things up, just remember to de-frag/Optz it again after cleanup.