What is Copy-on-write?

Copy-on-write

     Copy-on-write (sometimes referred to as "COW") is an optimization strategy used in computer programming. The fundamental idea is that if multiple callers ask for resources which are initially indistinguishable, you can give them pointers to the same resource.
This function can be maintained until a caller tries to modify its "copy" of the resource, at which point a true private copy is created to prevent the changes becoming visible to everyone else. All of this happens transparently to the callers. The primary
advantage is that if a caller never makes any modifications, no private copy need ever be created.

Copy-on-write in virtual memory

     Copy-on-write finds its main use in virtual memory operating systems; when a process creates a copy of itself, 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 operating system's kernel intercepts the operation and copies the memory so that changes in one process's memory are not visible to the other.

     Another use is in the calloc function. This can be implemented by having a page of physical memory filled with zeroes. When the memory is allocated, the pages returned all refer to the page of zeroes and are all marked as copy-on-write. This way, the amount
of physical memory allocated for the process does not increase until data is written. This is typically only done for larger allocations.

     Copy-on-write can be implemented by telling the MMU that certain pages in the process's address space are read-only. When data is written to these pages, the MMU raises an exception which is handled by the kernel, which allocates new space in physical
memory and makes the page being written to correspond to that new location in physical memory.

     One major advantage of COW is the ability to use memory sparsely. Because the usage of physical memory only increases as data is stored in it, very efficient hash tables can be implemented which only use little more physical memory than is necessary to
store the objects they contain. However, such programs run the risk of running out of virtual address space -- virtual pages unused by the hash table cannot be used by other parts of the program. The main problem with COW at the kernel level is the complexity
it adds, but the concerns are similar to those raised by more basic virtual memory concerns such as swapping pages to disk; when the kernel writes to pages, it must copy them if they are marked copy-on-write.

Other applications of copy-on-write

     COW is also used outside the kernel, in library, application and system code. The string class provided by the C++ standard library, for example, was specifically designed to allow copy-on-write implementations. One hazard of COW in these contexts arises
in multithreaded code, where the additional locking required for objects in different threads to safely share the same representation can easily outweigh the benefits of the approach.

     The COW concept is also used in virtualization/emulation software such as Bochs, QEMU, and UML for virtual disk storage. This allows a great reduction in required disk space when multiple VMs can be based on the same hard disk image, as well as increased
performance as disk reads can be cached in RAM and subsequent reads served to other VMs out of the cache.

     The COW concept is also used in maintenance of instant snapshot on database servers like Microsoft SQL Server 2005. Instant snapshots preserve a static view of a database by storing a pre-modification copy of data when underlaying data are updated. Instant
snapshots are used for testing uses or moment-dependent reports and should not be used to replace backups.

     COW may also be used as the underlying mechanism for snapshots provided by logical volume management and Microsoft Volume Shadow Copy Service.

     The copy-on-write technique can be used to emulate a read-write storage on media that require wear levelling or are physically Write Once Read Many.


快照COW的更多相关文章

  1. ROW/COW 快照技术原理解析

    NOTE:ROW/COW 最新更新请跳转<再谈 COW.ROW 快照技术> 目录 目录 快照与备份的区别 Snapshot 快照技术 全量快照 增量快照 COW 写时拷贝快照技术 ROW ...

  2. Linux就这个范儿 第15章 七种武器 linux 同步IO: sync、fsync与fdatasync Linux中的内存大页面huge page/large page David Cutler Linux读写内存数据的三种方式

    Linux就这个范儿 第15章 七种武器  linux 同步IO: sync.fsync与fdatasync   Linux中的内存大页面huge page/large page  David Cut ...

  3. kvm虚拟化一: 图形化的管理方式

    1.安装必要工具yum install -y / qemu-kvm //kvm主程序 libvirt //虚拟化服务库 libguestfs-tools //虚拟机系统管理工具 virt-instal ...

  4. docker的简单操作和端口映射

    一:简介 Docker镜像 在Docker中容器是基于镜像启动的 镜像是启动容器的核心 镜像采用分层设计,最顶层为读写层 使用快照COW技术,确保底层不丢失 通过ifconfig(ip  a)来查看d ...

  5. 再谈 COW、ROW 快照技术

    目录 目录 前言 快照与备份的区别 快照技术 增量快照之 COW 增量快照之 row 前言 在经过了一段时间的实践之后,再次回顾 COW/ROW 快照技术的实现原理,温故而知新. 快照与备份的区别 传 ...

  6. btrfs-snapper 实现Linux 文件系统快照回滚

    ###btrfs-snapper 应用 ----------####环境介绍> btrfs文件系统是从ext4过渡而来的被誉为“下一代的文件系统”.该文件系统具有高扩展性(B-tree).数据一 ...

  7. raw,cow,qcow,qcow2镜像的比较

    在linux下,虚拟机的选择方式有很多,比如vmware for linux,virtual box,还有qemu,在以前,使用qemu的人不多,主要是使用起来有些麻烦,但现在随着Openstack的 ...

  8. lvm snapshot(lvm 快照)

    lvm快照有多种实现方法,其中一种是COW(Copy-On-Write),不用停止服务或将逻辑卷设为只读就可以进行备份,当一个 snapshot创建的时候只是拷贝原始卷里的元数据,而不是物理上的数据, ...

  9. LVM快照(snapshot)备份

    转载自:http://wenku.baidu.com/link?url=cbioiMKsfrxlzrJmoUMaztbrTelkE0FQ8F9qUHX7sa9va-BkkL4amvzCCAKg2hBv ...

随机推荐

  1. C#CRC16 Modbus 效验算法

    CRC校验(循环冗余校验)小知识 CRC即循环冗余校验码(Cyclic Redundancy Check):是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗 ...

  2. C#中String.Empty、NULL与""三者的区别

    String.Empty和""是一样的,都是空,习惯用string.empty. Null和他们就有区别了,就是没有值,也没分配地址,此处可以理解成什么都没有.

  3. 【.net项目中。。】.net一般处理程序使用方法

    1.基本原理图 IsReusable属性用来表示在IHttpHandlerFactory对象创建IHttpHandler的时候是否能够将这个Handler存入池中以便重用. 一般处理程序(HttpHa ...

  4. is_callable — 检测参数是否为合法的可调用结构

    说明 bool is_callable ( callable $name [, bool $syntax_only = false [, string &$callable_name ]] ) ...

  5. 【cocos2dx开发技巧10】cocosStudio的集成以及c++11的新特性

    转发.请保持地址:http://blog.csdn.net/stalendp/article/details/38880997 非常长时间没有碰cocos2dx了,近期又用起来了.花了好几个小时又一次 ...

  6. python 中的"switch"用法

    转载:http://python.jobbole.com/82008/ 为什么Python中没有Switch/Case语句? 不同于我用过的其它编程语言,Python 没有 switch / case ...

  7. 挑战--asp.net 文件夹上传

    今天遇到一个有趣的问题,公司让平安做一个上传文件夹的功能,这个任务具有一定的挑战性哦.上传文件夹,我第一次看到有人这样做,以前都是上传压缩文件,从来就没有见人上传过文件夹,我也从来就没有尝试过.先不讨 ...

  8. 机器学习6—SVM学习笔记

    机器学习牛人博客 机器学习实战之SVM 三种SVM的对偶问题 拉格朗日乘子法和KKT条件 支持向量机通俗导论(理解SVM的三层境界) 解密SVM系列(一):关于拉格朗日乘子法和KKT条件 解密SVM系 ...

  9. redhat安装中文man手册

    1.下载中文man手册 http://download.chinaunix.net/download.php?id=13232&ResourceID=6537 2.上传至服务器并解压 tar ...

  10. excel表格系列

    MicroSoft Excel表格系列问题 1.excel表格修改默认行高 2.[Excel技巧]Excel实现部分保护技巧