Introduction to Operating Systems: Unit III: Memory Management

Copy on Write

Memory Management - Introduction to Operating Systems

The fork () system call works by creating a copy of parent's address space for the child process.

Copy on Write

• The fork () system call works by creating a copy of parent's address space for the child process. Instead of copying the entire memory, the child copies just the page tables of the parent process and points to all of the same pages. The pages are by marked with a special Copy on Write (COW) bit.

• Fig. 4.11.1 shows copy on write implementation.

• When the contents of memory are to be updated, the COW bit is checked. If it is set, a new page is allocated, the data from the old page copied, the update is made on the new page and the "copy-on-write" bit is cleared for the new page.

• If one process tries to alter a page, a memory error occurs. The operating system receives an interrupt, sees that the page is shared, makes a copy of the page by physically copying the contents to another page frame and mapping the second page frame to the current process and gets the process to retry the memory access.

• In this way the simple case of fork() and then exec of a simple program does not use any more memory resource except that needed to hold the page tables which is a small percentage of the total virtual memory used.

• Linux, Solaris and Windows operating system used copy on write method.

Introduction to Operating Systems: Unit III: Memory Management : Tag: : Memory Management - Introduction to Operating Systems - Copy on Write