Does O_DIRECT bypass filesystem journaling?

时间:2015-10-30 23:19:59

标签: linux file io dma

The man page for open(2) only suggests that O_DIRECT bypasses the page cache, but many descriptions around the net describe it as causing the user buffer to be DMA'd straight to the drive. If this is the case I imagine it would also bypass journaling done by the filesystem (e.g. xfs, ext4, etc.). Is this the case?

I can't find anyone claiming one way or the other. It seems to me this would be consistent with O_DIRECT being used by databases -- the common example use for O_DIRECT is when an application like a database is doing its own caching in userspace, and similarly I can imagine databases doing their own transaction logs.

1 个答案:

答案 0 :(得分:3)

  

O_DIRECT是否会绕过文件系统日记功能?

通常它确实如此。但是,文件数据通常不会进入文件系统的日志。下面有更多细节(但请注意,这个答案不会考虑CoW文件系统):

大多数Linux日志文件系统(当日志设置为回写或有序(默认),XFS,JFS等时的Ext4)不会记录文件中的数据 - 它们记录了文件系统的数据结构(元数据)的一致性。 / p>

文件系统日志仅元数据(典型案例):文件中的井数据无论如何都不会进入日志,因此使用O_DIRECT不会改变这一点并且数据仍然没有进入期刊。但是,O_DIRECT操作仍然可以像正常情况一样触发元数据更新,但启动操作可以在元数据更新之前返回。有关详细信息,请参阅Ext4 wiki Clarifying Direct IO's Semantics page

期刊中的Ext4 =数据模式:这比较棘手 - 有警告称O_DIRECT模式下journal=data所需的结果可能不符合预期。来自"data=journal" section of ext4.txt

  

启用此模式[journal = data]将禁用延迟分配和O_DIRECT支持。

在这种情况下,O_DIRECT仅被视为一个提示,文件系统默默地回退到将数据填充到页面缓存中(使其不再直接!)。因此,在这种情况下,数据将最终进入期刊并且期刊不会被绕过。请参阅“Re: [PATCH 1/1 linux-next] ext4: add compatibility flag check”主题,了解Ted Ts'o所阐述的内容。有一些补丁(“ext4: refuse O_DIRECT opens for mode where DIO doesn't work”)浮动,以使文件系统在打开时返回错误,但从我可以看到它们被主线内核拒绝。