Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


This function yields the required page by reference to aswp_entry_tinstance by scanning the
swapper_spaceaddress space using the familiarfind_get_pagefunction discussed in Chapter 16. As
for many other address space related tasks, all the hard work is done by the radix tree implementation!
Note that if the page is not found, the code returns a null pointer. The kernel must then fetch the data
from the hard disk.

18.5 Writing Data Back


Another part of the swapping implementation is the ‘‘downward’’ interface that is used to write page
data to a selected reserved position in the swap area (or, to be precise, that issues the appropriate request
to the block layer). As you have seen, this is done from the swap cache using thewritepageaddress space
operation, which points toswap_writepage. Figure 18-10 shows the code flow diagram of the function
defined inmm/page_io.c.

swap_writepage

remove_exclusive_swap_page

get_swap_bio

map_swap_page

set_page_writeback

submit_bio

Set up bio instance

Figure 18-10: Code flow diagram for
swap_writepage.

As most of the work has been done by the above mechanisms, there is little left forswap_writepageto do.
The very first thing the kernel does is to invokeremove_exclusive_swap_pageto check that the relevant
page is used by the swap cache but not by any other parts of the kernel. If this is true, the page is no
longer needed and can be removed from memory.

Before the kernel can write the page data, it requires a correctly filled instance ofstruct biowith
all the parameters needed for the block layer — as discussed in Chapter 6. This task is delegated to
get_swap_bio, which returns a finishedbioinstance.

Not only the destination block device and the length of the data to be written back, but more particularly,
the sector number, are required when thebiostructure is filled. As discussed above in Section 18.3.1, it
is not always certain that a swap area is located in a contiguous area on disk. Consequently, extents are
used to create a mapping between the page slots and the available blocks. This extent list must now be
searched:

mm/page_io.c
sector_t map_swap_page(struct swap_info_struct *sis, pgoff_t offset)
{
struct swap_extent *se = sis->curr_swap_extent;
struct swap_extent *start_se = se;
Free download pdf