Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


❑ pages_min,pages_high,andpages_loware ‘‘watermarks‘‘used when pages are swapped out.
The kernel can write pages to hard disk if insufficient RAM memory is available. These three
elements influence the behavior of the swapping daemon.

❑ If more thanpages_highpages are free, the state of the zone is ideal.
❑ If the number of free pages falls belowpages_low, the kernel begins to swap pages out onto
the hard disk.
❑ If the number of free pages falls belowpages_min, the pressure to reclaim pages is
increased because free pages are urgently needed in the zone. Chapter 18 will discuss
various means of the kernel to find relief.

The importance of these watermarks will mainly show in Chapter 18, but they also come into
play in Section 3.5.5.
❑ Thelowmem_reservearray specifies several pages for each memory zone that are reserved for
critical allocations that must not fail under any circumstances. Each zone contributes accord-
ing to its importance. The algorithm to calculate the individual contributions is discussed in
Section 3.2.2.
❑ pagesetis an array to implement per-CPU hot-n-cold page lists. The kernel uses these lists to
store fresh pages that can be used to satisfy implementations. However, they are distinguished
by their cache status: Pages that are most likely still cache-hot and can therefore be quickly
accessed are separated from cache-cold pages. The next section discusses thestruct per_
cpu_pagesetdata structure used to realize this behavior.
❑ free_areais an array of data structures of the same name used to implement the buddy system.
Each array element stands for contiguous memory areas of a fixed size. Management of free
memory pages contained in each area is performed starting fromfree_area.
The employed data structures merit a discussion of their own, and Section 3.5.5 covers the imple-

Structure of the Buddy System


❑ The elements of the second section are responsible for cataloging the pages used in the zone
according to activity. A page is regarded asactiveby the kernel if it is accessed frequently; an
inactive page is obviously the opposite. This distinction is important when pages need to be
swapped out. If possible, frequently used pages should be left intact, but superfluous inactive
pages can be swapped out without impunity.
The following elements are involved:

❑ active_listcollects the active pages, andinactive_listthe inactive pages (page
instances).
❑ nr_scan_activeandnr_scan_inactivespecify how many active and inactive pages are
to be scanned when reclaiming memory.
❑ pages_scannedspecifies how many pages were unsuccessfully scanned since the last time
a page was swapped out.
❑ flagsdescribes the current status of the zone. The following flags are allowed:
<mmzone.h>
typedef enum {
ZONE_ALL_UNRECLAIMABLE, /* all pages pinned */
ZONE_RECLAIM_LOCKED, /* prevents concurrent reclaim */
Free download pdf