简体   繁体   English

EXT4的data=journal模式能否避免用户数据丢失?

[英]Can the data=journal mode of EXT4 avoid user data loss?

  • journal mode日记模式

data=journal mode provides full data and metadata journaling. data=journal 模式提供完整的数据和元数据日志。 All new data is written to the journal first, and then to its final location.所有新数据首先写入日志,然后写入其最终位置。

In the event of a crash, the journal can be replayed, bringing both data and metadata into a consistent state.如果发生崩溃,可以重播日志,将数据和元数据带入一致的 state。 This mode is the slowest except when data needs to be read from and written to disk at the same time where it outperforms all others modes.这种模式是最慢的,除非需要同时从磁盘读取数据和将数据写入磁盘,它的性能优于所有其他模式。 Enabling this mode will disable delayed allocation and O_DIRECT support.启用此模式将禁用延迟分配和 O_DIRECT 支持。

Here I have a few questions, please take a look at it:在这里我有几个问题,请看一下:

  1. Configure data=journal, then the user calls write(), does the write() return after the data is successfully written to the journal, or does it return the user success after entering the pagecache?配置data=journal,然后用户调用write(),是数据写入journal成功后write()返回,还是进入pagecache后返回用户成功? If it is the latter, it means that the journal is submitted asynchronously, so the meaning of the journal of ext4 is to ensure the consistency of the file system itself, and there is no guarantee that user data will not be lost?如果是后者,就说明journal是异步提交的,那么ext4的journal的意义就是保证文件系统本身的一致性,不保证用户数据不会丢失?

  2. If ext4 submits the journal asynchronously, when will the journal be triggered?如果ext4异步提交日志,什么时候触发日志?

  3. Is there any other file system that allows the journal to be synchronized before write() returns successfully?是否有任何其他文件系统允许在 write() 成功返回之前同步日志?

According to the results of my local experiments, it is inferred that the journal should be submitted asynchronously.根据我本地实验的结果,推断该期刊应该是异步提交的。 I used a separate ssd partition as journal_dev.我使用了一个单独的 ssd 分区作为 journal_dev。 When I used fio to test and write files, I found that the io of journal_dev was intermittent, not always having IO.我用fio测试写文件的时候发现journal_dev的io是断断续续的,不是一直都有IO。

  1. the write() will return the user success after it has entered the page cache (assuming you aren't using any extra options on open() ). write() 将在进入页面缓存后返回用户成功(假设您没有在open()上使用任何额外选项)。
  2. At least periodically (see commit= in https://www.kernel.org/doc/Documentation/filesystems/ext4.txt ) and probably before any pending sync / fsync etc are allowed to complete.至少定期(参见https://www.kernel.org/doc/Documentation/filesystems/ext4.txt中的commit= )并且可能在任何待处理的sync / fsync等被允许完成之前。
  3. No (otherwise it would defeat the point of buffering).否(否则它会破坏缓冲点)。

If you were to pass O_SYNC to open() or to do an additional fsync you will learn about when your write made it to stable media as far as the kernel can know.如果您要将O_SYNC传递给open()或进行额外的fsync ,您将了解 kernel 所知的稳定媒体何时写入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM