Synchronization of Individual Files

The contents of individual files can be synchronized without the need to synchronize all the data in the system. This option is used by applications that must ensure that the data they modify in memory are always written back to the appropriate block device. Because normal write access operations first land in cache, this option provides added safety for really important data (of course, another alternative would be to use direct I/O operations that bypass the cache).

As already noted, several different system calls are available for this purpose:

1. fsync synchronizes the contents of a file and also writes the metadata associated with the file's inode back to the block device.

2. fdatasync writes back only the data contents and ignores the metadata.

3. sync_file_range is a comparatively new system call that was introduced in kernel 2.6.16. It allows for controlling synchronization for precisely defined parts of open files. Essentially, the implementation selects the desired pages for writeback and possibly awaits the result. Since this is not too different from the methods employed for the above system calls, I will not bother to discuss sync_file_range in detail.

The implementation of fsync and fdatasync differs only at a single point (to be more accurate, in a single character):

Continue reading here: Fssyncc

Was this article helpful?

0 0