- 论坛徽章:
- 1
|
回复 7# river617
15.4.1. The sync ( ) System Call
The service routine sys_sync( ) of the sync( ) system call invokes a series of auxiliary functions:
wakeup_bdflush(0);
sync_inodes(0);
sync_supers( );
sync_filesystems(0);
sync_filesystems(1);
sync_inodes(1);
As described in the previous section, wakeup_bdflush( ) starts a pdflush kernel thread, which flushes to disk all dirty pages contained in the page cache.
The sync_inodes( ) function scans the list of superblocks looking for dirty inodes to be flushed; it acts on a wait parameter that specifies whether it must wait until flushing has been performed or not. The function scans the superblocks of all currently mounted filesystems; for each superblock containing dirty inodes, sync_inodes( ) first invokes sync_sb_inodes( ) to flush the corresponding dirty pages (we described this function earlier in the section "Looking for Dirty Pages To Be Flushed" , then invokes sync_blockdev( ) to explicitly flush the dirty buffer pages owned by the block device that includes the superblock. This is done because the write_inode superblock method of many disk-based filesystems simply marks the block buffer corresponding to the disk inode as dirty; the sync_blockdev( ) function makes sure that the updates made by sync_sb_inodes( ) are effectively written to disk.
The sync_supers( ) function writes the dirty superblocks to disk, if necessary, by using the proper write_super superblock operations. Finally, the sync_filesystems( ) executes the sync_fs superblock method for all writable filesystems. This method is simply a hook offered to a filesystem in case it needs to perform some peculiar operation at each sync; this method is only used by journaling filesystems such as Ext3 (see Chapter 1 .
Notice that sync_inodes( ) and sync_filesystems( ) are invoked twice, once with the wait parameter equal to 0 and the second time with the parameter equal to 1. This is done on purpose: first, they quickly flush to disk the unlocked inodes; next, they wait for each locked inode to become unlocked and finish writing them one by one.
这是从ULK3中找的
具体实现得看操作系统是怎么做的
注意最后一段的描述 |
|