Chapter3:MemoryManagement
❑ _mapcountindicates how many entries in the page table point to the page.
❑ lruis a list head used to keep the page on various lists that allow grouping the pages into
different categories, most importantly active and inactive pages. Especially the discussion in
Chapter 18 will come back to these lists.
❑ The kernel allows for combining multiple adjacent pages into a largercompound page.Thefirst
page in the cluster is called thehead page, while all other pages are namedtail page. All tail pages
havefirst_pageset to point to the head page.
❑ mappingspecifies the address space in which a page frame is located.indexis the offset within
the mapping. Address spaces are a very general concept used, for example, when reading a file
into memory. An address space is used to associate the file contents (data) with the areas in
memory into which the contents are read. By means of a small trick,^7 mappingis able to hold not
only a pointer, but also information on whether a page belongs to an anonymous memory area
that is not associated with an address space. If the bit with numeric value 1 is set inmapping,the
pointer doesnotpoint to an instance ofaddress_spacebut to another data structure (anon_vma)
that is important in the implementation of reverse mapping for anonymous pages; this struc-
ture is discussed in Section 4.11.2. Double use of the pointer is possible becauseaddress_space
instances are always aligned withsizeof(long); the least significant bit of a pointer to this
instance is therefore 0 on all machines supported by Linux.
The pointer can be used directly if it points normally to an instance ofaddress_space.Ifthetrick
involving setting the least significant bit to 1 is used, the kernel can restore the pointer by means
of the following operation:
anon_vma = (struct anon_vma *) (mapping - PAGE_MAPPING_ANON)
❑ privateis a pointer to ‘‘private‘‘ data ignored by virtual memory management. The pointer can
be employed in different ways depending on page usage. It is mostly used to associate the page
with data buffers as described in the following chapters.
❑ virtualis used for pages in the highmem area, in other words, for pages that cannot be directly
mapped into kernel memory.virtualthen accepts thevirtualaddress of the page.
As the pre-processor statement#ifdef{WANT_PAGE_VIRTUAL}shows, thevirtualelement is
only part ofstruct pageif the corresponding pre-processor constant is defined. Currently, this
is only the case for a few architectures, namely, Motorola m68k, FRV, and Extensa.
All other architectures adopt a different scheme of addressing virtual pages. At the heart of this
is a hash table used to find the address of all highmem pages. Section 3.5.8 deals with the appro-
priate techniques in more detail. Handling the hash table requires some mathematical operations
that are slow on the aforementioned machines, so they chose the direct approach.
Architecture-Independent Page Flags
The different attributes of a page are described by a series of page flags stored as bits in theflags
element ofstruct page. The flags are independent of the architecture used and cannot therefore
provide CPU- or machine-specific information (this information is held in the page table itself as is
shown below).
Not only are the individual flags defined with the help of the pre-processor inpage-flags.h,butalso
macros are generated to set, delete, and query the flags. In doing so, the kernel conforms to a universal
(^7) The trick borders on the unscrupulous but helps save space in one of the most frequently needed kernel structures.