c字符串格式化用零填充_如果重新格式化的硬盘填充了零,写入性能是否会提高?...
c字符串格式化用零填充
If you are going to reformat a hard-drive, is there anything that would ‘improve’ write performance afterward or is it something that you should not even worry about? Today’s SuperUser Q&A post has the answers to a curious reader’s questions.
如果您要重新格式化硬盘驱动器,那么是否有什么事情可以在事后“改善”写入性能,还是您甚至不必担心的事情? 今天的“超级用户问答”帖子回答了好奇的读者的问题。
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网站分组。
Photo courtesy of Chris Bannister (Flickr).
照片由Chris Bannister(Flickr)提供 。
问题 (The Question)
SuperUser reader Brettetete wants to know if filling a hard-drive with zeroes would improve write performance:
超级用户阅读器Brettetete想知道用零填充硬盘是否会提高写入性能:
I have a 2TB hard-drive that was 99 percent full. I have deleted the partitions with fdisk and formatted it as ext4. As far as I know, the actual data that was on the hard-drive still exists, yet the partition table was reassigned.
我有一个2TB的硬盘,已满99%。 我用fdisk删除了分区,并将其格式化为ext4 。 据我所知,硬盘上的实际数据仍然存在,但分区表已重新分配。
My question is: Would it improve the write performance for further write actions if the hard-drive was clean? By ‘clean’ I mean fill the hard-drive with zeroes? Something like:
我的问题是:如果硬盘驱动器是干净的,是否可以提高进一步执行写操作的写性能? “干净”是指用零填充硬盘驱动器? 就像是:
- dd if=/dev/zero of=/dev/sdx bs=1 count=4503599627370496 dd if = / dev / zero of = / dev / sdx bs = 1 count = 4503599627370496
Would filling the hard-drive with zeroes improve write performance?
用零填充硬盘驱动器会提高写入性能吗?
答案 (The Answer)
SuperUser contributor Michael Kjörling has the answer for us:
超级用户贡献者MichaelKjörling为我们提供了答案:
No, it would not improve performance. HDDs do not work like that.
不,它不会提高性能。 HDD不能那样工作。
First, when you write any given data to a rotational drive, it gets transformed into magnetic domains that may actually look very different from the bit pattern you are writing. This is done in part because it is much easier to maintain synchronization when the pattern read back from the platter has a certain amount of variability. For example, a long string of ‘zero’ or ‘one’ values would make it very hard to maintain synchronization. Have you read 26,393 bits or 26,394 bits? How do you recognize the boundary between bits?
首先,当您将任何给定数据写入旋转驱动器时,它会转换为磁畴 ,这些磁畴实际上看起来与您正在写入的位模式非常不同。 之所以这样做,部分是因为当从盘片读取的图案具有一定程度的可变性时,保持同步要容易得多。 例如,长字符串“零”或“一”将使保持同步非常困难。 您读过26,393位或26,394位吗? 您如何识别位之间的边界?
The techniques for doing this have evolved over time. For example, look up Modified Frequency Modulation, MMFM, Group Code Recording, and the more general technology of run-length limited encodings.
随着时间的流逝,执行此操作的技术不断发展。 例如,查找“ 修改的频率调制” ,“ MMFM”,“ 组代码记录 ”以及行程限制编码的更通用技术。
Second, when you write new data to a sector, the magnetic domains of the relevant portions of the platter are simply set to the desired value. This is done regardless of what the previous magnetic domain ‘was’ at that particular physical location. The platter is already spinning under the write head; first reading the current value, then writing the new value if and only if it is different. It would cause each write to require two revolutions (or an extra head for each platter), causing write latency to double or greatly increasing the complexity of the drive, in turn increasing cost.
其次,当您将新数据写入扇区时,盘片相关部分的磁畴只需设置为所需值即可。 无论先前的磁畴在该特定物理位置上是什么,都可以执行此操作。 盘片已经在写头下旋转; 首先读取当前值,然后在且仅当不同时才写入新值。 这将导致每次写入都需要旋转两圈(或每个盘片都需要一个额外的磁头),从而导致写入延迟增加一倍或大大增加了驱动器的复杂度,进而增加了成本。
Since the limiting factor in hard-drive sequential I/O performance is how quickly each bit passes under the read/write head, this would not even offer any benefit to the user. As an aside, the limiting factor in random I/O performance is how fast the read/write head can be positioned at the desired cylinder and then the desired sector arrives under the head. The major reason why SSDs can be so fast in random I/O workloads is that they completely eliminate both of these factors.
由于硬盘驱动器顺序I / O性能的限制因素是每个位在读/写磁头下方通过的速度,因此这甚至无法为用户带来任何好处。 顺便说一句,随机I / O性能的限制因素是读/写头可以定位在所需圆柱体上的速度,然后所需扇区到达该头下方的速度。 SSD在随机I / O工作负载中如此之快的主要原因是它们完全消除了这两个因素。
As pointed out by JakeGould, one reason why you might want to overwrite the drive with some fixed pattern (such as all zeroes) would be to ensure that no remnants of previously stored data can be recovered, either deliberately or accidentally. But doing so will not have any effect on the hard-drive’s performance going forward, for the reasons stated above.
正如JakeGould指出的那样 ,您可能想用某种固定模式(例如全零) 覆盖驱动器的原因之一是要确保不会有意或无意地恢复以前存储的数据的剩余部分。 但是,由于上述原因,这样做不会对硬盘的性能产生任何影响。
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的用户那里获得更多答案? 在此处查看完整的讨论线程 。
c字符串格式化用零填充