Adding New Pages

Adding new pages to the swap cache is a very simple matter because the appropriate page cache mechanisms are used. The standard methods reduce the requisite effort to invoking the add_to_page_cache function described in Chapter 16. This function inserts the data structure of a given page into the corresponding lists and trees of the swapper_space address space.

However, this does not constitute the whole of the task. The page is not only added to the swap cache, but also requires space in one of the swap areas. Even though the data are not yet copied to hard disk at this point, the kernel must nevertheless consider which area it wants to select for the page and into which slot it will be inserted. This decision must then be saved in the data structures of the swap cache.

Page fault management Page Reclaim swapin_readahead

Architecture-specific page fault handler do_swap_page I

Zone scanning shrink_page_listI

Tranfer swap data to swap space and handle page tables read_swap_cache_async add_to_swap

__add_to_swap_cache try_to_unmap try_to_unmap_one

Page Cache Management

Reverse Mapping

Figure 18-7: Overview of the most important functions that implement swapping and page reclaim. The figure is not a proper code flow diagram and skips some intermediate functions.

Two kernel methods add pages to the swap cache but serve different purposes:

1. add_to_swap is invoked when the kernel wants to swap out a page actively; that is, when the policy algorithm has determined that insufficient memory is available. The routine not only adds the page to the swap cache (where it remains until its data are written to disk), but also reserves a slot in one of the swap areas.

2. When a page shared by several processes (this can be determined by referring to the usage counter in the swap area) is read in from the swap area, the page is retained in both the swap area and the swap cache until it is either swapped out again or until it is swapped in by all the processes that share it. The kernel implements this behavior by means of the add_to_swap_cache function, which adds a page to the swap cache without performing operations on the swap areas themselves.

Continue reading here: Reserving Page Slots

Was this article helpful?

0 0