为什么清空磁盘空间会加快计算机的速度?

当你更多地了解计算机及其工作原理时,你偶尔会碰到一些似乎毫无意义的事情。考虑到这一点,清空磁盘空间真的会加速计算机吗?今天的超级用户问答帖子回答了一位困惑的读者的问题。...

为什么清空磁盘空间会加快计算机的速度?

当你更多地了解计算机及其工作原理时,你偶尔会碰到一些似乎毫无意义的事情。考虑到这一点,清空磁盘空间真的会加速计算机吗?今天的超级用户问答帖子回答了一位困惑的读者的问题。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

屏幕截图由nchenga(Flickr)提供。

问题

超级用户阅读器Remi.b想知道为什么清空磁盘空间似乎可以加速计算机:

I have been watching a lot of videos and now understand how computers work a bit better. I understand what RAM is, about volatile and non-volatile memory, and the process of swapping. I also understand why increasing RAM speeds up a computer.

What I do not understand is why cleaning up disk space seems to speed a computer up. Does it really speed a computer up? If so, why does it do so?

Does it have something to do with searching for memory space to save things or with moving things around to make a long enough continuous space to save something? How much empty space should I leave free on a hard disk?

为什么清空磁盘空间似乎可以加快计算机的速度?

答案

超级用户贡献者Jason C为我们提供了答案:

“Why does emptying disk space speed up computers?”

It does not, at least not on its own. This is a really common myth. The reason it is a common myth is because filling up your hard drive often happens at the same time as other things that traditionally could slow down your computer (A). SSD performance does tend to degrade as they fill, but this is a relatively new issue, unique to SSDs, and is not really noticeable for casual users. Generally, low free disk space is just a red herring.

For example, things like:

1. File fragmentation. File fragmentation is an issue (B), but lack of free space, while definitely one of many contributing factors, is not the only cause of it. Some key points here:

  • The chances of a file being fragmented are not related to the amount of free space left on the drive. They are related to the size of the largest contiguous block of free space on the drive (i.e. “holes” of free space), which the amount of free space happens to put an upper bound on. They are also related to how the file system handles file allocation (more below). C***ider: A drive that is 95 percent full with all the free space in one single contiguous block has zero percent chance of fragmenting a new file (C) (and the chance of fragmenting an appended file is independent of the free space). A drive that is five percent full but with data spread evenly over the drive has a very high chance of fragmentation.
  • Keep in mind that file fragmentation only affects performance when the fragmented files are being accessed. C***ider: You have a nice, defragmented drive that still has lots of free “holes” in it. A common scenario. Everything is running **oothly. Eventually, though, you get to a point where there are no more large blocks of free space remaining. You download a huge movie, the file ends up being severely fragmented. This will not slow down your computer. All of your application files and such that were previously fine will not suddenly become fragmented. This may make the movie take longer to load (although typical movie bit rates are so low compared to hard drive read rates that it will most likely be unnoticeable), and it may affect I/O-bound performance while the movie is loading, but other than that, nothing changes.
  • While file fragmentation is certainly an issue, often times the effects are mitigated by OS and hardware level buffering and caching. Delayed writes, read-ahead, strategies like the prefetcher in Windows, etc., all help reduce the effects of fragmentation. You generally do not actually experience significant impact until the fragmentation becomes severe (I would even venture to say that as long as your swap file is not fragmented, you will probably never notice).

2. Search indexing is another example. Say that you have automatic indexing turned on and an OS that does not handle this gracefully. As you save more and more indexable content to your computer (documents and such), indexing may take longer and longer and may start to have an effect on the perceived speed of your computer while it is running, both in I/O and CPU usage. This is not related to free space, it is related to the amount of indexable content you have. However, running out of free space goes hand in hand with storing more content, hence a false connection is drawn.

3. Anti-virus software (similar to the search indexing example). Say that you have anti-virus software set up to do background scanning of your drive. As you have more and more scannable content, the search takes more I/O and CPU resources, possibly interfering with your work. Again, this is related to the amount of scannable content you have. More content often equals less free space, but the lack of free space is not the cause.

4. Installed software. Say that you have a lot of software installed that loads when your computer boots, thus slowing down start-up times. This slow down happens because lots of software is being loaded. However, installed software takes up hard drive space. Therefore, hard drive free space decreases at the same time that this happens, and again a false connection can be readily made.

5. Many other examples along these lines which, when taken together, appear to closely associate lack of free space with lower performance.

The above illustrates another reason that this is such a common myth: While the lack of free space is not a direct cause of slow down, uninstalling various applicati***, removing indexed or scanned content, etc. sometimes (but not always; outside the scope of this answer) increases performance again for reas*** unrelated to the amount of free space remaining. But this also naturally frees up hard drive space. Therefore, again, an apparent (but false) connection between “more free space” and a “faster computer” can be made.

