Writing Immediately With fsync()
Understand how to use the fsync system call to force buffered file data to persistent storage. Explore why fsync is essential for applications like databases that require immediate data durability, and learn about key details such as syncing directories to avoid common file system consistency errors.
We'll cover the following...
Most times when a program calls write(), it is just telling the file system: please write this data to persistent storage, at some point in the future. The file system, for performance reasons, will buffer such writes in memory for some time (say 5 seconds, or 30); at that later point in time, the write(s) will actually be issued to the storage device. From the perspective of the calling application, writes seem to complete quickly, and only in rare cases (e.g., the machine crashes after the write() call but before the write to disk) will data be lost.
However, some applications require ...