磁盘扇区是否写入原子? [英] Are disk sector writes atomic?

查看:1100
本文介绍了磁盘扇区是否写入原子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

澄清问题:

当操作系统发送写入扇区的命令是否为原子?即新数据的写入完全成功,或者如果电源在写入命令之后立即失败,则旧数据保持原样。我不在乎多个部门的写作发生了什么 - 撕裂页面是可以接受的。

When the OS sends the command to write a sector to disk is it atomic? i.e. Write of new data succeeds fully or old data is left intact should the power fail immediately following the write command. I don't care about what happens in multiple sector writes - torn pages are acceptable.

旧问题:

假设您在磁盘上有旧数据X,则在其上写入新的数据Y,并且在写入期间树将落在电源线上。没有花哨的UPS或电池支持的磁盘控制器,您可能会遇到一个被撕毁的页面,其中磁盘上的数据是X部分和部分Y.您是否可以最终遇到磁盘上的数据是X部分,Y部分,和部分垃圾?

Say you have old data X on disk, you write new data Y over it, and a tree falls on the power line during that write. With no fancy UPS or battery backed disk controller, you can end up with a torn page, where the data on disk is part X and part Y. Can you ever end up with a situation where the data on disk is part X, part Y, and part garbage?

我一直在试图了解ACID系统的设计,如数据库,对我的天真的想法,似乎是firebird,它不使用提前记录,是依靠给定的写入不会破坏旧数据(X) - 只能完全写入新的数据(Y)。这意味着如果X的一部分被覆盖,则只能覆盖X的部分,而不是我们打算保留的X的部分。

I've been trying to understand the design of ACID systems like databases, and to my naive thinking, it seems firebird, which does not use a write-ahead log, is relying that a given write will not destroy old data (X) - only fail to fully write new data (Y). That means that if part of X is being overwritten, only the part of X that is being overwritten can be changed, not the part of X we intend to keep.

澄清一下,这意味着如果你有一个页面大小的缓冲区,比如说4096字节,填充半Y,我们要保留的一半,我们告诉操作系统把这个缓冲区写在X上,没有严重的磁盘故障我们想要保留的半X在写入期间被破坏。

To clarify, this means if you have a page sized buffer, say 4096 bytes, filled with half Y, half X that we want to keep - and we tell the OS to write that buffer over X, there is no situation short of serious disk failure where the half X that we want to keep is corrupted during the write.

推荐答案

没有人似乎同意这个问题。所以我花了很多时间尝试不同的Google查询,直到我终于找到答案。

Nobody seems to agree on this question. So I spent a lot of time trying different Google queries until I finally found an answer.

来自Dr. Stephen Tweedie,RedHat员工和Linux内核文件系统以及虚拟内存开发人员关于ext3的讲话(他开发的)这里的抄本。如果有人知道,那将是他。

from Dr. Stephen Tweedie, RedHat employee and linux kernel filesystem and virtual memory developer in a talk on ext3 (which he developed) transcript here. If anyone knows, it'd be him.

仅仅是把这个东西写到日记上是不够的,因为在这个杂志里有一些标记嗯,(实际上有这个日志记录)这个日志记录是否真的代表了一个完整的一致性的磁盘?你的方法是通过一些原子操作,把事务标记为在磁盘上完成[23m,14s]

"It's not sufficient just to write the thing to the journal, because there's got to be some mark in the journal which says: well, (has this journal record actually) does this journal record actually represent a complete consistency to the disk? And the way you do that is by having some atomic operation which marks that transaction as being complete on disk" [23m, 14s]

现在,磁盘这些天实际上做出了这些保证,如果你开始对磁盘进行写入操作,那么即使电源在该扇区写入中断,磁盘具有足够的电力可用,实际上可以从主轴的旋转能量窃取电力;它具有足够的电力来完成正在写入的扇区的写入,在所有情况下,磁盘都将做出保证。 [23m,41s]

"Now, disks these days actually make these guarantees. If you start a write operation to a disk, then even if the power fails in the middle of that sector write, the disk has enough power available, and it can actually steal power from the rotational energy of the spindle; it has enough power to complete the write of the sector that's being written right now. In all cases, the disks make that guarantee." [23m, 41s]

这篇关于磁盘扇区是否写入原子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