windows-ssd_真实而完整的故事-Windows是否对您的SSD进行碎片整理?

windows-ssd

windows-ssd

There has been a LOT of confusion around Windows, SSDs (hard drives), and whether or not they are getting automatically defragmented by automatic maintenance tasks in Windows.

关于Windows,SSD(硬盘驱动器)以及Windows中的自动维护任务是否对它们进行自动碎片整理,存在很多困惑。

There's a general rule of thumb or statement that "defragging an SSD is always a bad idea." I think we can agree we've all heard this before. We've all been told that SSDs don't last forever and when they die, they just poof and die. SSDs can only handle a finite number of writes before things start going bad. This is of course true of regular spinning rust hard drives, but the conventional wisdom around SSDs is to avoid writes that are perceived as unnecessary.

有一条一般的经验法则或声明,即“对SSD进行碎片整理总是一个坏主意”。 我想我们可以同意,我们之前都听过。 我们都被告知,SSD不会永远持续下去,当它们死掉时,它们只会po不休。 固态硬盘开始变坏之前,它只能处理有限数量的写入。 常规旋转生锈的硬盘驱动器当然是这样,但是关于SSD的传统观点是避免写被认为是不必要的写操作。

Does Windows really defrag your SSD?

I've seen statements around the web like this:

我在网上看到这样的声明:

I just noticed that the defragsvc is hammering the internal disk on my machine.  To my understanding defrag provides no value add on an SSD and so is disabled by default when the installer determines the disk is SSD.  I was thinking it could be TRIM working, but I thought that was internal to the SSD and so the OS wouldn’t even see the IO.

我只是注意到defragsvc正在锤打机器上的内部磁盘。 据我了解,碎片整理没有在SSD上提供任何附加值,因此在安装程序确定磁盘为SSD时默认情况下处于禁用状态。 我以为可能是TRIM工作,但是我认为这是SSD的内部功能,因此OS甚至看不到IO。

One of the most popular blog posts on the topic of defrag and SSDs under Windows is by Vadim Sterkin. Vadim's analysis has a lot going on. He can see that defrag is doing something, but it's not clear why, how, or for how long. What's the real story? Something is clearly running, but what is it doing and why?

Vadim Sterkin是Windows下有关碎片整理和SSD的最受欢迎的博客文章之一。 Vadim的分析正在进行中。 他可以看到碎片整理正在做某事,但不清楚原因,方式或持续时间。 真实的故事是什么? 显然正在运行,但是它在做什么,为什么?

I made some inquiries internally, got what I thought was a definitive answer and waded in with a comment. However, my comment, while declarative, was wrong.

我在内部进行了一些查询,得到了我认为是确定的答案,并加入了评论。 但是,我的评论虽然是声明性的,但却是错误的

Windows doesn’t defrag SSDs. Full stop. If it reports as an SSD it doesn’t get defraged, no matter what. This is just a no-op message. There’s no bug here, sorry. - Me in the Past

Windows不会对SSD进行碎片整理。 句号如果报告为SSD,则无论如何都不会损坏。 这只是一条禁止操作的消息。 很抱歉,这里没有错误。 -我过去

I dug deeper and talked to developers on the Windows storage team and this post is written in conjunction with them to answer the question, once and for all

我更深入地研究了Windows存储团队的开发人员,并与他们共同撰写了这篇文章,一劳永逸地回答了这个问题。

“与SSD,Windows和Defrag的交易如何,更重要的是Windows是否在做正确的事情?” ("What's the deal with SSDs, Windows and Defrag, and more importantly, is Windows doing the RIGHT THING?")

It turns out that the answer is more nuanced than just yes or no, as is common with technical questions.

事实证明,答案比技术问题中常见的“是”或“不是”更为细微。

The short answer is, yes, Windows does sometimes defragment SSDs, yes, it's important to intelligently and appropriately defrag SSDs, and yes, Windows is smart about how it treats your SSD.

简短的答案是,是的,Windows有时会对SSD进行碎片整理,是的,对智能和适当地对SSD进行碎片整理很重要,是的,Windows在如何对待SSD方面很聪明。

The long answer is this.

长答案是这个。

Actually Scott and Vadim are both wrong. Storage Optimizer will defrag an SSD once a month if volume snapshots are enabled. This is by design and necessary due to slow volsnap copy on write performance on fragmented SSD volumes. It’s also somewhat of a misconception that fragmentation is not a problem on SSDs. If an SSD gets too fragmented you can hit maximum file fragmentation (when the metadata can’t represent any more file fragments) which will result in errors when you try to write/extend a file. Furthermore, more file fragments means more metadata to process while reading/writing a file, which can lead to slower performance.

