do_anonymous_page cow
Posted: Tue Feb 18, 2014 10:40 pm
Hi,
I have a question related to read anonymous memory area.
In Linux kernel, when first read anonymous area, a page fault will happen which will call do_anonymous_page
It will allocate a zero-page to delay the real allocation. This page table entry should be marked write-protected.
When the page is written next time, a do_wp_page will be called to handle this situation.
I am not sure how pte_mkspecial will make the page entry as COW.
since in the old version, the entry is created by following function:
I don't know whether this is caused by the the x86 architecture change.
Thanks for your time!
Best Wishes,
Yaohui Hu
I have a question related to read anonymous memory area.
In Linux kernel, when first read anonymous area, a page fault will happen which will call do_anonymous_page
It will allocate a zero-page to delay the real allocation. This page table entry should be marked write-protected.
When the page is written next time, a do_wp_page will be called to handle this situation.
Code: Select all
static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long address, pte_t *page_table, pmd_t *pmd,
unsigned int flags)
{
.....
/* Use the zero-page for reads */
if (!(flags & FAULT_FLAG_WRITE)) {
entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
vma->vm_page_prot));
page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
if (!pte_none(*page_table))
goto unlock;
goto setpte;
}
......
}
since in the old version, the entry is created by following function:
Code: Select all
entry = pte_wrprotect(mk_pte(virt_to_page(empty_zero_page),
vma->vm_page_prot));
Thanks for your time!
Best Wishes,
Yaohui Hu