Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


17.7.3 Adjustable Parameters


The kernel supports the fine-tuning of synchronization by means of parameters. These can be set by
the administrator to help the kernel assess system usage and loading. Thesysctlmechanism described
in Chapter 10 is used for this purpose, which means that theprocfilesystem is the natural interface to
manipulate the parameters — they are located in/proc/sys/vm/. Four parameters can be set, all of which
are defined inmm/page-writeback.c^3 :

❑ dirty_background_ratiospecifies the percentage of dirty pages at whichpdflushstarts peri-
odic flushing in the background. The default value is 10 so that the update mechanism kicks in
when more than 10 percent of the pages have changed as compared to the backing store.
❑ vm_dirty_ratio(the correspondingsysctlisdirty_ratio) specifies the percentage of dirty
pages (with respect to non-HIGHMEMmemory) at which data flushing will be started. The default
value is 40.
Why is high memory excluded from the percentage? Older kernel versions before 2.6.20 did
not, in fact, distinguish between high and normal memory. However, if the ratio between high
memory and low memory is too large (i.e., ifmain memory is much more than 4 GiB on 32-bit
processors), the default settings fordirty_background_ratioanddirty_ratiowere required
to be scaled back slightly when the writeback mechanism was initialized.
Retaining the default values would have necessitated an excessively large number of
buffer_headinstances, and these would have had to be held in valuable low memory. By
excluding high memory from the calculation, the kernel does not deal with scaling anymore,
which simplifies matters somewhat.
❑ The interval between two invocations of the periodic flushing routine is defined in
dirty_writeback_interval(the correspondingsysctlisdirty_writeback_centisecs). The
interval is specified in hundredths of a second (also calledcentisecondsin the sources). The
default is 500, which equates to an interval of 5 seconds between invocations.
On systems where a very large number of write operations are performed, lowering this value
can have a positive effect, but increasing the value on systems with very few write operations
delivers only small performance gains.
❑ The maximum period during which a page may remain dirty is specified indirty_expire_
interval(thesysctlisdirty_expire_centisecs). Again, the period is expressed is hun-
dredths of a second. The default value is 3,000, which means that a page may remain dirty for a
maximum of 30 seconds before it is written back at the next opportunity.

17.8 Central Control


The key periodic flushing component is thewb_kupdateprocedure defined inmm/page-writeback.c.It
is responsible for dispatching lower-level routines to find the dirty pages in memory and synchronize
them with the underlying block device. As usual, our description is based on a code flow diagram as
shown in Figure 17-4.

The superblocks are synchronized right at the start of the function because this is essential to ensure
filesystem integrity. Incorrect superblock data result in consistency errors throughout the filesystem

(^3) The name of the sysctls differs with the variables names for historical reasons.

Free download pdf