Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


Usually, the interval between two calls of thewb_kupdatefunction is the value specified in
dirty_writeback_centisecs. However, a special situation arises ifwb_kupdatetakeslongerthan the
time specified indirty_writeback_centisecs. In this case, the time of the nextwb_kupdatecall is
postponed until 1 second after theendof the currentwb_kupdatecall. This also differs from the normal
situation because the interval is not calculated as the time between the start of two successive calls but as
the time between the end of one call and the start of the next.

The ball is set rolling when the synchronization layer is initialized inpage_writeback_init,wherethe
kernel first starts the timer. Initial values for thewb_timervariable — primarily thewb_timer_fncallback
function that is invoked when the timer expires — are set statically when the variable is declared in
mm/page-writeback.c. Logically, the timer expiry time changes over time and is reset at the end of each
wb_kupdatecall, as just described.

The structure of the periodically invokedwb_timer_fnfunction is very simple as it consists only of a
pdflush_operationcall bywb_kupdate. At this point, it isnotnecessary to reinitialize the timer because
this is done inwb_kupdate. The timer must be reset in one situation only — if nopdflushthread is
available, the nextwb_timer_fncall is postponed by 1 second by the function itself. This ensures that
wb_kupdateis invoked regularly to synchronize cache data with block device data, even if thepdflush
subsystem is heavily loaded.

17.9 Superblock Synchronization
Superblock data are synchronized by a dedicated function calledsync_supersto differentiate it from
normal synchronization operations. This and otherfunctions relevant to superblocks are defined in
fs/super.c. Its code flow diagram is shown in Figure 17-5.

Superblock dirty?

Iterate over allsuperblocks

write_sb->s_op->write_super

sync_supers

write_super

Figure 17-5: Code flow diagram forsync_supers.

Recall from Chapter 8 that the kernel provides the global listsuper_blocksto hold thesuper_block
instances of all mounted filesystems. As the code flow diagram shows, the initial task ofsync_supers
is to iterate over all superblocks and to check whether they are dirty using thes_dirtelement of
the superblock structure. If they are, the superblock data contents are written to the data medium by
write_super.

Thewrite_supermethod included in the superblock-specificsuper_operationsstructure does the
actual writing. If the pointer is not set, superblock synchronization is not needed for the filesystem (this
is the case with virtual and RAM-based filesystems). For instance, theprocfilesystem uses a null pointer.
Of course, normal filesystems on block devices, such as Ext3 or Reiserfs, provide appropriate methods
(e.g.,ext3_write_super) to communicate with the block layer and write back relevant data.
Free download pdf