Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


Swap
Cache

A

B

C

Swap Area

Swap
Cache

A

B

C

Swap Area

Swap
Cache

A

B

C

Swap Area

Swap In
of A

Swap In
of B,C

Figure 18-5: Swapping a page in via the swap cache.

When a shared page is swapped out, rmap finds all processes that reference the data in the page. Conse-
quently, the relevant page table entries ofallprocesses that reference the page can be updated to indicate
the new position in the swap area. This means that the page data can be swapped out immediately
without having to retain in the swap cache for a lengthy period.

18.4.1 Identifying Swapped-Out Pages


As discussed in Chapter 4, a memory page is identified on the basis of a virtual address using a system
of page tables to find the address of the associated page frame in RAM. This only works if the data are
actually present in memory; otherwise, there is no page table entry. It must also be possible to correctly
identify swapped-out pages; in other words, it must be possible to find the address of a memory page in
a swap area by reference to a given virtual address.

Swapped-out pages are marked in the page table by means of a special entry whose format depends on
the processor architecture used. Each system uses special coding to satisfy the particular requirements.

Common to all CPUs is that the following information is stored in the page table entry of a
swapped-out page:

❑ An indicator that the page has been swapped out.
❑ Thenumber of the swap areain which the page is located.
❑ Anoffsetthat specifies the relevant page slot is also required to enable the page to be found
within the swap area.

The kernel defines an architecture-independent format that can be derived (by the processor-specific
code) from the architecture-dependent data and is used to identify pages in the swap area. The advantage
of this approach is clearly that all swapping algorithms can be implemented regardless of the hardware
used and need not be rewritten for each processor type. The only interface to the actual hardware are the
functions for converting between architecture-specific and architecture-independent representation.
Free download pdf