Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping



  1. shrink_inactive_listremoves a selectable number of inactive pages from theinactive
    list of a given zone and transfers them toshrink_page_list, which then reclaims the
    selected pages by issuing requests to the various backing stores to write data back in order
    to free space in RAM.
    If, for any reason, pages cannot be written back (some programs can explicitly prevent write-
    back),shrink_inactive_listmust put them back on the list of active or inactive pages.


18.6.2 Data Structures


Before analyzing these functions in detail, we need to discuss a few of the data structures used by the
kernel. They include page vectors, which — with the help of an array — can hold a specific number of
pages on which the same operation is performed. This is best done in ‘‘batch mode,’’ which is much
quicker than performing the same operation separately on each page. I also examine the LRU cache used
to place pages on theactiveorinactivelist of a zone.

Page Vectors


The following structure is defined in the kernel to group several pages in a small array:

<pagevec.h>
struct pagevec {
unsigned nr;
int cold;
struct page *pages[PAGEVEC_SIZE];
};

This is simply an array with pointers topageinstances that also allow the number of elements they con-
taintobequeriedusingthenrelement. Thepagearray itself provides space forPAGEVEC_SIZEpointers
to pages (the default value is 14).

Thecoldelement is an addition that helps the kernel distinguish betweenhotandcoldpages. Pages
whose data are held in one of the CPU caches are described ashotbecause their data can be accessed very
quickly. Pages not held in the cache are thereforecold. For the sake of simplicity, this property of memory
pages is ignored in the following descriptions.

Page vectors enable operations to be performed on a whole list ofpagestructures;thisissometimes
quicker than performing operations on individual pages. Currently, the kernel provides functions that
are primarily concerned with releasing pages:

❑ pagevec_releasedecrements the usage counter of all pages in the vector batchwise. Pages
whose usage counter value reaches 0 — these are therefore no longer in use — are automati-
cally returned to the buddy system. If the page was on an LRU list of the system, it is removed
from the list, regardless of the value of its usage counter.
❑ pagevec_freereturns the memory space occupied by a collection of pages to the buddy system.
The caller is responsible for ensuring that the usage counter is 0 — which indicates that the pages
are not in use anywhere else — and that they are not included on any LRU list.
❑ pagevec_release_nonlruis a further function for releasingpages that decrements the usage
counter of all pages of a given collection by 1. When the counter reaches 0, the memory
Free download pdf