2

I understand the concept behind TRIM. I know you can schedule TRIM through the "optimization schedule" part of "defragment and optimize drives". But does Windows send a TRIM command every time you delete a file for the file(s) deleted? Or is this only managed by a scheduled or manual run TRIM event?

2 Answers 2

2

A block isn't only deleted/unused when you delete a file but may also when you do things like update some metadata or write new data to the file. Sending a TRIM command after every block deletion would create so many unnecessary IO traffic and overhead. Besides delaying the trim allows the OS to consolidate multiple blocks to unmap into a single command. Therefore I don't believe Windows do that on every delete, although I haven't been able to fully verify if that's true or not. I can see the retrim information in Windows but I'm not sure if it's just some weird wording of trim or it's some kind of full trim or anything else

To check the last retrim you can open defragmenter which will optimize the disk by defragmenting and trim as needed

Defragmenter

You can also check the full retrim history from the Windows Event log

PS C:\Users\> Get-EventLog -LogName Application -Message *trim* | select TimeWritten,Message

TimeWritten            Message                                                               
-----------            -------                                                               
06/10/2022 8:43:15 CH  The storage optimizer successfully completed retrim on Data (D:)      
06/10/2022 8:39:06 CH  The storage optimizer successfully completed retrim on Windows 11 (C:)
28/09/2022 8:21:33 SA  The storage optimizer successfully completed retrim on Data (D:)      
28/09/2022 12:54:52 SA The storage optimizer successfully completed retrim on Windows 11 (C:)
21/09/2022 9:47:18 SA  The storage optimizer successfully completed retrim on Data (D:)      
21/09/2022 9:47:18 SA  The storage optimizer successfully completed retrim on Windows 11 (C:)
21/09/2022 9:15:48 SA  The storage optimizer successfully completed retrim on Data (D:)      
20/09/2022 11:57:24 CH The storage optimizer successfully completed retrim on Windows 11 (C:)
15/09/2022 12:52:43 SA The storage optimizer successfully completed retrim on Data (D:)      
15/09/2022 12:52:42 SA The storage optimizer successfully completed retrim on Windows 11 (C:)
08/09/2022 12:25:19 SA The storage optimizer successfully completed retrim on Windows 11 (C:)
01/09/2022 12:05:08 SA The storage optimizer successfully completed retrim on Data (D:)      
01/09/2022 12:04:55 SA The storage optimizer successfully completed retrim on Windows 11 (C:)
24/08/2022 7:53:48 CH  The storage optimizer successfully completed retrim on Data (D:)      
24/08/2022 7:53:48 CH  The storage optimizer successfully completed retrim on Windows 11 (C:)
17/08/2022 8:35:33 SA  The storage optimizer successfully completed retrim on Data (D:)      
17/08/2022 8:35:32 SA  The storage optimizer successfully completed retrim on Windows 11 (C:)
13/08/2022 9:34:58 SA  The storage optimizer successfully completed retrim on Data (D:)      
13/08/2022 9:34:57 SA  The storage optimizer successfully completed retrim on Windows 11 (C:)
10/08/2022 11:14:44 CH The storage optimizer successfully completed retrim on Windows 11 (C:)
03/08/2022 8:03:00 SA  The storage optimizer successfully completed retrim on Data (D:)      
03/08/2022 8:02:32 SA  The storage optimizer successfully completed retrim on Windows 11 (C:)
27/07/2022 10:07:25 CH The storage optimizer successfully completed retrim on Data (D:)      
27/07/2022 10:07:24 CH The storage optimizer successfully completed retrim on Windows 11 (C:)
21/07/2022 9:46:18 SA  The storage optimizer successfully completed retrim on Data (D:)      
21/07/2022 9:46:18 SA  The storage optimizer successfully completed retrim on Windows 11 (C:)
13/07/2022 8:36:07 CH  The storage optimizer successfully completed retrim on Data (D:)      
13/07/2022 8:36:06 CH  The storage optimizer successfully completed retrim on Windows 11 (C:)
12/07/2022 11:14:47 CH The storage optimizer successfully completed retrim on Data (D:)      
12/07/2022 11:14:46 CH The storage optimizer successfully completed retrim on Windows 11 (C:)
30/06/2022 10:14:20 SA The storage optimizer successfully completed retrim on Data (D:)      
30/06/2022 10:10:56 SA The storage optimizer successfully completed retrim on Windows 11 (C:)

As you can see, sometimes the retrims are only 1 day from each other, but sometimes 10 days or 2 weeks. Sometimes only 1 drive is trimmed but sometimes 2. Windows will automatically determine how much it needs to trim

You can also run Optimize-Volume -DriveLetter C -ReTrim to force a manual retrim

See also How often do windows and mac run the trim command and therefore when will a deleted file become unrecoverable?

2
  • Note that the presented Get-EventLog command only works on English systems. Therefore it would be better to use event source and event IDs (e.g. 258?) for filtering.
    – Robert
    Commented Oct 11, 2022 at 17:51
  • Yes, the Trim command sent with every delete causes heavy IO. So heavy that sometimes Trim commands are dropped. Hence the need for occasional Retrim commands, which handle the lost trimming.
    – user165568
    Commented Jul 7 at 0:39
3

AFAIK the answer is yes. My own experiments seem to suggest this too: If I scan for deleted files almost immediately after deletion, files can be recovered but are zero-filled. Scenario was simple enough to try yourself: create folder > stuff twenty or so files in there > select them > press DEL while holding SHIFT. Check files using R-Studio, you do not even have to recover them, simply check contents in HEX view.

This video shows the experiment using DMDE: https://youtu.be/NyLQbxnPurc - The trimmed files are detected by are filled with zeros.

Files are recoverable as file system entries themselves are not 'trimmed', so unless file system entry is re-used, it is easy for undelete type tools to 'find' them. Many such tools will even flag such as files green or condition 'excellent' as long as the clusters previously allocated to the file are still un-used. In reality such recovered files will be useless.

Experiments from others confirm my findings, example: https://youtu.be/hzClnwGeJUM.

Of course it is assumed TRIM at OS level is enabled.

enter image description here

Even IF enabled like in above example, there's scenarios in which TRIM may not 'fire' or it may fire but the command(s) may be dropped from queue after some host initiated reset for example. I have also seen occurrences of deleted data not being trimmed due to for example certain file system inconsistencies: For example, the NTFS $Bitmap tracks used vs. free clusters and I can imagine if the file system driver deems this file inconsistent, it may withhold from sending TRIM commands even until the issue is corrected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .