Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


❑ A further situation leads to termination ofsync_sb_inodes.Ifapdflushthread is already in
the process of writing back the processed queue (this is indicated by theBDI_pdflushbit of the
statuselement ofbacking_dev_info), the current thread lets the runningpdflushthread pro-
cess the queue on its own.

Inode writeback may not be initiated until the kernel has ensured that the above conditions
are satisfied. As the code flow diagram in Figure 17-6 shows, the inode is written back using
__writeback_single_inode, examined below. It can happen that writing back pages does not succeed
for all pages that should be written back, for instance, because a page might be locked from another
part of the kernel, or connections for network filesystems might be unavailable. In this case, the inode is
moved back to thes_dirtylist again, possibly updating thedirtied_whenfield unless the inode has
been re-dirtied while it was written out. The kernel will automatically retry to synchronize the data in
one of the next synchronization runs. Additionally, the kernel needs to make sure that the inverse time
ordering of all inodes ons_dirtyis preserved. The auxiliary functionredirty_tailtakes care of this.

The process is repeated until one of the two conditions below is fulfilled:


  1. All dirty inodes of the superblock have been written back.

  2. The maximum number of page synchronizations (specified innr_to_write) has been
    reached. This is necessary to support the unit-by-unit synchronization described above.
    The remaining inodes ins_ioare processed the next timesync_sb_inodesis invoked.


17.10.3 Writing Back Single Inodes


As noted above, the kernel delegates synchronization of the data associated with an inode to
__writeback_single_inode. The corresponding code flow diagram is shown in Figure 17-7.

Inode locked?

Wait on inode

Move inode to s_more_io

Yes

No

__sync_single_inode

__writeback_single_inode

Data integrity writeback (WBC_SYNC_ALL set)?

do_writepages

return

Figure 17-7: Code flow diagram for__writeback_single_inode.

The function is essentially a dispatcher for__sync_single_inode, but is charged with the important
task of distinguishing whether a data integrity (WB_SYNC_ALL) or regular writeback is performed. This
influences how locked inodes are handled.
Free download pdf