Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


swap_aopsis defined as follows:

mm/page_io.c
static struct address_space_operations swap_aops = {
.writepage = swap_writepage,
.sync_page = block_sync_page,
.set_page_dirty = __set_page_dirty_nobuffers,
};

We will look at the significance and implementation of these functions more closely later on. Initially, it
is sufficient to outline what they do:


  1. swap_writepagesynchronizes dirty pages with the underlying block device. This is not done
    to maintain consistency between RAM memory and the block device, as is the case for all
    other page caches. Its purpose is toremovepages from the swap cache and to transfer their
    data to a swap area. The function is therefore responsible for implementing data transfer
    between RAM memory and the swap area on the disk.

  2. Pages must be marked as ‘‘dirty’’ in the swap cache without having to allocate new
    memory — a resource that is scarce enough anyway when swap-out mechanisms are used.
    As discussed in Chapter 16, one possible procedure to mark pages as dirty is to create
    buffers that enable the data to be written back chunk-by-chunk. However, additional
    memory is needed to hold thebuffer_headinstances that store the required management
    data. This is pointless as only complete pages in the swap cache are written back anyway.
    The__set_page_dirty_nobuffersfunction is therefore used to mark pages as dirty; it sets
    thePG_dirtyflag but does not create buffers.

  3. As with most other page caches, the standard implementation of the kernel
    (block_sync_page) is used to synchronize pages in the swap area. This function
    does nothing more than unplug to corresponding block queues. As far as the swap cache is
    concerned, this means that all data transfer requests forwarded to the block layer are then
    executed.


All ‘‘static’’ elements of the swap cache have been introduced, and the fundamentals upon which the
swapping implementation rests are in place. Before discussing how they are brought to use in live action,
let us briefly survey the functions that we will encounter in due course — there is a considerable number
of them. Figure 18-7 shows the most important ones and how they are connected.

The figure resembles the rough overview from Figure 18-4, but provides many more details. The general
structure introduced there can be immediately recognized. The individual functions that realize this
structure are discussed in the remainder of this chapter.

18.4.3 Adding New Pages


Adding new pages to the swap cache is a very simple matter because the appropriate page cache mech-
anisms are used. The standard methods reduce the requisite effort to invoking theadd_to_page_cache
function described in Chapter 16. This function inserts the data structure of a given page into the corre-
sponding lists and trees of theswapper_spaceaddress space.

However,thisdoesnotconstitutethewholeofthetask.Thepageisnotonlyaddedtotheswapcache,
but also requires space in one of the swap areas. Even though the data are not yet copied to hard disk at
Free download pdf