liunx清空磁盘空间_为什么清空磁盘空间可以加速计算机?

liunx清空磁盘空间

liunx清空磁盘空间

why-does-emptying-disk-space-speed-up-computers-00

When learning more about computers and how they work, you will occasionally run across something that does not seem to make sense. With that in mind, does emptying disk space actually speed computers up? Today’s SuperUser Q&A post has the answer to a puzzled reader’s question.

在了解有关计算机及其工作方式的更多信息时,您有时会遇到一些似乎没有意义的事情。 考虑到这一点,清空磁盘空间实际上是否可以加快计算机的速度? 今天的《超级用户问答》帖子解答了一个困惑的读者的问题。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

Screenshot courtesy of nchenga (Flickr).

屏幕快照由nchenga(Flickr)提供

问题 (The Question)

SuperUser reader Remi.b wants to know why emptying disk space seems to speed up a computer:

超级用户阅读器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.

我看了很多视频,现在了解了计算机的工作原理。 我了解什么是RAM,关于易失性和非易失性内存以及交换过程。 我也理解为什么增加RAM可以加快计算机速度。

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?

它与寻找内存空间来保存东西或到处移动东西以提供足够长的连续空间来保存东西有关吗? 我应该在硬盘上留出多少可用空间?

Why does emptying disk space seem to speed up a computer?

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

答案 (The Answer)

SuperUser contributor Jason C has the answer for us:

超级用户贡献者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.

它不是,至少不是靠它自己。 这是一个非常普遍的神话。 这是一个普遍的神话,是因为填充硬盘驱动器通常与传统上可能会使计算机速度变慢的其他事情同时发生(A) 。 SSD填充时确实会降低性能,但这是一个相对较新的问题,是SSD特有的,并且对于休闲用户而言并不十分明显。 通常,可用磁盘空间不足只是一个红鲱鱼。

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:

1.文件碎片。 文件碎片化是一个问题(B) ,但是缺少可用空间虽然绝对是众多促成因素之一,但并不是造成这种情况的唯一原因。 这里的一些关键点:

  • 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). Consider: 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.

    文件的几率被割裂是相关的剩余可用空间的驱动器上的金额。 它们与驱动器上最大的连续自由空间块的大小(即,自由空间的“空洞”)有关,自由空间的大小恰好使上限处于上限 。 它们还与文件系统处理文件分配的方式有关(请参见下文 )。 请考虑:一个驱动器在一个连续的块中具有95%的可用空间,而将一个新文件(C)分割成碎片的机会为零(而对附加文件进行碎片化的机会与该空闲空间无关)。 百分之五的驱动器已满,但数据均匀分布在该驱动器上的机会很高。

  • Keep in mind that file fragmentation only affects performance when the fragmented files are being accessed. Consider: You have a nice, defragmented drive that still has lots of free “holes” in it. A common scenario. Everything is running smoothly. 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.

    请记住,文件碎片只会在访问碎片文件时影响性能考虑:您有一个不错的,经过碎片整理的驱动器,其中仍然有许多空闲的“Kong”。 常见情况。 一切运行顺利。 最终,尽管如此,您到达的地步是不再有更多的可用自由空间。 您下载了一部大型电影,该文件最终被严重分割。 这不会降低计算机的速度 。 您所有的应用程序文件以及以前可用的文件都不会突然变得零散。 这可能会使影片的加载时间更长(尽管与硬盘驱动器读取速率相比,典型的影片比特率非常低,以至于很可能不会引起注意),并且可能会在影片加载时影响I / O绑定性能,但是除此之外,没有任何变化。

  • 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).

    虽然文件碎片肯定是一个问题,但通常情况下,操作系统和硬件级别的缓冲和缓存会减轻这种影响。 延迟的写入, 读,Windows中的预取器之类的策略等都有助于减少碎片的影响。 通常,在碎片变得很严重之前,您实际上并没有受到重大影响(我什至敢说,只要交换文件没有碎片,您可能永远不会注意到)。

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.

