Selecting Pages to Be Swapped

The key question faced by the swapping subsystem is always the same. Which pages can be swapped out to ensure maximum benefits at minimum cost to the system? The kernel uses a mixture of the ideas discussed earlier and implements a rough-grained LRU method that makes use of only one hardware feature — the setting of an accessed bit following a page access — because this function is available on all supported architectures and can be emulated with little effort.

In contrast to the general algorithms, the LRU implementation of the kernel is based on two linked lists that are referred to as the active and the inactive list (separate lists exist for each memory zone in the system). As the two names imply, all the pages in active use are on the one list, while all inactive pages that may be mapped into one or more processes but are not very frequently used are held on the other. To distribute the pages between the lists, the kernel performs a regular balancing operation that determines — by means of the above accessed bit — whether a page is regarded as active or inactive, in other words, whether or not it is frequently accessed by the applications in the system. Transfers between the two lists are possible in both directions. Pages can be transferred from active to inactive and vice versa. However, transfer does not take place after every single page access but at longer intervals.

In the course of time, the least frequently used pages collect at the end of the inactive list. When there is a memory shortage, the kernel selects these pages for swap-out. Since these pages have been little used so far, the LRU principle dictates that this will prove least disruptive to system operation.

Continue reading here: Handling Page Faults

Was this article helpful?

0 0