Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


the selected page frames could very well be unreclaimable. However, an attempt has been made,
and the probability of reclaiming higher-order allocations is drastically increased with lumpy reclaim as
compared to the situation without this technique.


Naturally, there are some complications in practice, but these are best discussed directly with the source
code. The first part ofisolate_lru_pagesis not very interesting. As described above, a single page is
isolated from the LRU list under consideration:


mm/vmscan.c
static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
struct list_head *src, struct list_head *dst,
unsigned long *scanned, int order, int mode)
{
unsigned long nr_taken = 0;
unsigned long scan;

for (scan = 0; scan < nr_to_scan && !list_empty(src); scan++) {
struct page *page;
unsigned long pfn;
unsigned long end_pfn;
unsigned long page_pfn;
int zone_id;

/* Isolate a single LRU page */
...

if (!order)
continue;

Theforloop iterates until the desired number of pages has been scanned. If no desired allocation order
is given inorder, each loop pass continues after isolating a single page from the LRU list.


However, more work is required for lumpy page reclaim. Recall thatpage_to_pfnandpfn_to_page
allow converting between instances ofstruct pageand the corresponding page frame number, and
vice versa:


mm/vmscan.c
zone_id = page_zone_id(page);
page_pfn = page_to_pfn(page);
pfn = page_pfn & ̃((1 << order) - 1);
end_pfn = pfn + (1 << order);
for (; pfn < end_pfn; pfn++) {
struct page *cursor_page;

Since it is desirable for the buddy system that higher allocation orders are order-aligned, the kernel
computes the appropriate page frame interval into which the page frame of the current tag page falls.
Consider, as in the example, that the tag page has page frame 6. The allocation order-aligned intervals
for second-order allocations are [0, 3], [4, 7], [8, 11], and so on. The kernel therefore needs to scan the page
frames 4 to 7, inclusive:


mm/vmscan.c
/* The target page is in the block, ignore it. */
if (unlikely(pfn == page_pfn))
continue;
Free download pdf