I would like to understand properly the swapping in process and yet, couldn't find a thorough explanation how pte's flags of a page are restored once a page is swapped in back to memory- since it's information is " lost" when swapping out and the corresponding disk area's adress is inserted in the pte entry of a swapped out page. I do understand that the flags of a virtual adress are stored in vm_area_struct but couldn't trace the stage when it is used during the swap-in procedure.

another potential problem is - what happens if a parent process forked, and both parent and child's are swapped out: as far as I consider, in both page tables-the read_only flag is on but the vm_area_struct allows writing since both have VM_MAYWRITE permission for some mem-areas but once swapped out the read_only flag in the corresponding pte is "erased" .does the COW technique is still applicable once a page they both points to once the page is swapped in and the child process wants to write?

1 Answer 1


Like you said, the vm_area_struct tells in what memory area the fault happened, and the protection flags are contained in this struct. The function __do_page_fault calls find_vma to get a pointer to the vm_area_struct. This struct is then passed via handle_pte_fault all the way to do_swap_page (in the vm_fault *vmf parameter), which calls mk_pte with the protection bits as parameter.

Your other problem: if a COW page is swapped out and a process wants to write to it. In this case you get a page fault because the page is swapped out. The handler takes care of the situation, and the process goes to sleep until the page has been read in from disk. When the process is scheduled to run again, it re-executes the faulting write instruction and BANG! — we get a new fault, this time since the page is read-only because of the copy-on-write.

  • thanks for completing the picture for the first part I haven't understood! yet, about the second part for clarifying- when a page swapped in- we use the permission's vm_flags of vm_area_struct to recover pte's bits . but we still hold the MAY_WRITE flag which resolves the second page fault you've indicated and then the COW succeeds? if this so, now I understand why we need WRITE flag and also MAY_WRITE flag! Commented Aug 2, 2017 at 7:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .