With exception to files opened in unbuffered mode or requests followed by flush, writes are lazy. The contents are only marked dirty in the fs cache and repeated or incremental updates to the same block are combined there.
Reads for files opened in unbuffered mode flush and discard the corresponding cache pages and thus cause writes. Furthermore, writes can result from memory pressure, which can be the result of anything, including reads. For example, the cache pages for the read data can be acquired by evicting the contents of a dirty page, which causes a write.
The journal will guarantee consistent fs structure after a crash even if it is written out lazily, because its operation depends only on correct sequencing. However, the user data will be lost/corrupted unless the filesystem is explicitly configured to journal it as well.
The sysctl parameters vm.dirty_writeback_centisecs, vm.dirty_expire_centisecs can be used to control the flush frequency on Linux. Windows can disable the file cache on a per device basis and configure certain quotas, but lacks fine grained timing control.
|