8.12. The Update DaemonThe update daemon (/usr/sbin/update) periodically flushes dirty file system buffers to disk by invoking the sync() system call. By default, the update daemon calls sync() once every 30 seconds, but an alternate interval can be specified as a command-line argument. Moreover, a separate power-save interval can be specified. When the system is on battery power and the disk is sleeping, the power-save interval is used instead of the normal interval.
Flushing does not mean that the data is written to disk immediatelyit is only queued for writing. The actual writing to disk typically happens at some time in the near future. The F_FULLSYNC file control operation can be used through the fcntl() system call to truly flush a file to disk. The sync() system call iterates over the list of mounted file systems, calling sync_callback() [bsd/vfs/vfs_syscalls.c] on each file system. sync_callback() calls VFS_SYNC() [bsd/vfs/kpi_vfs.c], which calls the file-system-specific sync function through the appropriate file system function pointer table maintained by the VFS layer. For example, hfs_sync() [bsd/hfs/hfs_vfsops.c] is invoked in the case of the HFS Plus file system.
A subtle caveat is that sync() does not flush a buffer that has been dirtied by writing to a memory-mapped file. The msync() system call must be used for that case. |