Daily Notes: Copy on write

Tuesday, August 26, 2008

Copy on write is an optimization technique used in system programming. The way COW works is that if multiple clients or callers that requires access to the same resource, you hand them the pointers instead. When one of the callers decides to change the resource, a copy is created (may or may not be private), and the pointers updated, which may be used by the caller that changed it, and other new callers as well. Note that this process is transparent to existing callers, so that those that didn't change the resource still reference the pointer to the original resource.

Examples of copy on write:

snapshots (most modern volume managers) - usually a block map is created when a snapshot is taken, and changes since the snapshot are written to new disk blocks, with the current block map changed accordingly.

calloc function - when memory is allocated, it initially returns or points all pages "allocated" to a page of zeros, and all pages are marked copy-on-write. As data is written, they are intercepted and written to new memory by the MMU and change the address of the page accordingly.

0 Comments: