简体   繁体   English

linux 上的 msync 保证

[英]msync guarantees on linux

Is msync guaranteed to physically write dates into the hard-drive? msync是否保证将日期物理写入硬盘驱动器? Can I be 100% sure that if the OS crashes immediately after msync returns, that I won't lose data?我能 100% 确定如果操作系统在msync返回后立即崩溃,我不会丢失数据吗?

By 100% sure I mean that the data was physically written to the disk and not just hard drive buffer. 100% 确定我的意思是数据被物理写入磁盘,而不仅仅是硬盘驱动器缓冲区。 Simply, I want to be sure that losing electricity won't result in loss of data.简单地说,我想确保断电不会导致数据丢失。

It is still possible for data to be lost if the OS crashes after msync returns.如果操作系统在 msync 返回后崩溃,数据仍有可能丢失。 Its because the data may still be stored in the file system cache and not yet written to the storage device.这是因为数据可能仍存储在文件系统缓存中,尚未写入存储设备。 To guarantee that data is not lost in the event of an OS crash, you can use the fsync system call to synchronize the file system cache with the storage device.为了保证在操作系统崩溃时数据不丢失,您可以使用fsync系统调用将文件系统缓存与存储设备同步。 To be extra sure you should use a disk journaling filesystem like ext3, ext4, jfs, ntfs, reiserfs, xfs etc, that ensure that the filesystem remains consistent in case of a crash or power failure.为确保您应该使用磁盘日志文件系统,如 ext3、ext4、jfs、ntfs、reiserfs、xfs 等,以确保文件系统在崩溃或电源故障时保持一致。

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

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