Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory



  1. Parts of nonlinear mappings that have been swapped out cannot be swapped in like regular
    pages because the nonlinear association must be restored correctly. The functionpte_file
    allows for checking if the PTE belongs to a nonlinear mapping, anddo_nonlinear_fault
    handles the fault.


A further potential case arises if the region grants write permission for the page but the access mecha-
nisms of the hardwaredo not(thus triggering the fault). Notice that since the page is present in this case,
the aboveifcase is executed and the kernel drops right through to the following code:

mm/memory.c
if (write_access) {
if (!pte_write(entry))
return do_wp_page(mm, vma, address,
pte, pmd, ptl, entry);
entry = pte_mkdirty(entry);
}
...

do_wp_pageis responsible for creating a copy of the page and inserting it in the page tables of the
process — with write access permission for thehardware. This mechanism is referred to ascopy on write
(COW, for short) and is discussed briefly in Chapter 1. When a process forks, the pages are not copied
immediately but are mapped into the address space of the process as ‘‘read-only‘‘ copies so as not to
spend too much time in the (wasteful) copying of information. A separate copy of the page is not created
for the process until write access actually takes place.

The sections below take a closer look at the implementation of the fault handler routines invoked dur-
ing page fault correction. They do not cover how pages are swapped in from a swap area by means of
do_swap_page, as this topic is discussed separately in Chapter 18 and requires additional knowledge of
the structure and organization of the swap layer.

4.11.1 Demand Allocation/Paging


Allocation of pages on demand is delegated todo_linear_fault, which is defined inmm/memory.c.After
some parameter conversion, the work is delegated to__do_fault,andthecodeflowdiagramofthis
function is shown in Figure 4-19.

First of all, the kernel has to make sure that the required data are read into the faulting page. How this is
handled depends on the file that is mapped into the faulting address space, and therefore a file-specific
method is invoked to obtain the data. Usually, it is stored invm->vm_ops->fault. Since earlier kernel
versions used a method with a different calling convention, the kernel must account for the situation in
which some code has not yet been updated to stick to the new convention. Therefore, the old variant
vm->vm_ops->nopageis invoked if nofaultmethod is registered.

Most files usefilemap_faultto read in the required data. The function not only reads in the required
data, but also implements readahead functionality, which reads in pages ahead of time that will most
likely be required in the future. The mechanisms needed to do this are introduced in Chapter 16, which
discusses the function in greater length. At the moment, all we need to know is that the kernel reads the
data from the backing store into a physical memory page using the information in theaddress_space
object.
Free download pdf