Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


Great effort would be needed if the kernel were to run through thecompletelist of filesystem inodes each
time in order to differentiate between clean and dirty inodes. The kernel therefore implements a far less
costly option by placing all dirty inodes on the superblock-specific listsuper_block->s_dirty.Notice
that inodes on the list are reverse time-ordered. The later an inode was dirtied, the closer it is to the tail
of the list.

Two more list heads are additionally required to perform the synchronization of these inodes. The rele-
vant portion of thesuper_blockstructure is as follows:

<fs.h>
struct super_block {
...
struct list_head s_dirty; /* dirty inodes */
struct list_head s_io; /* parked for writeback */
struct list_head s_more_io; /* parked for more writeback */
...
}

All dirty inodes of the superblock are held in thes_dirtylist — and are practically served up on a
platter to the synchronization mechanism. This list is updated automatically by the relevant code of the
VFS layer.s_iokeeps all inodes that are currently under consideration of the synchronization code.

s_more_iocontains inodes that have been selected for synchronization and were placed ons_io,but
could not be processed in one go. It would seem to be the simplest solution that the kernel puts such
inodes back tos_io, but this could starve newly dirtied inodes or lead to locking problems, so a second
list is introduced. All functions that place inodes ons_ioors_more_ioare indicated in Figure 17-1.

The first task ofsync_sb_inodesis to fill thes_iolist. Two cases must be distinguished:


  1. If the synchronization request didnotoriginate from the periodic mechanism, then all inodes
    on the dirty list are put onto thes_iolist. If inodes are present on themore_iolist, they are
    placed at the end of thei_iolist. The auxiliary functionqueue_iois provided to perform
    both list operations. The behavior ensures thatinodes from previous synchronization passes
    still get consideration, but morerecently dirtied inodes are preferred. This way, large dirtied
    files cannot starve smaller files that were dirtied afterward.

  2. If the periodic mechanismwb_kupdatehas triggered synchronization, thes_iolist is only
    replenished with additional dirty inodes if it is completely empty. Otherwise, the kernel
    waits until all members ofs_iohave been written back. There is no particular pressure for
    the periodic mechanism to write back as many inodes as possible in the shortest amount of
    time. Instead, it is more important to slowly but surely write out a constant stream of inodes.


If the writeback control parameter specifies anolder_than_thiscriterion, only inodes marked dirty
within a specified minimum period into the past are included in the synchronization process. If the time
stored in this element isbeforethe time held in thedirtied_whenelement of the mapping, the requisite
condition is not satisfied and the kernel does not move the inode from the dirty to thes_iolist.

After the members of thes_iolist have been selected, the kernel starts to iterate over the individual
elements.
Free download pdf