Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


access to data fails for whatever reason — for instance, if a mapping is accessed but has been shrunk by
another process in the meantime and is no longer present at the given address — theSIGBUSsignal is
sent to the process.

4.11 Correction of Userspace Page Faults


Once the architecture-specific analysis of the pagefault has been concluded and it has been established
that the fault was triggered at a permitted address, the kernel must decide on the appropriate method to
read the required data into RAM memory. This task is delegated tohandle_mm_fault, which is no longer
dependent on the underlying architecture but is implemented system-independently within the memory
management framework. The function ensures that page table entries for all directory levels that lead to
the faulty PTE are present. The functionhandle_pte_faultanalyzes the reason for the page fault.entry
is a pointer to the relevant page table element (pte_t).

mm/memory.c
static inline int handle_pte_fault(struct mm_struct *mm,
struct vm_area_struct *vma, unsigned long address,
pte_t *pte, pmd_t *pmd, int write_access)
{
pte_t entry;
spinlock_t *ptl;

if (!pte_present(entry)) {
if (pte_none(entry)) {
if (vma->vm_ops) {
return do_linear_fault(mm, vma, address,
pte, pmd, write_access, entry);
}
return do_anonymous_page(mm, vma, address,
pte, pmd, write_access);
}
if (pte_file(entry))
return do_nonlinear_fault(mm, vma, address,
pte, pmd, write_access, entry);
return do_swap_page(mm, vma, address,
pte, pmd, write_access, entry);
}
...
}

Three cases must be distinguished if the page is not present in physical memory [!pte_present(entry)].


  1. If no page table entry is present (page_none), the kernel must load the page from scratch —
    this is known asdemand allocationfor anonymous mappings anddemand pagingfor
    file-based mappings. This does not apply if there is novm_operations_structregis-
    tered invmops— in this case, the kernel must return an anonymous page usingdo
    anonymous_page.

  2. If the page is marked as not present but information on the page is held in the page table,
    this means that the page has been swapped out and must therefore be swapped back in from
    one of the system swap areas (swap-inordemand paging).

Free download pdf