Provide a solution to this problem using semaphores. Your solution should provide efficient use of the bridge, but avoid starvation.
For simplicity, assume that the object consists of a number of pages in the source address space, and starts and ends on a page boundary. When the copy is invoked, no new memory frames are allocated and no physical copy operation is performed. Instead, the appropriate page table entries in the destination address space are set to point to the memory frames to which the object is mapped in the source address space. Also, in both address spaces, the protection for those pages is set to read-only so that writes will cause a protection violation.
As long as all processes in the source and destination address spaces only read (or do not access) the page, they continue to actually share the same physical memory frames. When a process in one of the address spaces however attempts to write to the object, a protection violation occurs. This protection violation is called a copy-on-write fault. In response to such a fault, the operating system allocates a new frame, copies the page into the newly allocated frame, and changes the page table entry for that page in the current address space to point to the new frame rather than the original. Also, the protection for the pages in both address spaces is set to its original value.
Your task is to design an implementation of copy-on-write, with the following important simplification. You may assume that it will never happen that an object is first copied from address space A to address space B, and them from address space B to address space C, etc. You must, however, be prepared to handle the case in which an object is first copied from A to B, then from A to C, etc. You may, in addition, assume that processes do not share pages in any other way.
Your solution should consist of three parts:
You may assume the existence of the following primitives:
get_active_pid()
returns the process identifier of
the process currently running.
lookup_frame(pid,va)
returns the frame number
corresponding to virtual address va
of process
pid
.
lookup_prot(pid,va)
returns the protection status of
the page containing virtual address va
of process
pid
.
update_page_table(pid, va, fn, prot)
updates the
page table entry for virtual; address va
of process
pid
to contain frame number fn
and
protection prot
.
get_new_frame()
returns the frame number of a newly
allocated frame. You need not worry about how physical memory
allocation is done, and you may assume that this routine will always
succeed.
copy_frame(frame1, frame2)
copies the contents of
frame1
to frame2
.
resume_write_instruction()
resumes a faulted write
instruction.
Finally, what do you think about the efficiency of copy-on-write? On uniprocessors? On multiprocessors?
![]() |
![]() |
---|