C***ider: If you have a machine running slowly due to lots of installed software, etc., clone your hard drive (exactly) to a larger hard drive, then expand your partiti*** to gain more free space, the machine will not magically speed up. The same software loads, the same files are still fragmented in the same ways, the same search indexer still runs, nothing changes despite having more free space.

“Does it have something to do with searching for memory space to save things?”

No. It does not. There are two very important things worth noting here:

1. Your hard drive does not search around to find places to put things. Your hard drive is stupid. It is nothing. It is a big block of addressed storage that blindly puts things where your OS tells it to and reads whatever is asked of it. Modern drives have sophisticated caching and buffering mechani**s designed around predicting what the OS is going to ask for based on the experience we have gained over time (some drives are even aware of the file system that is on them), but essentially, think of your drive as just a big dumb brick of storage with occasional bonus performance features.

2. Your operating system does not search for places to put things, either. There is no searching. Much effort has gone into solving this problem as it is critical to file system performance. The way that data is actually organized on your drive is determined by your file system. For example, FAT32 (old DOS and Windows PCs), NTFS (later editi*** of Windows), HFS+ (Mac), ext4 (some Linux systems), and many others. Even the concept of a “file” and a “directory” are merely products of typical file systems — hard-drives know nothing about the mysterious beasts called files. Details are outside the scope of this answer. But essentially, all common file systems have ways of tracking where the available space is on a drive so that a search for free space is, under normal circumstances (i.e. file systems in good health), unnecessary. Examples:

  • NTFS has a master file table, which includes the special files $Bitmap, etc., and plenty of meta data describing the drive. Essentially it keeps track of where the next free blocks are so that new files can be written directly to free blocks without having to scan the drive every time.
  • Another example: Ext4 has what is called the bitmap allocator, an improvement over ext2 and ext3 that basically helps it directly determine where free blocks are instead of scanning the list of free blocks. Ext4 also supports delayed allocation, that is, buffering of data in RAM by the OS before writing it out to the drive in order to make better decisi*** about where to put it to reduce fragmentation.
  • Many other examples.

“Or with moving things around to make a long enough continuous space to save something?”

No. This does not happen, at least not with any file system I am aware of. Files just end up fragmented.

The process of “moving things around to make up a long enough contiguous space for saving something” is called defragmenting. This does not happen when files are written. This happens when you run your disk defragmenter. On newer editi*** of Windows, at least, this happens automatically on a schedule, but it is never triggered by writing a file.

Being able to avoid moving things around like this is key to file system performance, and is why fragmentation happens and why defragmentation exists as a separate step.

“How much empty space should I leave free on a hard disk?”

This is a trickier question to answer (and this answer has already turned into a **all book).

Rules of thumb:

1. For all types of drives:

  • Most importantly, leave enough free space for you to use your computer effectively. If you are running out of space to work, you will want a bigger drive.
  • Many disk defragmentation tools require a minimum amount of free space (I think the one with Windows requires 15 percent, worst case) to work in. They use this free space to temporarily hold fragmented files as other things are rearranged.
  • Leave space for other OS functi***. For example, if your machine does not have a lot of physical RAM, and you have virtual memory enabled with a dynamically sized page file, you will want to leave enough space for the page file’s maximum size. Or if you have a laptop that you put into hibernation mode, you will need enough free space for the hibernation state file. Things like that.

2. SSD-specific:

  • For optimum reliability (and to a lesser extent, performance), SSDs require some free space, which, without going into too much detail, they use for spreading data around the drive to avoid c***tantly writing to the same place (which wears them out). This concept of leaving free space is called over-provisioning. It is important, but in many SSDs, mandatory over-provisioned space already exists. That is, the drives often have a few dozen more GB than they report to the OS. Lower-end drives often require you to manually leave unpartitioned space, but for drives with mandatory OP, you do not need to leave any free space. An important thing to note here is that over-provisioned space is often only taken from unpartitioned space. So if your partition takes up your entire drive and you leave some free space on it, that does not always count. Many times, manual over-provisioning requires you to shrink your partition to be **aller than the size of the drive. Check your SSD’s user manual for details. TRIM, garbage collection, and such have effects as well, but those are outside the scope of this answer.

Personally, I usually grab a bigger drive when I have about 20-25 percent free space remaining. This is not related to performance, it is just that when I get to that point, I expect that I will probably be running out of space for data soon and it is time to get a bigger drive.

More important than watching free space is making sure scheduled defragmentation is enabled where appropriate (not on SSDs) so that you never get to the point where it becomes dire enough to affect you.


