Saturday, July 18, 2009

Copy-On-Write

Copy-On-Write (COW)
  1. optimization strategy used in computer systems
  2. Idea is that if multiple callers ask for resources, they can all be given pointers to the same resource. Now, all "callers" (processes) will be in assumption that "I m holding this X resource; and I can do whatever I want". But, when this "caller" tries to modify its so - called "My resource X", a true private copy is created actually, to prevent the changes becoming visible to other "callers".
  3. Hence, the primary advandage is that if a caller never makes any modifications, *NO PRIVATE COPY IS CREATED*.
In Virtual Memory:
  • COW finds its main-use in virtual memory OS; when a process creates a copy of itself (fork), the pages in memory that might be modified by either the process or its copy, are marked "Copy-On-Write".
  • When one process modifies the memory, the OS kernel intercepts the operation and copies the memory so that changes in one process's memory are not visible to other
COW and MMU
  • COW can be implemented by telling MMU that certain pages in the process's address space are read only.
  • When data is written to these pages, MMU raises an exception which is handled by kernel, which allocates new space in physical memory and makes the page being written to correspond to that new location in physical memory

No comments:

Post a Comment