Copy-On-Write

The copy- on-write method (short COW called, English for copy-on - write) is in the data processing optimization method to avoid unnecessary copies and copy operations, for example, between processes under Unix-like systems, especially during or after a fork system call.

The basic idea of ​​the method is that the copy is only "real " in production once it is changed by one of the parties involved. As long as all parties have not changed their copy, it is enough to save the original once. The copy is thus first "virtual", and is applied only when a delayed first use.

Main memory

When the kernel has to make a memory page in the address space of another process available, it is not necessary to actually copy the data, or to create another time in the main memory when the data is only read, but not write. It is sufficient, once the two access processes to the same memory page. Only when one of the two processes tries to modify the data, they must be actually ( and then only partially ) copied since then distinguish the contents of the memory pages.

This is usually realized in modern central processing units by means of the paging, whereby the two processes to access the same memory page. Both in the address space of the owner of the original, as well as in the owner's copy of the shared memory area is marked " read only " as. Finding a write access instead, the operating system is notified so that it can replace the affected memory page by an actual copy before the actual write access.

File system

For file systems, copy- on-write means that modified blocks are not overwritten but are first written in full to an empty seat. Thereafter, references will be updated on the block in the metadata. Copy- on-write enables transaction- based file systems that can create, among others, without delay memory dumps (or snapshots thereof). Old and metadata blocks are not deleted, but assigned to the respective memory dump.

ZFS or btrfs are well-known representatives of file systems that rely on copy-on -write.

202107
de