Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


area management is theswap_infoarray defined inmm/swap-info.c; its entries store information on the
individual swap areas in the system^1 :

mm/swapfile.c
struct swap_info_struct swap_info[MAX_SWAPFILES];

The number of elements is defined statically inMAX_SWAPFILESat compilation time. The constant is
normally defined as 2^5 =32.

The kernel uses the termswap fileto refer not only to swap files but also to swap
partitions; the array therefore includes both types. As normally only one swap file is
used, the limitation to a specific number is of no relevance. Neither does this
number impose any kind of restriction on numerical calculations or other
memory-intensive programs because, depending on architecture, swap areas may
now have sizes in the gigabyte range. The restriction to 128 MiB in older versions
no longer applies.

Characterizationof SwapAreas


struct swap_info_structdescribes a swap area and is defined as follows:

<swap.h>
struct swap_info_struct {
unsigned int flags;
int prio; /* swap priority */
struct file *swap_file;
struct block_device *bdev;
struct list_head extent_list;
struct swap_extent *curr_swap_extent;
unsigned short * swap_map;
unsigned int lowest_bit;
unsigned int highest_bit;
unsigned int cluster_next;
unsigned int cluster_nr;
unsigned int pages;
unsigned int max;
unsigned int inuse_pages;
int next; /* next entry on swap list */
};

The main data on the swap state can be quickly queried with the help of theprocfilesystem:

wolfgang@meitner>cat /proc/swaps
Filename Type Size Used Priority
/dev/hda5 partition 136512 96164 1
/mnt/swap1 file 65556 6432 0
/tmp/swap2 file 65556 6432 0

(^1) During the development of kernel 2.6.18, the ability to migrate pages physically between NUMA nodes while keeping their virtual
addresses has been added. This requires using twoswap_infoentries to handle pages that are currently under migration, so the
number of possible swap files is reduced. The configuration optionMIGRATIONis required to include the page migration code. This
is, for instance, helpful on NUMA systems, where pages can be moved nearer to processors using them, or for memory hot remove.
Page migration, however, is not considered in detail in this book.

Free download pdf