Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


install_file_ptefirst removes any existing page table entry withzap_file_pteand then constructs
a new entry using the helper functionpgoff_to_pte, which encodes a given file offset into a format
suitable for a PTE:

mm/fremap.c
static int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long addr, unsigned long pgoff, pgprot_t prot)
{
pte_t *pte;
...
if (!pte_none(*pte))
zap_pte(mm, vma, addr, pte);

set_pte_at(mm, addr, pte, pgoff_to_pte(pgoff));
...
}

The final step insys_remap_file_pagesis to read in the pages of the mapping if this is desired (it can be
prevented by setting the flagMAP_NONBLOCK). This is done usingmake_present_pages, which acts as if a
page fault would have occurred for each single pagein the mapping, and triggers reading the data from
the underlying block device.

4.8 Reverse Mapping


The data structures already discussed enable the kernel to establish a link between a virtual and a physi-
cal address (via the page tables) and between a memory region of a process and its virtual page addresses.
What is still missing is a link between a physical page and the processes to which the page belongs (or,
to be more accurate, to the page table entries of all processes that use the page). This is the very link that
is needed when swapping pages out (see Chapter 18) in order to update all processes that use the page
because the fact that the page has been swapped out must be noted in their page tables.

In this context, it is necessary to distinguish between two similar terms:


  1. When a page is mapped, it is associated with a process but need not necessarily be in
    active use.

  2. The number ofreferencesto a page indicates how actively the page is used. In order to deter-
    mine this number, the kernel must first establish a link between a page and all its users and
    must then resort to a few tricks to find out how actively the page is used.


The first task is therefore to create a link between a page and all points at which it is mapped. To do this,
the kernel uses a few additional data structures and functions and adopts areverse mappingapproach.^13

All mapping actions described above are concerned only with virtual pages, and there was therefore no
need (and no way) to create reverse mappings. The discussion of how the kernel handles page faults and

(^13) Reverse mappings were first introduced during the development of kernel 2.5. They were available as separate patches for 2.4 but
had never been included in the standard sources. Swapping-out of shared pages is much more complicated and inefficient without
this mechanism because the shared page had to be kept in a special cache until the kernel had chosen separately (and independently)
to swap the page out for all processes involved. The implementation of the reverse mapping algorithm was also heavily revised dur-
ing the development of kernel 2.6.

Free download pdf