thin-provisioning.txt 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. Introduction
  2. ============
  3. This document descibes a collection of device-mapper targets that
  4. between them implement thin-provisioning and snapshots.
  5. The main highlight of this implementation, compared to the previous
  6. implementation of snapshots, is that it allows many virtual devices to
  7. be stored on the same data volume. This simplifies administration and
  8. allows the sharing of data between volumes, thus reducing disk usage.
  9. Another significant feature is support for an arbitrary depth of
  10. recursive snapshots (snapshots of snapshots of snapshots ...). The
  11. previous implementation of snapshots did this by chaining together
  12. lookup tables, and so performance was O(depth). This new
  13. implementation uses a single data structure to avoid this degradation
  14. with depth. Fragmentation may still be an issue, however, in some
  15. scenarios.
  16. Metadata is stored on a separate device from data, giving the
  17. administrator some freedom, for example to:
  18. - Improve metadata resilience by storing metadata on a mirrored volume
  19. but data on a non-mirrored one.
  20. - Improve performance by storing the metadata on SSD.
  21. Status
  22. ======
  23. These targets are very much still in the EXPERIMENTAL state. Please
  24. do not yet rely on them in production. But do experiment and offer us
  25. feedback. Different use cases will have different performance
  26. characteristics, for example due to fragmentation of the data volume.
  27. If you find this software is not performing as expected please mail
  28. dm-devel@redhat.com with details and we'll try our best to improve
  29. things for you.
  30. Userspace tools for checking and repairing the metadata are under
  31. development.
  32. Cookbook
  33. ========
  34. This section describes some quick recipes for using thin provisioning.
  35. They use the dmsetup program to control the device-mapper driver
  36. directly. End users will be advised to use a higher-level volume
  37. manager such as LVM2 once support has been added.
  38. Pool device
  39. -----------
  40. The pool device ties together the metadata volume and the data volume.
  41. It maps I/O linearly to the data volume and updates the metadata via
  42. two mechanisms:
  43. - Function calls from the thin targets
  44. - Device-mapper 'messages' from userspace which control the creation of new
  45. virtual devices amongst other things.
  46. Setting up a fresh pool device
  47. ------------------------------
  48. Setting up a pool device requires a valid metadata device, and a
  49. data device. If you do not have an existing metadata device you can
  50. make one by zeroing the first 4k to indicate empty metadata.
  51. dd if=/dev/zero of=$metadata_dev bs=4096 count=1
  52. The amount of metadata you need will vary according to how many blocks
  53. are shared between thin devices (i.e. through snapshots). If you have
  54. less sharing than average you'll need a larger-than-average metadata device.
  55. As a guide, we suggest you calculate the number of bytes to use in the
  56. metadata device as 48 * $data_dev_size / $data_block_size but round it up
  57. to 2MB if the answer is smaller. The largest size supported is 16GB.
  58. If you're creating large numbers of snapshots which are recording large
  59. amounts of change, you may need find you need to increase this.
  60. Reloading a pool table
  61. ----------------------
  62. You may reload a pool's table, indeed this is how the pool is resized
  63. if it runs out of space. (N.B. While specifying a different metadata
  64. device when reloading is not forbidden at the moment, things will go
  65. wrong if it does not route I/O to exactly the same on-disk location as
  66. previously.)
  67. Using an existing pool device
  68. -----------------------------
  69. dmsetup create pool \
  70. --table "0 20971520 thin-pool $metadata_dev $data_dev \
  71. $data_block_size $low_water_mark"
  72. $data_block_size gives the smallest unit of disk space that can be
  73. allocated at a time expressed in units of 512-byte sectors. People
  74. primarily interested in thin provisioning may want to use a value such
  75. as 1024 (512KB). People doing lots of snapshotting may want a smaller value
  76. such as 128 (64KB). If you are not zeroing newly-allocated data,
  77. a larger $data_block_size in the region of 256000 (128MB) is suggested.
  78. $data_block_size must be the same for the lifetime of the
  79. metadata device.
  80. $low_water_mark is expressed in blocks of size $data_block_size. If
  81. free space on the data device drops below this level then a dm event
  82. will be triggered which a userspace daemon should catch allowing it to
  83. extend the pool device. Only one such event will be sent.
  84. Resuming a device with a new table itself triggers an event so the
  85. userspace daemon can use this to detect a situation where a new table
  86. already exceeds the threshold.
  87. Thin provisioning
  88. -----------------
  89. i) Creating a new thinly-provisioned volume.
  90. To create a new thinly- provisioned volume you must send a message to an
  91. active pool device, /dev/mapper/pool in this example.
  92. dmsetup message /dev/mapper/pool 0 "create_thin 0"
  93. Here '0' is an identifier for the volume, a 24-bit number. It's up
  94. to the caller to allocate and manage these identifiers. If the
  95. identifier is already in use, the message will fail with -EEXIST.
  96. ii) Using a thinly-provisioned volume.
  97. Thinly-provisioned volumes are activated using the 'thin' target:
  98. dmsetup create thin --table "0 2097152 thin /dev/mapper/pool 0"
  99. The last parameter is the identifier for the thinp device.
  100. Internal snapshots
  101. ------------------
  102. i) Creating an internal snapshot.
  103. Snapshots are created with another message to the pool.
  104. N.B. If the origin device that you wish to snapshot is active, you
  105. must suspend it before creating the snapshot to avoid corruption.
  106. This is NOT enforced at the moment, so please be careful!
  107. dmsetup suspend /dev/mapper/thin
  108. dmsetup message /dev/mapper/pool 0 "create_snap 1 0"
  109. dmsetup resume /dev/mapper/thin
  110. Here '1' is the identifier for the volume, a 24-bit number. '0' is the
  111. identifier for the origin device.
  112. ii) Using an internal snapshot.
  113. Once created, the user doesn't have to worry about any connection
  114. between the origin and the snapshot. Indeed the snapshot is no
  115. different from any other thinly-provisioned device and can be
  116. snapshotted itself via the same method. It's perfectly legal to
  117. have only one of them active, and there's no ordering requirement on
  118. activating or removing them both. (This differs from conventional
  119. device-mapper snapshots.)
  120. Activate it exactly the same way as any other thinly-provisioned volume:
  121. dmsetup create snap --table "0 2097152 thin /dev/mapper/pool 1"
  122. Deactivation
  123. ------------
  124. All devices using a pool must be deactivated before the pool itself
  125. can be.
  126. dmsetup remove thin
  127. dmsetup remove snap
  128. dmsetup remove pool
  129. Reference
  130. =========
  131. 'thin-pool' target
  132. ------------------
  133. i) Constructor
  134. thin-pool <metadata dev> <data dev> <data block size (sectors)> \
  135. <low water mark (blocks)> [<number of feature args> [<arg>]*]
  136. Optional feature arguments:
  137. - 'skip_block_zeroing': skips the zeroing of newly-provisioned blocks.
  138. Data block size must be between 64KB (128 sectors) and 1GB
  139. (2097152 sectors) inclusive.
  140. ii) Status
  141. <transaction id> <used metadata blocks>/<total metadata blocks>
  142. <used data blocks>/<total data blocks> <held metadata root>
  143. transaction id:
  144. A 64-bit number used by userspace to help synchronise with metadata
  145. from volume managers.
  146. used data blocks / total data blocks
  147. If the number of free blocks drops below the pool's low water mark a
  148. dm event will be sent to userspace. This event is edge-triggered and
  149. it will occur only once after each resume so volume manager writers
  150. should register for the event and then check the target's status.
  151. held metadata root:
  152. The location, in sectors, of the metadata root that has been
  153. 'held' for userspace read access. '-' indicates there is no
  154. held root. This feature is not yet implemented so '-' is
  155. always returned.
  156. iii) Messages
  157. create_thin <dev id>
  158. Create a new thinly-provisioned device.
  159. <dev id> is an arbitrary unique 24-bit identifier chosen by
  160. the caller.
  161. create_snap <dev id> <origin id>
  162. Create a new snapshot of another thinly-provisioned device.
  163. <dev id> is an arbitrary unique 24-bit identifier chosen by
  164. the caller.
  165. <origin id> is the identifier of the thinly-provisioned device
  166. of which the new device will be a snapshot.
  167. delete <dev id>
  168. Deletes a thin device. Irreversible.
  169. trim <dev id> <new size in sectors>
  170. Delete mappings from the end of a thin device. Irreversible.
  171. You might want to use this if you're reducing the size of
  172. your thinly-provisioned device. In many cases, due to the
  173. sharing of blocks between devices, it is not possible to
  174. determine in advance how much space 'trim' will release. (In
  175. future a userspace tool might be able to perform this
  176. calculation.)
  177. set_transaction_id <current id> <new id>
  178. Userland volume managers, such as LVM, need a way to
  179. synchronise their external metadata with the internal metadata of the
  180. pool target. The thin-pool target offers to store an
  181. arbitrary 64-bit transaction id and return it on the target's
  182. status line. To avoid races you must provide what you think
  183. the current transaction id is when you change it with this
  184. compare-and-swap message.
  185. 'thin' target
  186. -------------
  187. i) Constructor
  188. thin <pool dev> <dev id>
  189. pool dev:
  190. the thin-pool device, e.g. /dev/mapper/my_pool or 253:0
  191. dev id:
  192. the internal device identifier of the device to be
  193. activated.
  194. The pool doesn't store any size against the thin devices. If you
  195. load a thin target that is smaller than you've been using previously,
  196. then you'll have no access to blocks mapped beyond the end. If you
  197. load a target that is bigger than before, then extra blocks will be
  198. provisioned as and when needed.
  199. If you wish to reduce the size of your thin device and potentially
  200. regain some space then send the 'trim' message to the pool.
  201. ii) Status
  202. <nr mapped sectors> <highest mapped sector>