Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


and, in most cases, lead to loss of at least part of the data. This is whysync_supers,whosepurposeis
described in more detail in Section 17.9, is invoked first.


wb_kupdate

sync_supers

global_page_state

writeback_inodes

Congested?

Reset writeback timer

congestion_wait

Figure 17-4: Code flow diagram ofwb_kupdate.

Thereafter, ‘‘normal‘‘ dirty data are written back from the page cache. The kernel invokes the
global_page_statefunction to get a picture of the current status of all system pages in apage_state
instance. The key item of information is the number of dirty pages held in theNR_FILE_DIRTYelement of
thevm_statsarray.


This function then goes into a loop whose code is repeatedly executed until there are no dirty pages
in the system. After awriteback_controlinstance has been started to initiate non-blocking writeback
ofMAX_WRITEBACK_PAGESpages (normally 1,024),writeback_inodeswrites back the data that can be
reached via the inodes. This is quite a lengthy function so it is discussed separately in greater detail in
Section 17.10, but a couple of salient points are listed below:


❑ Notalldirty pages are written back — in fact, the number is restricted toMAX_WRITEBACK_PAGES.
Because inodes are locked during writeback, smaller groups of dirty pages are pro-
cessed to prevent overly long blocking of an inode that adversely affects system
performance.
❑ The number of pages actually written back is transferred betweenwb_kupdateand
writeback_inodesby subtracting the number of pages written back — which are therefore no
longer dirty — from thenr_to_writeelement of thewriteback_controlinstance after each
writeback_inodescall.

Whenwriteback_inodesterminates, the kernel repeats the loop until there are no more dirty pages in
the system.


Thecongestion_waitfunction is invoked if queue congestion occurs (the kernel detects this by means of
the setencountered_congestionelement of the writeback instance). The function waits until congestion
has eased and then continues the loop as normal. Section 17.10 takes a closer look at how the kernel
defines congestion.


Once the loop has finished,wb_kupdatemakes sure that the kernel invokes it again after the interval
defined bydirty_writeback_intervalin order to guarantee periodic background flushing. Low-
resolution kernel timers as discussed in Chapter 15 are used for this purpose — in this particular case,
the timer is implemented by means of the global timer listwb_timer(defined inmm/page_writeback.c).

Free download pdf