Copy-on-write

from Wikipedia, the free encyclopedia

The copy-on-write procedure (short COW called English literally for "copy-on-write") is in the data processing optimization method to avoid extra copies, and copy operations, such as between processes under Unix-like systems , particularly during or after a fork -System call.

The basic idea of ​​the procedure is that the copy is only made "in real" as soon as it is changed by one of the parties involved. As long as all those involved have not changed their copy, it is sufficient to save the original once. The copy is assigned its own inode , but the pointer structures stored in it that point to the data blocks match those of the original. Only when one of the data blocks is changed is a new data block used for the change and the corresponding pointer reset. If the data blocks have not been changed, the original blocks can still be referenced.

Main memory

If the kernel has to make a memory page available in the address space of another process , it is not necessary to actually copy the data or to create it again in main memory if the data is only read out but not written. It is sufficient if the two processes first access one and the same memory page. Only when one of the two processes tries to change the data do they actually (and then only partially) be copied, since the contents of the memory pages then differ.

This is usually implemented on modern main processors with the help of paging , with the two processes accessing the same memory page. This shared memory area is marked as "read-only" both in the address space of the owner of the original and that of the owner of the copy. If write access takes place, the operating system is informed so that it can replace the affected memory page with an actual copy before the actual write access.

File system

In the case of file systems , copy-on-write means that changed blocks are not overwritten, but are first copied completely to a free space. References to the block in the metadata are then updated. Copy-on-write enables transaction-based file systems that, among other things, can create memory images (or snapshots of them) without delay . Old metadata and blocks are not deleted, but assigned to the respective memory image.

ZFS , Btrfs , APFS and NILFS are well-known representatives of file systems that rely on copy-on-write .

Individual evidence

  1. Ralph Tandetzky: cow_ptr - The Smartpointer for Copy-On-Write. In: Informatik Aktuell: Development / Programming Languages. Alkmene Verlags- und Mediengesellschaft mbH, September 19, 2017, accessed on November 28, 2018 : "Copy-On-Write means that when copying a data structure X" under the hood "only a pointer (or reference) to the internal data is passed on. A real and deep copy of the actual data is only carried out when an instance of X changes its internal data. "
  2. Copy-on-Write. In: ITwissen.info. DATACOM Buchverlag GmbH, 2018, accessed on November 28, 2018 : "Copy-on-Write, which stands for" copy while writing ", copies are made when a user has changed copies."

See also