Chapter 4: Virtual Process Memory
Write access on private page?
Only vma->vm_ops->nopage available?
Allocate page
Write access?
Anonymous page?
Yes
No
Yes
No
_ _do_fault
vma->vm_ops->nopage
vma->vm_ops->fault
anon_vma_prepare
copy_user_highpage
flush_icache_page
mk_pte
pte_mkwrite
lru_cache_add_active
page_add_new_anon_rmap
page_add_file_rmap
update_mmu_cache
Figure 4-19: Code flow diagram for__do_fault.
Given thevm_area_structregion involved, how can the kernel choose which method to use to read the
page?
- The mappedfileobject is found usingvm_area_struct->vm_file.
- A pointer to the mapping itself can be found infile->f_mapping.
- Each address space has special address space operations from which thereadpagemethod
can be selected. The data are transferred from the file into RAM memory usingmapping->
a_ops->readpage(file, page).
If write access is required, the kernel has to distinguish between shared and private mappings. For private
mappings, a copy of the page has to be prepared.
mm/memory.c
static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long address, pmd_t *pmd,
pgoff_t pgoff, unsigned int flags, pte_t orig_pte)
{
...