Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


laptop_timer_fnstartspdflushwithlaptop_flushas the worker function. This causes a full
synchronization to be performed.
❑ Recall from above thatbalance_dirty_pagesactivates apdflushthread if the ratio of dirty
pages in memory becomes too high. In laptop mode, however,pdflushis started as soon as
some data have been written.
❑ try_to_free_pagesis also slightly modified. If the routine decides to use apdflushthread, then
the number of pages that may be written back is not limited. This makes sense because if the disk
needs to be spun up, then as much I/O as possible should be triggered.

Notice finally that laptop mode benefits from setting the values in/proc/sys/vm/dirty_writeback_
centisec /proc/sys/vm/dirty_expire_centisecto large values. This will delay write operations
longer than usual. When a write operation finally takes place, then the changes in laptop mode as
described above automatically ensure that the spinning disk is brought to good use.

17.14 System Calls for Synchronization


Control


The kernel synchronization mechanisms can be enabled from within userspace by various system calls to
ensure full or partial data integrity between memory and block devices. Three basic options are available:


  1. Theentirecache contents can be flushed using thesyncsystem call; in certain circumstances,
    this can be very time-consuming.

  2. The contents of individual files (as well as the associated metadata of the inode) can be trans-
    ferred to the underlying block device. The kernel provides thefsyncandfdatasyncsystem
    calls for this purpose. Whereassyncis normally used in conjunction with thesyncsystem
    tool mentioned above,fsyncandfdatasyncare reserved for particular applications because
    the files to be flushed are selected by means of the process-specific file descriptors introduced
    in Chapter 8. There are therefore no generic userspace tools for writing back specific files.

  3. msyncis used to synchronize memory mappings.


17.15 Full Synchronization


As per kernel convention, thesyncsystem call is implemented insys_sync. Its code is held in
fs/buffer.c, and the associated code flow diagram is shown in Figure 17-10.

The routine is very simply structured and consists of a chain of function calls (viado_sync) starting with
wakeup_pdflush, which is invoked with the parameter 0. As described above, this triggers writeback of
alldirty pages in the system.

The next step is synchronization of the inode metadata by means ofsync_inodes. This is the first time
we have come across this procedure that ensures that all inodes are written back. We take a closer look
at it below.

sync_supersiterates over all superblocks in thesuper_blockslist and callssuper_block->write_super
if the routine exists. This triggers writing the superblock-specific information for each filesystem.
Free download pdf