Chapter 17: Data Synchronization
17.10 Inode Synchronization
writeback_inodeswrites back installed mappings by walking through the system inodes (for the sake
of simplicity, this is calledinode writeback, but in fact not the inode but the dirty data associated with it
are written back). The function shoulders the mainburden of synchronizationbecause most system data
are provided in the form of address space mappings that make use of inodes. Figure 17-6 illustrates the
code flow diagram forwriteback_inodes. The function is slightly more complicated in reality because
some more details and corner cases need to be handled properly. We consider a simplified variant that
nevertheless contains everything that isessential when inodes are written back.
Writeback limit reached?
Iterate oversb->s_ioFailed to write pages? Move to s_dirty
Iterate over allsuperblocks
Fill I/O list
Perform checks
Writeback limit reached?
writeback_inodes
sync_sb_inodes
__writeback_single_inode
break
break
Figure 17-6: Code flow diagram forwriteback_inodes.
The function uses the data structures discussed in Chapter 8 to establish a link among superblocks,
inodes, and associated data.
17.10.1 Walking the Superblocks
When mappings are written back inode-by-inode, the initial path taken is via all system superblock
instances that represent the mounted filesystems.sync_sb_inodesis invoked for each instance in order
to write back the superblock inode data, as shown in the code flow diagram in Figure 17-6. Walking the
superblock list can be terminated by two different conditions:
- All superblock instances have been scanned sequentially. The kernel has reached the end of
the list, and its work is therefore done. - The maximum number of writeback pages specified by thewriteback_controlinstance
has been reached. Since writeback requires obtaining various important locks, the system
should not be disturbed for too long to make the inodes available for other parts of the
kernel again.
17.10.2 Examining Superblock Inodes
Once it has been established with the help of the superblock structure that the filesystem contains inodes
with dirty data, the kernel hands over tosync_sb_inodes, which synchronizes the dirty superblock
inodes. The code flow diagram is in Figure 17-6.