blob: 8a7a3d46e0daa00d6f87315648b7cb292e8c05b4 [file] [log] [blame]
Joe Thornber991d9fa2011-10-31 20:21:18 +00001Introduction
2============
3
Masanari Iida4998d8e2012-02-16 22:14:34 +09004This document describes a collection of device-mapper targets that
Joe Thornber991d9fa2011-10-31 20:21:18 +00005between them implement thin-provisioning and snapshots.
6
7The main highlight of this implementation, compared to the previous
8implementation of snapshots, is that it allows many virtual devices to
9be stored on the same data volume. This simplifies administration and
10allows the sharing of data between volumes, thus reducing disk usage.
11
12Another significant feature is support for an arbitrary depth of
13recursive snapshots (snapshots of snapshots of snapshots ...). The
14previous implementation of snapshots did this by chaining together
15lookup tables, and so performance was O(depth). This new
16implementation uses a single data structure to avoid this degradation
17with depth. Fragmentation may still be an issue, however, in some
18scenarios.
19
20Metadata is stored on a separate device from data, giving the
21administrator some freedom, for example to:
22
23- Improve metadata resilience by storing metadata on a mirrored volume
24 but data on a non-mirrored one.
25
26- Improve performance by storing the metadata on SSD.
27
28Status
29======
30
31These targets are very much still in the EXPERIMENTAL state. Please
32do not yet rely on them in production. But do experiment and offer us
33feedback. Different use cases will have different performance
34characteristics, for example due to fragmentation of the data volume.
35
36If you find this software is not performing as expected please mail
37dm-devel@redhat.com with details and we'll try our best to improve
38things for you.
39
40Userspace tools for checking and repairing the metadata are under
41development.
42
43Cookbook
44========
45
46This section describes some quick recipes for using thin provisioning.
47They use the dmsetup program to control the device-mapper driver
48directly. End users will be advised to use a higher-level volume
49manager such as LVM2 once support has been added.
50
51Pool device
52-----------
53
54The pool device ties together the metadata volume and the data volume.
55It maps I/O linearly to the data volume and updates the metadata via
56two mechanisms:
57
58- Function calls from the thin targets
59
60- Device-mapper 'messages' from userspace which control the creation of new
61 virtual devices amongst other things.
62
63Setting up a fresh pool device
64------------------------------
65
66Setting up a pool device requires a valid metadata device, and a
67data device. If you do not have an existing metadata device you can
68make one by zeroing the first 4k to indicate empty metadata.
69
70 dd if=/dev/zero of=$metadata_dev bs=4096 count=1
71
72The amount of metadata you need will vary according to how many blocks
73are shared between thin devices (i.e. through snapshots). If you have
74less sharing than average you'll need a larger-than-average metadata device.
75
76As a guide, we suggest you calculate the number of bytes to use in the
77metadata device as 48 * $data_dev_size / $data_block_size but round it up
Mike Snitzerc4a69ec2012-03-28 18:41:28 +010078to 2MB if the answer is smaller. If you're creating large numbers of
79snapshots which are recording large amounts of change, you may find you
80need to increase this.
Joe Thornber991d9fa2011-10-31 20:21:18 +000081
Mike Snitzerc4a69ec2012-03-28 18:41:28 +010082The largest size supported is 16GB: If the device is larger,
83a warning will be issued and the excess space will not be used.
Joe Thornber991d9fa2011-10-31 20:21:18 +000084
85Reloading a pool table
86----------------------
87
88You may reload a pool's table, indeed this is how the pool is resized
89if it runs out of space. (N.B. While specifying a different metadata
90device when reloading is not forbidden at the moment, things will go
91wrong if it does not route I/O to exactly the same on-disk location as
92previously.)
93
94Using an existing pool device
95-----------------------------
96
97 dmsetup create pool \
98 --table "0 20971520 thin-pool $metadata_dev $data_dev \
99 $data_block_size $low_water_mark"
100
101$data_block_size gives the smallest unit of disk space that can be
Carlos Maiolinoa561ddb2013-07-23 11:03:16 -0300102allocated at a time expressed in units of 512-byte sectors.
103$data_block_size must be between 128 (64KB) and 2097152 (1GB) and a
104multiple of 128 (64KB). $data_block_size cannot be changed after the
105thin-pool is created. People primarily interested in thin provisioning
106may want to use a value such as 1024 (512KB). People doing lots of
107snapshotting may want a smaller value such as 128 (64KB). If you are
108not zeroing newly-allocated data, a larger $data_block_size in the
109region of 256000 (128MB) is suggested.
Joe Thornber991d9fa2011-10-31 20:21:18 +0000110
111$low_water_mark is expressed in blocks of size $data_block_size. If
112free space on the data device drops below this level then a dm event
113will be triggered which a userspace daemon should catch allowing it to
114extend the pool device. Only one such event will be sent.
115Resuming a device with a new table itself triggers an event so the
116userspace daemon can use this to detect a situation where a new table
117already exceeds the threshold.
118
119Thin provisioning
120-----------------
121
122i) Creating a new thinly-provisioned volume.
123
124 To create a new thinly- provisioned volume you must send a message to an
125 active pool device, /dev/mapper/pool in this example.
126
127 dmsetup message /dev/mapper/pool 0 "create_thin 0"
128
129 Here '0' is an identifier for the volume, a 24-bit number. It's up
130 to the caller to allocate and manage these identifiers. If the
131 identifier is already in use, the message will fail with -EEXIST.
132
133ii) Using a thinly-provisioned volume.
134
135 Thinly-provisioned volumes are activated using the 'thin' target:
136
137 dmsetup create thin --table "0 2097152 thin /dev/mapper/pool 0"
138
139 The last parameter is the identifier for the thinp device.
140
141Internal snapshots
142------------------
143
144i) Creating an internal snapshot.
145
146 Snapshots are created with another message to the pool.
147
148 N.B. If the origin device that you wish to snapshot is active, you
149 must suspend it before creating the snapshot to avoid corruption.
150 This is NOT enforced at the moment, so please be careful!
151
152 dmsetup suspend /dev/mapper/thin
153 dmsetup message /dev/mapper/pool 0 "create_snap 1 0"
154 dmsetup resume /dev/mapper/thin
155
156 Here '1' is the identifier for the volume, a 24-bit number. '0' is the
157 identifier for the origin device.
158
159ii) Using an internal snapshot.
160
161 Once created, the user doesn't have to worry about any connection
162 between the origin and the snapshot. Indeed the snapshot is no
163 different from any other thinly-provisioned device and can be
164 snapshotted itself via the same method. It's perfectly legal to
165 have only one of them active, and there's no ordering requirement on
166 activating or removing them both. (This differs from conventional
167 device-mapper snapshots.)
168
169 Activate it exactly the same way as any other thinly-provisioned volume:
170
171 dmsetup create snap --table "0 2097152 thin /dev/mapper/pool 1"
172
Joe Thornber2dd9c252012-03-28 18:41:28 +0100173External snapshots
174------------------
175
176You can use an external _read only_ device as an origin for a
177thinly-provisioned volume. Any read to an unprovisioned area of the
178thin device will be passed through to the origin. Writes trigger
179the allocation of new blocks as usual.
180
181One use case for this is VM hosts that want to run guests on
182thinly-provisioned volumes but have the base image on another device
183(possibly shared between many VMs).
184
185You must not write to the origin device if you use this technique!
186Of course, you may write to the thin device and take internal snapshots
187of the thin volume.
188
189i) Creating a snapshot of an external device
190
191 This is the same as creating a thin device.
192 You don't mention the origin at this stage.
193
194 dmsetup message /dev/mapper/pool 0 "create_thin 0"
195
196ii) Using a snapshot of an external device.
197
198 Append an extra parameter to the thin target specifying the origin:
199
200 dmsetup create snap --table "0 2097152 thin /dev/mapper/pool 0 /dev/image"
201
202 N.B. All descendants (internal snapshots) of this snapshot require the
203 same extra origin parameter.
204
Joe Thornber991d9fa2011-10-31 20:21:18 +0000205Deactivation
206------------
207
208All devices using a pool must be deactivated before the pool itself
209can be.
210
211 dmsetup remove thin
212 dmsetup remove snap
213 dmsetup remove pool
214
215Reference
216=========
217
218'thin-pool' target
219------------------
220
221i) Constructor
222
223 thin-pool <metadata dev> <data dev> <data block size (sectors)> \
224 <low water mark (blocks)> [<number of feature args> [<arg>]*]
225
226 Optional feature arguments:
Joe Thornber67e2e2b2012-03-28 18:41:29 +0100227
228 skip_block_zeroing: Skip the zeroing of newly-provisioned blocks.
229
230 ignore_discard: Disable discard support.
231
232 no_discard_passdown: Don't pass discards down to the underlying
233 data device, but just remove the mapping.
Joe Thornber991d9fa2011-10-31 20:21:18 +0000234
Joe Thornbere49e5822012-07-27 15:08:16 +0100235 read_only: Don't allow any changes to be made to the pool
236 metadata.
237
Mike Snitzer787a996c2013-12-06 16:21:43 -0500238 error_if_no_space: Error IOs, instead of queueing, if no space.
239
Joe Thornber991d9fa2011-10-31 20:21:18 +0000240 Data block size must be between 64KB (128 sectors) and 1GB
241 (2097152 sectors) inclusive.
242
243
244ii) Status
245
246 <transaction id> <used metadata blocks>/<total metadata blocks>
247 <used data blocks>/<total data blocks> <held metadata root>
Joe Thornbere49e5822012-07-27 15:08:16 +0100248 [no_]discard_passdown ro|rw
Joe Thornber991d9fa2011-10-31 20:21:18 +0000249
250 transaction id:
251 A 64-bit number used by userspace to help synchronise with metadata
252 from volume managers.
253
254 used data blocks / total data blocks
255 If the number of free blocks drops below the pool's low water mark a
256 dm event will be sent to userspace. This event is edge-triggered and
257 it will occur only once after each resume so volume manager writers
258 should register for the event and then check the target's status.
259
260 held metadata root:
261 The location, in sectors, of the metadata root that has been
262 'held' for userspace read access. '-' indicates there is no
263 held root. This feature is not yet implemented so '-' is
264 always returned.
265
Joe Thornbere49e5822012-07-27 15:08:16 +0100266 discard_passdown|no_discard_passdown
267 Whether or not discards are actually being passed down to the
268 underlying device. When this is enabled when loading the table,
269 it can get disabled if the underlying device doesn't support it.
270
271 ro|rw
272 If the pool encounters certain types of device failures it will
273 drop into a read-only metadata mode in which no changes to
274 the pool metadata (like allocating new blocks) are permitted.
275
276 In serious cases where even a read-only mode is deemed unsafe
277 no further I/O will be permitted and the status will just
278 contain the string 'Fail'. The userspace recovery tools
279 should then be used.
280
Mike Snitzer787a996c2013-12-06 16:21:43 -0500281 error_if_no_space|queue_if_no_space
282 If the pool runs out of data or metadata space, the pool will
283 either queue or error the IO destined to the data device. The
284 default is to queue the IO until more space is added.
285
Joe Thornber991d9fa2011-10-31 20:21:18 +0000286iii) Messages
287
288 create_thin <dev id>
289
290 Create a new thinly-provisioned device.
291 <dev id> is an arbitrary unique 24-bit identifier chosen by
292 the caller.
293
294 create_snap <dev id> <origin id>
295
296 Create a new snapshot of another thinly-provisioned device.
297 <dev id> is an arbitrary unique 24-bit identifier chosen by
298 the caller.
299 <origin id> is the identifier of the thinly-provisioned device
300 of which the new device will be a snapshot.
301
302 delete <dev id>
303
304 Deletes a thin device. Irreversible.
305
Joe Thornber991d9fa2011-10-31 20:21:18 +0000306 set_transaction_id <current id> <new id>
307
308 Userland volume managers, such as LVM, need a way to
309 synchronise their external metadata with the internal metadata of the
310 pool target. The thin-pool target offers to store an
311 arbitrary 64-bit transaction id and return it on the target's
312 status line. To avoid races you must provide what you think
313 the current transaction id is when you change it with this
314 compare-and-swap message.
315
Joe Thornbercc8394d2012-06-03 00:30:01 +0100316 reserve_metadata_snap
317
318 Reserve a copy of the data mapping btree for use by userland.
319 This allows userland to inspect the mappings as they were when
320 this message was executed. Use the pool's status command to
321 get the root block associated with the metadata snapshot.
322
323 release_metadata_snap
324
325 Release a previously reserved copy of the data mapping btree.
326
Joe Thornber991d9fa2011-10-31 20:21:18 +0000327'thin' target
328-------------
329
330i) Constructor
331
Joe Thornber2dd9c252012-03-28 18:41:28 +0100332 thin <pool dev> <dev id> [<external origin dev>]
Joe Thornber991d9fa2011-10-31 20:21:18 +0000333
334 pool dev:
335 the thin-pool device, e.g. /dev/mapper/my_pool or 253:0
336
337 dev id:
338 the internal device identifier of the device to be
339 activated.
340
Joe Thornber2dd9c252012-03-28 18:41:28 +0100341 external origin dev:
342 an optional block device outside the pool to be treated as a
343 read-only snapshot origin: reads to unprovisioned areas of the
344 thin target will be mapped to this device.
345
Joe Thornber991d9fa2011-10-31 20:21:18 +0000346The pool doesn't store any size against the thin devices. If you
347load a thin target that is smaller than you've been using previously,
348then you'll have no access to blocks mapped beyond the end. If you
349load a target that is bigger than before, then extra blocks will be
350provisioned as and when needed.
351
352If you wish to reduce the size of your thin device and potentially
353regain some space then send the 'trim' message to the pool.
354
355ii) Status
356
357 <nr mapped sectors> <highest mapped sector>
Joe Thornbere49e5822012-07-27 15:08:16 +0100358
359 If the pool has encountered device errors and failed, the status
360 will just contain the string 'Fail'. The userspace recovery
361 tools should then be used.