Windows 每次删除时都会发送 TRIM 命令吗?

Windows 每次删除时都会发送 TRIM 命令吗?

我理解 TRIM 背​​后的概念。我知道您可以通过“碎片整理和优化驱动器”中的“优化计划”部分来安排 TRIM。但是每次删除文件时,Windows 是否会为已删除的文件发送 TRIM 命令?还是这仅由计划或手动运行的 TRIM 事件管理?

答案1

块不仅在您删除文件时被删除/未使用,而且在您执行更新某些元数据或将新数据写入文件等操作时也可能会删除/未使用块。每次删除块后发送 TRIM 命令会产生大量不必要的 IO 流量和开销。此外,延迟修剪允许操作系统将多个块合并为一个命令以取消映射。因此,我不相信 Windows 在每次删除时都会这样做,尽管我无法完全验证这是否属实。我可以在 Windows 中看到重新修剪信息,但我不确定它只是一些奇怪的修剪措辞,还是某种完整的修剪或其他什么

要检查上次重新修剪,您可以打开碎片整理程序,它将通过以下方式优化磁盘根据需要进行碎片整理和修剪

碎片整理程序

您还可以从 Windows 事件日志中检查完整的重新修剪历史记录

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:)

如您所见,有时重新修剪间隔仅 1 天,但有时间隔 10 天或 2 周。有时只修剪 1 个驱动器,但有时修剪 2 个。Windows 将自动确定需要修剪多少

您还可以Optimize-Volume -DriveLetter C -ReTrim运行强制手动重新修剪

也可以看看Windows 和 Mac 多久运行一次 trim 命令,因此何时已删除的文件将无法恢复?

答案2

据我所知,答案是肯定的。我自己的实验似乎也表明了这一点:如果我在删除后立即扫描已删除的文件,文件可以恢复,但会填充零。场景很简单,您可以自己尝试一下:创建文件夹 > 在其中塞入二十个左右的文件 > 选择它们 > 按住 SHIFT 键并按 DEL。使用 R-Studio 检查文件,您甚至不必恢复它们,只需在 HEX 视图中检查内容即可。

由于文件系统条目本身没有被“修剪”,因此文件是可恢复的,因此除非文件系统条目被重新使用,否则恢复删除类型的工具很容易“找到”它们。许多此类工具甚至会将文件标记为绿色或状态为“优秀”,只要先前分配给文件的簇仍未使用。实际上,这种恢复的文件将毫无用处。

其他人的实验证实了我的发现,例如: https://youtu.be/hzClnwGeJUM

当然,假设操作系统级别的 TRIM 已启用。

在此处输入图片描述

即使像上例一样启用了 IF,也存在 TRIM 可能不会“触发”或触发但从队列中删除的情况。我曾见过由于某些文件系统不一致等原因而未修剪已删除数据的情况。

相关内容