Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


whensync_sb_inodesis called. Ifsync_sb_inodeswere called withWB_SYNC_NONEin the first pass, then
the inodes would not be on any of these lists anymore, and waiting could not be performed!

For this purpose, the special writeback modeWB_SYNC_HOLDis introduced. It is nearly identical with
WB_SYNC_NONE. The important difference is that inodes that have been synchronized are not removed
froms_ioinsync_sb_inodes, but are placed back onto thes_dirtylist. Thus they are still visible in the
second pass and can be waited for. The block layer can, nevertheless, start to write out data in between
the passes.

The additional CPU time consumed by the redundant invocation of functions during thesyncsys-
tem call is negligible compared to the time needed for the slow I/O operations and is therefore totally
acceptable.

17.15.1 Synchronization of Inodes


sync_inodessynchronizes all dirty inodes. Its code flow diagram is shown in Figure 17-11.

wait set?

sync_inodes

_ _sync_inode

_ _sync_inode

sync_inodes_sb(wait=0)

sync_inodes_sb(wait=1)

sync_blockdev

sync_blockdev

set_sb_syncing(0)

set_sb_syncing(0)

1

1

1 Iterate over the superblocks
of all filesystems mounted
inuserland

Figure 17-11: Code flow diagram forsync_inodes.

sys_syncis afront endthat directs the real synchronization performed in__sync_inodes.Before
__sync_inodesis called, the kernel usesset_sb_syncingto set thes_syncingelement ofstruct
super_blockto 0 for all superblocks. This helps to avoid synchronization of superblocks from
multiple places.

The__sync_inodesfunction iterates over all superblocks andinvokes several methods for each block.
The function has one parameter:

fs/fs-writeback.c
static void __sync_inodes(int wait)

waitis a Boolean variable that decides if the kernel should wait for write operations to finish or not.
Recall from above that this behavior is essential for thesyncsystem call.
Free download pdf