Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


Reading the SwapArea Characteristics


The characteristics of a swap area are held in the first page slot of the area. The kernel uses the following
structure to interpret these data:

<swap.h>
union swap_header {
struct
{
char reserved[PAGE_SIZE - 10];
char magic[10]; /* SWAP-SPACE or SWAPSPACE2 */
} magic;
struct
{
char bootbits[1024]; /* Space for disklabel etc. */
__u32 version;
__u32 last_page;
__u32 nr_badpages;
unsigned char sws_uuid[16];
unsigned char sws_volume[16];
__u32 padding[117];
__u32 badpages[1];
} info;
};

Theunionallowsidenticaldata to be interpreted in different ways, as illustrated in Figure 18-2.

❑ The first 1,024 bytes are left free to create space for boot loaders that on some architectures must
be present at defined places on the hard disk. This enables swap areas to be positioned right at
the start of a disk on such architectures even though boot loader code is also located there.
❑ Details of the swap area version (version) then follow, plus the number of the last page
(nr_lastpage) and the number of unusable pages (nr_badpages). A list with the number
of unusable blocks follows after 117 integer filler entries, which can be used for additional
information in any new versions of the swap format. Even if formally this list has only one
element in the data structure, it has in realitynr_badpagesmembers.
labelanduuidallow associating a label and a UUID (Universally Unique Identifier) with a
swap partition. The kernel does not use these fields, but they are required by some userland
tools (the manual pageblkid8 provides more information about the rationale behind these
identifiers).

“SWAPSPACE2”

struct info

struct swap_header
Figure 18-2: Layout of the swap header.

The reason why two data structures are used to analyze this information is historical (new information is
created only in areas that were not used by the old format — in other words, between the 1,024 reserved
Free download pdf