Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


/* Avoid holes within the zone. */
if (unlikely(!pfn_valid_within(pfn)))
break;

cursor_page = pfn_to_page(pfn);
/* Check that we have not crossed a zone boundary. */
if (unlikely(page_zone_id(cursor_page) != zone_id))
continue;
switch (__isolate_lru_page(cursor_page, mode)) {
case 0:
list_move(&cursor_page->lru, dst);
nr_taken++;
scan++;
break;
...
default:
break;
}
}

*scanned = scan;
return nr_taken;
}

The kernel must ignore the target page — it is already contained in the set of selected pages. Processing
must be aborted if the computed interval crosses amemory zone boundary because mixed allocations
(e.g., mixing DMA memory with normal memory) are not allowed.

Notice that__isolate_lru_pagehas an extra parameter that allows for controlling the activity state of
pages that compose the new cluster. Three choices are possible:

mm/vmscan.c
#define ISOLATE_INACTIVE 0 /* Isolate inactive pages. */
#define ISOLATE_ACTIVE 1 /* Isolate active pages. */
#define ISOLATE_BOTH 2 /* Isolate both active and inactive pages. */

The comments say it all —__isolate_lru_pagescan be instructed to take only pages in an active state,
inactive state, or either of the two states. Since the pages are directly selected via their page frame num-
ber and not via an LRU list, all possibilities can arise. Note, however, that unused pages that are not part
of any LRU list are not accepted — the page flagPG_lrumustbe set. Otherwise,__lru_isolate_page
returns the error code-EINVAL.Thisishandledinthedefaultbranch ofcase, and page selection can
be aborted because the kernel cannot hope for a larger continuous interval because of the resulting
hole anymore.

18.6.6 Shrinking the List of Active Pages


Moving pages from the inactive list to the active list is one of the key actions in the implementation
of the policy algorithm for page reclaim because this is where the importance of the various pages
in the system (or, to be more precise, in the zone) is assessed. It therefore comes as no surprise
Free download pdf