Docker practice (3)-Analysis of Thin provoision of device mapeper

Source: Internet
Author: User

Thin provision is introduced in kernel3.2. It has the following features:

(1) Allow multiple virtual devices to be stored in the same data volume to share data and save space;

(2) snapshots of any depth are supported. The previous implementation of the performance is O (n), the new implementation through a separate data to avoid performance decreases with the increase of snapshot depth.

(3) metadata can be stored on individual devices. In this way, metadata can be stored on an image device or a faster SSD.

The above three features are the key features that devicemapper supports docker to store images.

 

Use LVM to manage thin provisioning

# Dd If =/dev/Zero of = lvm0.img BS = 1024 k count = 256

# Losetup/dev/loop7 lvm0.img

# Losetup-

/Dev/loop0: [fd00]: 786725 (/dev/loop0)

/Dev/loop1: [fd00]: 786726 (/dev/loop1)

/Dev/loop7: [fd00]: 420986 (/root/LVM/lvm0.img)

 

# Pvcreate/dev/loop7

Physical Volume "/dev/loop7" successfully created

# Vgcreate vg_test/dev/loop7

Volume group "vg_test" successfully created

 

Create a thin pool in the volume group. The size is 200 MB:

# Lvcreate-L 200 m-T vg_test/mythinpool

Logical volume "lvol0" created

Logical volume "mythinpool" created

 

# Ls/dev/mapper/* | grep mythin

/Dev/mapper/vg_test-mythinpool

/Dev/mapper/vg_test-mythinpool_tdata

/Dev/mapper/vg_test-mythinpool_tmeta

/Dev/mapper/vg_test-mythinpool-tpool

 

Create thin logical volume:

# Lvcreate-T vg_test/mythinpool-V 300 m-N lvol1

Logical volume "lvol1" created

Although the thin pool is only 200 m, you can create a logical volume of M.

# LVS

Lv vg attr lsize pool ORIGIN data % Move log CPY % sync convert

Lvol1 vg_test VWI-a-tz -- 300.00 M mythinpool 0.00

Mythinpool vg_test twi-a-tz -- 200.00 M 0.00

 

Create a snapshot:

# Lvcreate-s -- name mysnapshot1 vg_test/lvol1

Logical volume "mysnapshot1" created

 

Use DMSetup to manage thin provisioning

Create thin pool

DMSetup create pool \

-- Table "0 20971520 thin-pool $ metadata_dev $ data_dev \

$ Data_block_size $ low_water_mark"

 

# DMSetup create yy_thin_pool -- table '0 409600 thin-pool/dev/loop6/dev/loop7 128 0'

# DMSetup table/dev/mapper/yy_thin_pool

0 409600 thin-pool 128 0 0

# DMSetup remove yy_thin_pool

 

Create thinly-provisioned volume

First, you must send a message to the pool:

DMSetup message/dev/mapper/yy_thin_pool 0 "create_thin 0"

Here, "0" is the volume identifier, a 24-digit number, which is allocated by the caller. if it already exists, the-eexist error is returned.

 

Use thinly-provisioned volume

Create a 20 m volume

DMSetup create thin -- table "0 40960 thin/dev/mapper/yy_thin_pool 0"

# DMSetup table/dev/mapper/thin

0 40960 thin 253: 3 0

# Mkfs. ext4/dev/mapper/thin

# Mount/dev/mapper/thin/mnt/share1

/Dev/mapper/thin 20 m 1.2 m 18 m 7%/mnt/share1

 

Internal snapshots

Create Snapshot

To create a snapshot for an active volume, you must first create a suspend volume.

DMSetup suspend/dev/mapper/thin

DMSetup message/dev/mapper/yy_thin_pool 0 "create_snap 1 0"

DMSetup resume/dev/mapper/thin

DMSetup create snap -- table "0 40960 thin/dev/mapper/yy_thin_pool 1"

The red part is the snapshot name.

 

Delete volume

DMSetup remove thin

DMSetup message/dev/mapper/yy_thin_pool 0 "delete 0"

 

Docker Structure

The internal storage structure of docker is roughly as follows:

During the initialization process, docker creates a GB sparse file for storing data and a 2 GB sparse file for storing metadata, then, attach the device to/dev/loop0 and/dev/loop1. Create a thin pool based on the loopback block device.

 

 

When docker creates an image, it writes the image information (struct DevInfo) to the file/var/lib/docker/devicemapper/metadata/$ id. For details, refer to the function (devices * deviceset) registerdevice.

 

References

[1] https://www.kernel.org/doc/Documentation/device-mapper/thin-provisioning.txt


YY brother
Source: http://www.cnblogs.com/hustcat/
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.