Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


This task is simple if highmem support is not enabled. In this case, all pages can be accessed directly so
it is only necessary to return the page address; there is no need to create a mapping explicitly.

The situation is more complicated if highmem pages are actually present. As withvmalloc,the
kernel must first establish an association between the highmem pages and the addresses at which
they are mapped. An area in virtual address space must also be reserved to map the pages, and
finally, the kernel must keep track of which parts of the virtual area are already in use and which are
still free.

Data Structures


As discussed in Section 3.4.2, the IA-32 kernel reserves a region that follows on from thevmallocarea
and extends fromPKMAP_BASEtoFIXADDR_START. This area is used for persistent mappings. The schemes
used by different architectures are similar.

pkmap_count(defined inmm/highmem.m) is an integer array withLAST_PKMAPpositions that contain an
entry for each page that can be persistently mapped. It is, in fact, a usage counter for the mapped pages
with slightly unusual semantics. The number of users in the kernel is not counted, but the number of
users plus 1. If the value of the counter is 2, the mapped page is used at just one point in the kernel. The
counter value 5 indicates that there are four users. Expressed more generally, the counter valuenstands
forn−1 users in the kernel.

As with classic usage counters, 0 means that the associated page is not in use. Counter value 1 has a
special meaning. The page associated with the position has already been mapped but cannot be used
because the TLB of the CPU has not been updated andaccess would either fail or be directed to an
incorrect address.

The kernel makes use of the following data structure to create the association between thepageinstances
of the physical pages and their position in the virtual memory area:

mm/highmem.c
struct page_address_map {
struct page *page;
void *virtual;
struct list_head list;
};

This structure is used to create thepage−→virtualmapping (hence the name of the structure).page
holds a pointer to thepageinstance in the globalmem_maparray, andvirtualspecifies the allocated
position in the kernel virtual address space.

For ease of organization, the mappings are kept in a hash table where thelistelement is used to set up
an overflow list to handle hash collisions.

The hash table is implemented by means of thepage_address_htablearray, not discussed further here.
Thehashfunctionispage_slotfrommm/highmen.c, which determines the page address on the basis
of thepageinstance.page_addressis the front-end function to determine the address of a given page
instance using the data structures just described:
Free download pdf