实际上,斯科特和瓦迪姆都是错的。 如果启用了卷快照,Storage Optimizer将每月对SSD进行一次碎片整理。 这是设计使然,并且由于在分散的SSD卷上写入性能上的慢速Volsnap复制而有必要。 碎片不是SSD的问题,这也有点误解。 如果SSD碎片过多,您可能会遇到最大的文件碎片(当元数据不能代表更多文件碎片时),这将在您尝试写入/扩展文件时导致错误。 此外,更多的文件碎片意味着在读写文件时需要处理更多的元数据,这可能导致性能降低。

As far as Retrim is concerned, this command should run on the schedule specified in the dfrgui UI. Retrim is necessary because of the way TRIM is processed in the file systems. Due to the varying performance of hardware responding to TRIM, TRIM is processed asynchronously by the file system. When a file is deleted or space is otherwise freed, the file system queues the trim request to be processed. To limit the peek resource usage this queue may only grow to a maximum number of trim requests. If the queue is of max size, incoming TRIM requests may be dropped. This is okay because we will periodically come through and do a Retrim with Storage Optimizer. The Retrim is done at a granularity that should avoid hitting the maximum TRIM request queue size where TRIMs are dropped.

就Retrim而言,此命令应按dfrgui UI中指定的计划运行。 由于文件系统中TRIM的处理方式,必须进行重整。 由于响应TRIM的硬件性能各异,因此TRIM由文件系统异步处理。 当删除文件或以其他方式释放空间时,文件系统会将修剪请求排队等待处理。 为了限制监视资源的使用,此队列只能增加到最大修剪请求数。 如果队列的大小最大,则可能会丢弃传入的TRIM请求。 可以,因为我们会定期进行操作并使用Storage Optimizer进行重新整理。 重新整理的粒度应避免达到丢弃TRIM的最大TRIM请求队列大小。

Wow, that's awesome and dense. Let's tease it apart a little.

哇,棒极了! 让我们来梳理一下。

When he says volume snapshots or "volsnap" he means the Volume Shadow Copy system in Windows. This is used and enabled by Windows System Restore when it takes a snapshot of your system and saves it so you can rollback to a previous system state. I used this just yesterday when I install a bad driver. A bit of advanced info here - Defrag will only run on your SSD if volsnap is turned on, and volsnap is turned on by System Restore as one needs the other. You could turn off System Restore if you want, but that turns off a pretty important safety net for Windows.

当他说卷快照或“ volsnap”时,是指Windows中的卷影复制系统。 Windows System Restore在为其拍摄系统快照并保存它时可以使用并启用它,以便可以回滚到以前的系统状态。 昨天我在安装错误的驱动程序时使用了此功能。 这里有一些高级信息-Defrag仅在打开volsnap时才在您的SSD上运行,并且当一个系统需要另一个时,volumenap由系统还原打开。 您可以根据需要关闭“系统还原”,但这将关闭Windows的一个非常重要的安全网。

One developer added this comment, which I think is right on.

一位开发人员添加了此评论,我认为这是正确的。

I think the major misconception is that most people have a very outdated model of disk\file layout, and how SSDs work.

我认为主要的误解是,大多数人对磁盘\文件布局以及SSD的工作方式都非常过时。

First, yes, your SSD will get intelligently defragmented once a month. Fragmentation, while less of a performance problem on SSDs vs traditional hard drives is still a problem. SSDS *do* get fragmented.

首先,是的,您的SSD将每月进行一次智能碎片整理。 尽管与传统硬盘相比,固态硬盘上的性能问题较少,但碎片仍然是一个问题。 SSDS *会碎片化。

It's also worth pointing out that what we (old-timers) think about as "defrag.exe" as a UI is really "optimize your storage" now. It was defrag in the past and now it's a larger disk health automated system.

还值得指出的是,作为UI的我们(旧用户)现在认为的是“ defrag.exe”,实际上是在“优化存储”。 过去是碎片整理,现在是更大的磁盘运行状况自动化系统。

Additionally, there is a maximum level of fragmentation that the file system can handle. Fragmentation has long been considered as primarily a performance issue with traditional hard drives. When a disk gets fragmented, a singular file can exist in pieces in different locations on a physical drive. That physical drive then needs to seek around collecting pieces of the file and that takes extra time.

