Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


Table 18-1: Swap Page States

Initial state Target state

Inactive, unreferenced Inactive,referenced

Inactive, referenced Active,unreferenced

Active, unreferenced Active,referenced

18.6.4 Shrinking Zones


The routines for shrinking zones are (among others) supplied with the following information by the other
parts of the kernel:

❑ The NUMA section and the memory zones it contains that are to be processed.
❑ The number of pages to be swapped out.
❑ The maximum number of pages that may be examined to find out if they are suitable for swap-
ping out before the operation is aborted.
❑ The priority assigned to the attempt to free pages. This is not a process priority in the classical
Unixsense, as this would make little sense in kernel mode anyway, but an integer that specifies
how urgently the kernel needs fresh memory. When pages are swapped out in the background
as a preventive measure, this need is not as immediate as when, for example, the kernel has
detected an acute memory shortage and urgently needs fresh memory to execute or complete
an action.

Page selection begins inshrink_zone. However, some more infrastructure must be introduced before we
can discuss the code.

Controlling Scanning


A special data structure that holds the parameters is used to control the scan operation. Notice that
the structure is not only used to pass instructions on how to proceed from the higher level functions
to the lower level ones, but is also used to propagate results in the inverse direction. This informs the
caller on how successful an operation was:

mm/vmscan.c
struct scan_control {
/* Incremented by the number of inactive pages that were scanned */
unsigned long nr_scanned;
/* This context’s GFP mask */
gfp_t gfp_mask;
int may_writepage;
/* Can pages be swapped as part of reclaim? */
int may_swap;
...
int swappiness;
int all_unreclaimable;
int order;
};
Free download pdf