最近,我正在测试ext4文件系统的正确用法。我的专家是:
当系统崩溃时,数据已经被写回ok不能丢失,但是元数据可以。
下面是我的用法:
1. call fallocate to alloc centain space fallocate(fd, 0, 0, 4\*1024\*1024); //4MB
2. call fsync(fd) let data and metadata write to disks
3. then i call function to randomly write the file with 4k size(random data but not 0). with O\_DRICT flag,but not call fsync. I log the offset with return write ok.
4. check the offset that logged. but i find in some offset, read 4k data, is 0. It seems mean that offset isn't used like hole files. 我的问题是:
<1. why after calling fallocate and fsync the metadata of the file still seems indicate some blocks is not used, so when read it return null. It is my understand .<2. have other api to call, can make sure that in allocate space with file is not holes ,after that when write data return ok with O\_DIRECT can make sure the data will not be loss even the system crashed. Thanks.发布于 2017-08-09 20:40:41
只有写入文件空间才能消除漏洞。如果不写,就没有脏页,fsync什么也不做。
我想知道你是如何执行你的第四步的。看起来你是手动崩溃的,是吗?如果你在没有崩溃的情况下读完它,它不应该是零,只要你写了非零。如果您在崩溃后读取它,如果存在磁盘缓存,则可能发生零。然而,这种类型的零不像孔,它们是从磁盘读取的零(很可能磁盘包含零)。
https://stackoverflow.com/questions/42864794
复制相似问题