Linux Kernel Architecture

(Jacob Rumans) #1

Page Reclaim


and Swapping


The available RAM memory in a computer is never enough to meet user needs or to always satisfy
memory-intensive applications. The kernel therefore enables seldom-used parts of memory to be
swapped out to block devices, effectively providing more main memory. This mechanism, which
is referred to asswappingorpaging, is implemented transparently by the kernel for application pro-
cesses that automatically profit from it. Swapping, however, is not the only mechanism to evict
pages from memory. If a seldom-used page is backed by a block device (e.g., memory mappings
of files) then the modified pages need not be swapped out, but can be directlysynchronizedwith
the block device. The page frame can be reused, and if the data are required again, it can be recon-
structed from the source. If a page is backed by a file but cannot be modified in memory (e.g., binary
executable data), then it can bediscardedif it is currently not required. All three techniques, together
with the selection of policy for pages that experience little activity, go by the name ofpage reclaim.
Notice that pages allocated for the core kernel (i.e., not for caches) cannot be reclaimed because this
would complicate things more than it would benefit them.

Page reclaim is the cornerstone to one of the kernel’s fundamental decisions with respect to caching.
The size of caches is never fixed, and they can grow as necessary. The rationale behind this is simple:
RAM that is not used for something is simply wasted, so it shouldalwaysbe used to cache some-
thing. If, however, some important task requires memory that is filled by the caches, the kernel can
reclaimmemory to support these needs. This Chapter describes how swapping and page reclaim are
implemented.

18.1 Overview


Synchronization of data with the underlying block device as described in the previous chapter
makes the situation easier for the kernel when the available RAM memory limit has been reached.
Writing back cached data allows some memory pages to be released in order to make RAM available
for more important functions. Since the data involved can be read in again from the block device as
and when required, this does take time, but no information is lost.
Free download pdf