确保FSYNC做自己的工作 [英] Ensure fsync did its job
问题描述
联机帮助页 FSYNC
说:
如果底层的硬盘已启用写入缓存,则数据
未必真的是永久存储时FSYNC()/ fdatasync()
返回。
If the underlying hard disk has write caching enabled, then the data may not really be on permanent storage when fsync() / fdatasync() return.
有什么办法如何保证数据实际写入磁盘?
Is there any way how to ensure that data was physically written to the disk?
推荐答案
没有,没有。
使用 FSYNC
你告诉你的OS写入到磁盘并尽可能操作系统而言,它已被写入到磁盘中。
With fsync
you tell your OS to write it to disk and as far as the OS is concerned, it has been written to disk.
如果磁盘伪装的,那么它是不是你真的可以改变很遗憾。
有了适当的磁盘系统(即BBU RAID设置),你可以简单地启用/禁用写高速缓存大多避免这种情况。
If disks are faking this then it is not something you can really change unfortunately. With proper disk systems (i.e. BBU raid setups) you can simply enable/disable write cache to avoid this mostly.
请注意,如果您指定 O_DIRECT
和 O_SYNC
标记,它的应的其写入到磁盘: HTTP:// WWW。 kernel.org/doc/man-pages/online/pages/man2/open.2.html
Do note that if you specify the O_DIRECT
and O_SYNC
flags, it should write it to disk: http://www.kernel.org/doc/man-pages/online/pages/man2/open.2.html
这篇关于确保FSYNC做自己的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!