# RBD clones: copy-up, copy-on-read and flatten

*HTML: https://book.ceph-s3.ir/en/lab-rbdclone.html*
*Licence: CC BY-NC-SA 4.0. Author: Ramin Najarbashi.*

[Interactive lab](lab.html)RBD clones: copy-up, copy-on-read and flatten
In the book: [Chapter 3](03-openstack.html#sec-03-9-2)
LabRBD clones: copy-up, copy-on-read and flattenWrite to or read the objects of a clone and see which ones are read from the parent snapshot, when a whole 4 MiB object is copied up and what flatten does; write to the parent too and watch RADOS keep a clone of the object.**2 / 16**objects owned by the clone**8 MiB**data copied up**0**reads sent to the parent**1**object clones on the parentParent (head, writable)Parent snapshot (read-only)p0p1p2·p4p5p6·p8p9p10·p12p13p14·CloneThe clone's own object Read from the parent Empty (sparse) RADOS object cloneWrite to parent object 1; the clone sees no changeRADOS kept the snapshot version of parent object 1Write to clone object 5 (data came from the parent)Copy-up: the whole object 5 (4 MiB) was written from the parent snapshot into the cloneWrite to clone object 0 (data came from the parent)Copy-up: the whole object 0 (4 MiB) was written from the parent snapshot into the cloneCopy-up is the hidden cost of VM clones: the first small writes to a fresh clone each read and write 4 MiB. If a clone lives long or the parent is going away, flatten it (chapter 3).Follows:`src/librbd/io/ObjectRequest.cc :: ObjectReadRequest::read_parent, ObjectReadRequest::copyup` Reading from the parent and copy-on-read`src/librbd/io/CopyupRequest.cc :: CopyupRequest` Copy-up`src/librbd/operation/FlattenRequest.cc` Flatten`src/common/options/rbd.yaml.in :: rbd_clone_copy_on_read (false), rbd_default_clone_format (auto)` Clone optionsA fixed snapshot of the simulator; the interactive version is in the web edition's lab. [Interactive lab: RBD clones: copy-up, copy-on-read and flatten](lab-rbdclone.html)The interactive version needs JavaScript; this is a fixed snapshot.