2.搜索索引是另一个示例。 假设您已打开自动索引功能,并且操作系统无法正常处理此问题。 随着您将越来越多的可索引内容(例如文档等)保存到计算机中,建立索引的时间可能越来越长,并且可能开始影响计算机在运行时的I / O和CPU使用率。 这与可用空间无关,与您拥有的可索引内容的数量有关。 但是,用尽可用空间与存储更多内容密切相关,因此绘制了错误的连接。

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.

3.防病毒软件(类似于搜索索引示例)。 假设您已设置防病毒软件来对驱动器进行后台扫描。 当您拥有越来越多的可扫描内容时,搜索将占用更多的I / O和CPU资源,可能会干扰您的工作。 同样,这与您拥有的可扫描内容的数量有关。 更多的内容通常等于更少的可用空间,但是没有可用空间不足不是原因。

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.

4.安装的软件。 假设您安装了许多在计算机启动时加载的软件,从而减慢了启动时间。 之所以会变慢,是因为正在加载许多软件。 但是,已安装的软件会占用硬盘空间。 因此,硬盘驱动器的可用空间在发生这种情况的同时减少,并且再次可以容易地建立错误的连接。

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

5.沿着这些思路,还有许多其他示例,这些示例加在一起似乎将缺乏可用空间与性能降低紧密联系在一起。

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 applications, removing indexed or scanned content, etc. sometimes (but not always; outside the scope of this answer) increases performance again for reasons 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.

上面的例子说明了这是一个普遍的神话的另一个原因:虽然可用空间不足并不是造成速度变慢的直接原因,但有时(但不总是)卸载各种应用程序,删除索引或扫描的内容等(但不总是这样)。此答案)由于与剩余可用空间量无关的原因而再次提高了性能。 但这自然也会释放硬盘空间。 因此,同样可以在“更多的自由空间”和“更快的计算机”之间建立明显的连接(但错误的连接)。

Consider: 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 partitions 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 mechanisms 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.

1. 您的硬盘驱动器不会四处寻找放置物品的地方。 您的硬盘很笨。 没事 这是寻址存储的一大块,它盲目地将内容放置在OS告诉它的地方,并读取对其提出的要求。 现代驱动器具有复杂的缓存和缓冲机制,旨在根据我们随着时间的推移获得的经验来预测操作系统的要求(某些驱动器甚至知道其上的文件系统),但从本质上讲,请考虑一下您的操作系统。驱动器只是一个笨拙的存储砖,偶尔会有额外的性能表现。

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

2. 您的操作系统也不会搜索放置东西的地方。 没有搜索。 解决此问题已经付出了很多努力,因为这对文件系统性能至关重要。 在驱动器上实际组织数据的方式由文件系统决定。 例如,FAT32(旧的DOS和Windows PC),NTFS(Windows的更高版本),HFS +(Mac),ext4(某些Linux系统)等。 甚至“文件”和“目录”的概念也仅仅是典型文件系统的产物-硬盘对称为文件的神秘野兽一无所知。 详细信息不在此答案的范围内。 但从本质上讲,所有常见的文件系统都具有跟踪驱动器上可用空间的位置的方法,因此在正常情况下(即运行状况良好的文件系统),无需搜索可用空间。 例子:

  • 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.

    NTFS有一个主文件表 ,其中包括特殊文件$ Bitmap等,以及描述驱动器的大量元数据。 本质上,它跟踪下一个空闲块的位置,以便可以将新文件直接写入空闲块,而不必每次都扫描驱动器。

  • 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 decisions about where to put it to reduce fragmentation.

    另一个示例: Ext4具有所谓的位图分配器 ,它是对ext2和ext3的改进,基本上可以帮助它直接确定空闲块的位置,而不是扫描空闲块的列表。 Ext4还支持延迟分配 ,即在将数据写到驱动器之前由OS在RAM中缓冲数据,以便更好地决定将数据放在何处以减少碎片。

  • 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 editions of Windows, at least, this happens automatically on a schedule, but it is never triggered by writing a file.

“将事物四处移动以形成足够长的连续空间来保存某些东西”的过程称为碎片整理 。 写入文件时不会发生这种情况。 当您运行磁盘碎片整理程序时,会发生这种情况。 至少在Windows的较新版本中,这是按计划自动发生的,但绝不会通过写入文件来触发。

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 small book).

