Regarding Copy on Write in ext4

Greg Freemyer greg.freemyer at gmail.com
Wed Jan 4 18:11:07 EST 2012


On Wed, Jan 4, 2012 at 4:45 AM, Swapnil Gaikwad <swapnilgaik72 at gmail.com> wrote:
> How Copy on Write ( COW )is implemented in ext4?
> Help me in understanding design issues in it.
> Is anybody have source code of it with proper documentation.
>
> --
>     Regards,
>
> Swapnil Gaikwad.

Do you read the answers to your questions?

I said COW (copy on write) is typically implemented below the
filesystem layer and is filesystem agnostic.

I am not aware of a ext4 specific COW implementation.

Thus in the linux kernel it is implemented in device mapper and that
code works for all hard disk based filesystems.

For finding source, get familiar with:

http://lxr.linux.no/#linux+v3.1.7/

That's a nice linux kernel source browser.  Or of course you can
download the full kernel source tarball from kernel.org and browse
through it locally.

At the root of the kernel source tree is the Documentation directory.
It's not typically the most detailed, but it is always a good place to
start to look for basic docs about kernel systems.

In this case device-mapper has a sub-folder of its own:

http://lxr.linux.no/#linux+v3.1.7/Documentation/device-mapper/

And in that folder is a file dedicated to device mapper snapshots:

http://lxr.linux.no/#linux+v3.1.7/Documentation/device-mapper/snapshot.txt

Read that first to get a high level understanding of what snapshots
are good for.

You will find in that doc:
===
In the first two cases, dm copies only the chunks of data that get
  changed and uses a separate copy-on-write (COW) block device for storage.

  For snapshot merge the contents of the COW storage are merged back
into the origin device.
===

That is telling you that DM (device mapper) uses a dedicated volume
for each snapshot.  When a data block is first overwritten, the
original data is moved to the snapshot volume and then the primary
volume gets updated with the new data.

Then there are is a bitmap file that keeps track of which data blocks
still have original data in them and which don't.

I suspect the best documentation is the source code itself.

http://lxr.linux.no/#linux+v3.1.7/drivers/md/dm-snap.c

is one of the source files.

Greg



More information about the Kernelnewbies mailing list