Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


nr_pages = global_page_state(NR_FILE_DIRTY) +
global_page_state(NR_UNSTABLE_NFS);
return pdflush_operation(background_writeout, nr_pages);
}

If the number of writeback pages is not explicitly restricted by passing the parameter 0, the kernel
invokesglobal_page_stateto determine the system-wide number of (file-based) dirty pages in the
system. Apdflushthread is then activated but this time using thebackground_writeoutfunction
andnotwb_kupdate. Although the name of the former includes the word background, it isnotused
to perform background synchronization in the intuitive sense; this is done bywb_kupdate. However,
background_writeoutdoes not explicitly wait on pages to be written to the backing store, but just ini-
tiates a corresponding request, so the background term is justified. When, in contrast, data integrity
synchronization is performed (as is the case when the requests originate from a system call), the ker-
nel does explicitly wait until an issued write request is completed. This then definitely cannot be called
background synchronization anymore.

As already stated, as far as thetechnicalaspects of synchronization are concerned, it is basically irrelevant
whether synchronization is initiated from the periodic mechanism or is requested explicitly. There are
only the following minor differences in detail betweenbackground_writepagesandwb_kupdate:

❑ background_writepagesdoes not require pages to have been dirty for any minimum period
of time before they can be written back. The technical implications are that the value of the
older_than_thiselement of writeback control is set toNULL.
❑ The superblocks are not synchronized inbackground_writepagesbecause the corresponding
sync_superscall is missing.
❑ No timer is set to periodically restart the writeback mechanism.

More important are the places in the kernel at which flushing is initiated. Interestingly,wakeup_pdflush
is invoked with a non-zero argument at only two places in the kernel sources:


  1. Infree_more_memory, which is always used when there is insufficient memory to generate
    page caches. In this case, the argument used is the fixed value of 1,024.

  2. Intry_to_free_pages,thepage reclaimdiscussed in Chapter 18, which employs the
    wakeup_pdflushmethod to write back dirty data in pages regarded as superfluous when
    the caches were scanned. (When laptop mode is in use,try_to_free_pagesalso calls
    wakeup_pdflushwith a zero argument; see Section 17.13.)


All other calls write back all dirty pages; that is, there is no limit on the maximum number of pages.

Understandably, writeback of all dirty pages isa very costly and time-consuming action and
should therefore be used only with extreme care and at very few points in the kernel as indicated
below:

❑ When synchronization of dirty data was requested explicitly by thesyncsystem call.
❑ When emergency synchronization or an emergency remount was requested using the magic
system request key.
❑ balance_dirty_pagesalso instructsbackground_writeoutto write as many pages as possi-
ble. The function is called by the VFS layer when filesystems (or any other part of the kernel)
Free download pdf