Snapshot in ext4

Greg Freemyer greg.freemyer at gmail.com
Thu Jan 5 14:35:15 EST 2012


On Wed, Jan 4, 2012 at 4:55 AM, Swapnil Gaikwad <swapnilgaik72 at gmail.com> wrote:
> If we store snapshot on other partition and assign new inode to each file's
> snapshot. Then datablocks of that partition where we store snapshot is
> wasted ? If not how?

That's effectively what a device mapper snapshot does.

Since only _changed_ blocks (inodes, pointer blocks, and data blocks)
are maintained in the snapshot volume, the snapshot volume can be much
smaller than the original volume.

I haven't studied the code, but obviously they have something like:

struct {
   boolean virgin;
   int alt_location;
} map[max_blocks];


So a read from the snapshot is just:

    if (map[block].virgin)
         read(primary_volume, block)
    else
         read(snapshot_volume,map[block].alt_location)

And write to the primary volume becomes

    if (map[block].virgin) {
         alt_loc=alloc_block_in_snapshot()
         map[block].alt_location = alt_loc
         map[block].virgin = false
         copy(block,alt_loc)
   }
    write(primary_volume, block)


Then when your snapshot volume fills up, you have to discard it
because it can't hold anymore changes.  So if your snapshot volume is
only 10% of the size of the primary volume, you can only support
having 10% of the original volume written to.

Greg



More information about the Kernelnewbies mailing list