这是一个棘手的问题(这个答案已经变成了一本小书)。

Rules of thumb:

经验法则:

1. For all types of drives:

1.对于所有类型的驱动器:

  • 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.

    许多磁盘碎片整理工具需要最少的可用空间(我认为Windows的磁盘碎片整理工具需要15%,最坏的情况)才能使用。它们会在重新排列其他内容时使用此可用空间来临时保存碎片文件。
  • Leave space for other OS functions. 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.

    为其他OS功能留出空间。 例如,如果您的计算机没有太多的物理RAM,并且已为动态大小的页面文件启用了虚拟内存,则您将需要留出足够的空间来容纳页面文件的最大大小。 或者,如果您有一台笔记本电脑进入Hibernate模式,则将需要足够的可用空间来存储Hibernate状态文件。 像这样的东西。

2. SSD-specific:

2.特定于SSD:

  • 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 constantly 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 smaller 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.

    为了获得最佳可靠性(并在较小程度上提高性能),SSD需要一定的可用空间,而无需花费太多细节,它们就可以在驱动器周围散布数据,从而避免不断写入同一位置(使它们磨损) 。 留下自由空间的概念称为“ 过度配置” 。 这很重要, 但是在许多SSD中,已经存在强制性的超额配置空间 。 也就是说,驱动器通常比向操作系统报告的容量多几十个GB。 低端驱动器通常需要您手动保留未分区的空间,但是对于具有强制OP的驱动器, 则无需保留任何可用空间 。 这里要注意的重要一点是, 预留空间通常仅取自未分配的空间 。 因此,如果分区占用了整个驱动器,并且在其上留下了一些可用空间,那么这并不总是有效的 。 很多时候,手动超额配置要求您将分区缩小为小于驱动器的大小。 有关详细信息,请检查您的SSD的用户手册。 TRIM,垃圾回收等也有效果,但是这些不在此答案的范围之内。

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.

就个人而言,当我剩余约20%到25%的可用空间时,我通常会抓住更大的驱动器。 这与性能无关,只是到了这一点,我预计我可能很快就会用完数据空间,现在是时候获得更大的驱动器了。

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.

比观察可用空间更重要的是确保在适当的地方(而不是在SSD上)启用计划的碎片整理,这样您就永远不会陷入严重影响您的境地。



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 directions 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 operations, etc.

最后一件事值得一提。 此处的其他答案之一是SATA的半双工模式阻止同时进行读写。 的确如此,但是这大大简化了,并且与此处讨论的性能问题无关。 简而言之,这意味着不能同时在导线的两个方向传输数据。 但是,SATA具有相当复杂的规范,涉及极小的最大块大小(我认为线路上每个块大约8kB),读写操作队列等,并且不排除在读取进行中,交错时发生对缓冲区的写操作操作等

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.

发生的任何阻塞都可能是由于争用物理资源,通常可以通过大量缓存来缓解。 SATA的双工模式在这里几乎完全不相关。



(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 tons of files).

(A) “减速”是一个广义术语。 在这里,我用它来指代受I / O约束的事物(即,如果您的计算机坐在那儿,数字很紧,硬盘驱动器的内容没有影响)或受CPU约束并且与切线相关的事物竞争很高的事物。 CPU使用率(即防病毒软件扫描大量文件)。

(B) SSDs are affected by fragmentation in that sequential access speeds are generally faster than random access, despite SSDs not facing the same limitations 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 applications, booting the computer, etc.

(B) SSD受碎片影响的原因是,尽管SSD不会遇到与机械设备相同的局限性,但顺序访问的速度通常比随机访问要快(即使那样,缺乏碎片也不能保证由于磨损均衡等原因导致的顺序访问。 )。 但是,实际上在每种通用情况下,这都不是问题。 由于SSD碎片化而导致的性能差异通常对于加载应用程序,启动计算机等而言可以忽略不计。

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

(C)假设一个健全的文件系统没有故意碎片化文件。

Make sure to read through the rest of the lively discussion at SuperUser via the link below!

请确保通过下面的链接阅读SuperUser上其余的生动讨论!



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/215413/why-does-emptying-disk-space-speed-up-computers/

liunx清空磁盘空间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值