There is one last thing worth mentioning. One of the other answers here mentioned that SATA’s half-duplex mode prevents reading and writing at the same time. While true, this is greatly oversimplified and is mostly unrelated to the performance issues being discussed here. What this means, simply, is that data cannot be transferred in both directi*** on the wire at the same time. However, SATA has a fairly complex specification involving tiny maximum block sizes (about 8kB per block on the wire, I think), read and write operation queues, etc., and does not preclude writes to buffers happening while reads are in progress, interleaved operati***, etc.

Any blocking that occurs would be due to competing for physical resources, usually mitigated by plenty of cache. The duplex mode of SATA is almost entirely irrelevant here.


(A) “Slow down” is a broad term. Here I use it to refer to things that are either I/O-bound (i.e. if your computer is sitting there crunching numbers, the contents of the hard drive have no impact) or CPU-bound and competing with tangentially related things that have high CPU usage (i.e. anti-virus software scanning t*** of files).

(B) SSDs are affected by fragmentation in that sequential access speeds are generally faster than random access, despite SSDs not facing the same limitati*** as a mechanical device (even then, lack of fragmentation does not guarantee sequential access due to wear leveling, etc.). However, in virtually every general use scenario, this is a non-issue. Performance differences due to fragmentation on SSDs are typically negligible for things like loading applicati***, booting the computer, etc.

(C) Assuming a sane file system that is not fragmenting files on purpose.

请务必通过下面的链接阅读SuperUser的其他生动讨论!


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-10 20:49
  • 阅读 ( 239 )
  • 分类:互联网

你可能感兴趣的文章

删除这些windows文件和文件夹以释放磁盘空间

...安全地删除以释放磁盘空间的Windows文件和文件夹,以及为什么要删除它们。请注意,其中一些文件夹位于受保护的位置,因此删除它们时要小心。 ...

  • 发布于 2021-03-11 09:22
  • 阅读 ( 365 )

如何防止spotify浪费磁盘空间

...间。Spotify将缓存限制为您的10%的可用空间,但每隔一次清空它仍然是一个好主意。 ...

  • 发布于 2021-03-15 16:37
  • 阅读 ( 113 )

10种简单的方法来调整你的mac以获得最佳性能

... 5清空缓存 ...

  • 发布于 2021-03-16 11:22
  • 阅读 ( 218 )

mac关闭时间太长?7个小贴士

... 打印机因引起计算机问题而臭名昭著。最让人恼火的是打印工作的停滞。你可以试着打印一份文件,但不知什么原因它不起作用。这会导致其他计算机任务暂停。 ...

  • 发布于 2021-03-22 09:51
  • 阅读 ( 231 )

减少mac备份大小和节省空间的6种简单方法

... 自动清空垃圾箱 ...

  • 发布于 2021-03-22 18:50
  • 阅读 ( 247 )

是时候再次信任ccleaner了吗?

...现在注册表中,但没有很好的证据表明清理注册表会加快计算机的速度。事实上,如果注册表清洁工过于热心,它实际上会导致比它解决的问题更多的问题。 ...

  • 发布于 2021-03-30 17:14
  • 阅读 ( 414 )

如何在Windows10上整理硬盘

...能会在访问磁盘上的数据时加快读取时间。然而,在现代计算机中,碎片整理已经不再是必要的了。Windows会自动对机械驱动器进行碎片整理,而固态驱动器则不需要进行碎片整理。 不过,保持驱动器以最高效的方式运行并没有...

  • 发布于 2021-04-02 05:08
  • 阅读 ( 157 )

如何阻止Windows10自动清空回收站

...此选项处于启用状态。 这是一个有用的功能!如果您的计算机磁盘空间不足,您可能需要更多磁盘空间。Windows将清除回收站中的旧文件。无论如何,你不应该把文件存储在你的回收站里。但是,如果您想阻止Windows自动执行此操...

  • 发布于 2021-04-03 12:39
  • 阅读 ( 187 )

如何在mac上恢复已删除的文件

...。您可以选择外部硬盘,并启用自动备份。 Time Machine将计算机的数据安全地备份到外部硬盘上,您可以通过旧版本的文件及时浏览。 如果你不信任你的旧硬盘(或者你想要一个额外的异地备份),你可以使用Arq之类的东西,它...

  • 发布于 2021-04-05 02:23
  • 阅读 ( 211 )

释放mac硬盘空间的10种方法

...理语言文件、删除重复文件、删除附件、清除临时文件或清空所有垃圾桶时,Mac上浪费的大部分空间才会被回收。 如果你不能保持Mac的硬盘清洁,你最终会得到可怕的“你的磁盘快满了”错误,所以你不妨现在就开始清理一些...

  • 发布于 2021-04-05 07:19
  • 阅读 ( 212 )
vq207902
vq207902

0 篇文章

相关推荐