the picture shows a case where two processes have mapped a private object into different areas of their virtual memories but share the same physical copy of the object. For each process that maps the private object, the page table entries for the corresponding private area are flagged as read-only, and the area struct is flagged as private copy-on-write. as soon as a process attempts to write to some page in the private area, the write triggers a protection fault.When the fault handler notices that the protection exception was caused by the process trying to write to a page in a private copy-on-write area, it creates a new copy of the page in physical memory, updates the page table entry to point to the new copy, and then restores write permissions to the page
And we know that Linux uses
vm_area_struct (area structs) to characterizes an area of the current virtual address space as:
and I think
vm_flags will be set to "private" for private area so that copy-on-write will work
my question is, let's say the private area for the private object in process 2's virtual memory is called
pa2. so in the beginning, process 2 tries to write a page(let's say the starting virual address is
pa2, which triggers a protection fault, then it is handled and new copy of the page in physical memory is created.
Let's say after a while, the program needs to modify the page starting at
0x404000 again, since
pa2 is still private area, another protection fault will be triggered, then another new copy of the page in physical memory is created, but what about the first new page created during first fault handler?? it is not referenced by the virtual address anymore and it will still reside in physical memory, which is a waste of resource?