此外,文件系统可以处理最大程度的碎片。 长期以来,碎片化一直被认为是传统硬盘驱动器的主要性能问题。 磁盘碎片化后,单个文件可能会分散存在于物理驱动器上的不同位置。 然后,该物理驱动器需要四处寻找文件碎片,这需要花费额外的时间。

This kind of fragmentation still happens on SSDs, even though their performance characteristics are very different. The file systems metadata keeps track of fragments and can only keep track of so many. Defragmentation in cases like this is not only useful, but absolutely needed.

尽管SSD的性能特征非常不同,但这种碎片仍然会在SSD上发生。 文件系统元数据跟踪片段,并且只能跟踪这么多片段。 在这种情况下进行碎片整理不仅有用,而且绝对必要。

SSDs also have the concept of TRIM. While TRIM (retrim) is a separate concept from fragmentation, it is still handled by the Windows Storage Optimizer subsystem and the schedule is managed by the same UI from the User's perspective. TRIM is a way for SSDs to mark data blocks as being not in use. Writing to empty blocks on an SSD is faster that writing to blocks in use as those need to be erased before writing to them again. SSDs internally work very differently from traditional hard drives and don't usually know what sectors are in use and what is free space. Deleting something means marking it as not in use. TRIM lets the operating system notify the SSD that a page is no longer in use and this hint gives the SSD more information which results in fewer writes, and theoretically longer operating life. 

SSD也具有TRIM的概念。 尽管TRIM(retrim)是与碎片分离的独立概念,但从用户的角度来看,它仍由Windows Storage Optimizer子系统处理,并且时间表由同一UI管理。 TRIM是SSD可以将数据块标记为未使用的一种方式。 写入SSD上的空块比写入正在使用的块要快,因为在再次写入之前需要擦除这些块。 SSD的内部工作方式与传统硬盘完全不同,并且通常不知道正在使用哪些扇区以及什么是可用空间。 删除某些内容意味着将其标记为未使用。 TRIM使操作系统可以通知SSD不再使用页面,并且此提示可为SSD提供更多信息,从而减少写入次数,并在理论上延长使用寿命。

In the old days, you would sometimes be told by power users to run this at the command line to see if TRIM was enabled for your SSD. A zero result indicates it is.

在过去,有时超级用户会告诉您在命令行运行此命令,以查看是否为您的SSD启用了TRIM。 结果为零表示是。

fsutil behavior query DisableDeleteNotify

However, this stuff is handled by Windows today in 2014, and you can trust that it's "doing the right thing." Windows 7, along with 8 and 8.1 come with appropriate and intelligent defaults and you don't need to change them for optimal disk performance. This is also true with Server SKUs like Windows Server 2008R2 and later.

但是,这些内容已在2014年的Windows上得到处理,您可以相信它在“做正确的事”。 Windows 7、8和8.1带有适当的智能默认值,您无需更改它们即可获得最佳磁盘性能。 对于服务器SKU(例如Windows Server 2008R2和更高版本)也是如此。

结论 (Conclusion)

No, Windows is not foolishly or blindly running a defrag on your SSD every night, and no, Windows defrag isn't shortening the life of your SSD unnecessarily. Modern SSDs don't work the same way that we are used to with traditional hard drives.

不,Windows并非每天晚上都在愚蠢或盲目地对SSD进行碎片整理,并且不,Windows碎片整理不会不必要地缩短SSD的寿命。 现代SSD的工作方式与传统硬盘不同。

Yes, your SSD's file system sometimes needs a kind of defragmentation and that's handled by Windows, monthly by default, when appropriate. The intent is to maximize performance and a long life. If you disable defragmentation completely, you are taking a risk that your filesystem metadata could reach maximum fragmentation and get you potentially in trouble.

是的,您的SSD的文件系统有时需要进行某种碎片整理,并且Windows会在适当的情况下默认每月进行一次碎片整理。 目的是最大程度地提高性能并延长使用寿命。 如果完全禁用碎片整理,则可能会导致文件系统元数据可能达到最大碎片的风险,并可能给您带来麻烦。

相关链接 (Related Links)

* photo by Simon Wüllhorst, used under CC BY 2.0.

*图片由SimonWüllhorst摄,在CC BY 2.0下使用。

翻译自: https://www.hanselman.com/blog/the-real-and-complete-story-does-windows-defragment-your-ssd

windows-ssd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值