Swap Area

The pages swapped out from memory are stored in a swap area , which may be implemented either as a disk partition of its own or as a file included in a larger partition. Several different swap areas may be defined, up to a maximum number specified by the MAX_SWAPFILES macro (usually set to 32).

Having multiple swap areas allows a system administrator to spread a lot of swap space among several disks so that the hardware can act on them concurrently; it also lets swap space be increased at runtime without rebooting the system.

Each swap area consists of a sequence of page slots : 4,096-byte blocks used to contain a swapped-out page. The first page slot of a swap area is used to persistently store some information about the swap area; its format is described by the swap_header union composed of two structures, info and magic. The magic structure provides a string that marks part of the disk unambiguously as a swap area; it consists of just one field, magic.magic, which contains a 10-character “magic” string. The magic structure essentially allows the kernel to unambiguously identify a file or a partition as a swap area; the text of the string depends on the swapping algorithm version: SWAP-SPACE for Version 1 or SWAPSPACE2 for Version 2. The field is always located at the end of the first page slot.

The info structure includes the following fields:

info.bootbits

Not used by the swapping algorithm; this field corresponds to the first 1,024 bytes of the swap area, which ...

Get Understanding the Linux Kernel, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.