persistent-data.rst 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ===============
  2. Persistent data
  3. ===============
  4. Introduction
  5. ============
  6. The more-sophisticated device-mapper targets require complex metadata
  7. that is managed in kernel. In late 2010 we were seeing that various
  8. different targets were rolling their own data structures, for example:
  9. - Mikulas Patocka's multisnap implementation
  10. - Heinz Mauelshagen's thin provisioning target
  11. - Another btree-based caching target posted to dm-devel
  12. - Another multi-snapshot target based on a design of Daniel Phillips
  13. Maintaining these data structures takes a lot of work, so if possible
  14. we'd like to reduce the number.
  15. The persistent-data library is an attempt to provide a re-usable
  16. framework for people who want to store metadata in device-mapper
  17. targets. It's currently used by the thin-provisioning target and an
  18. upcoming hierarchical storage target.
  19. Overview
  20. ========
  21. The main documentation is in the header files which can all be found
  22. under drivers/md/persistent-data.
  23. The block manager
  24. -----------------
  25. dm-block-manager.[hc]
  26. This provides access to the data on disk in fixed sized-blocks. There
  27. is a read/write locking interface to prevent concurrent accesses, and
  28. keep data that is being used in the cache.
  29. Clients of persistent-data are unlikely to use this directly.
  30. The transaction manager
  31. -----------------------
  32. dm-transaction-manager.[hc]
  33. This restricts access to blocks and enforces copy-on-write semantics.
  34. The only way you can get hold of a writable block through the
  35. transaction manager is by shadowing an existing block (ie. doing
  36. copy-on-write) or allocating a fresh one. Shadowing is elided within
  37. the same transaction so performance is reasonable. The commit method
  38. ensures that all data is flushed before it writes the superblock.
  39. On power failure your metadata will be as it was when last committed.
  40. The Space Maps
  41. --------------
  42. dm-space-map.h
  43. dm-space-map-metadata.[hc]
  44. dm-space-map-disk.[hc]
  45. On-disk data structures that keep track of reference counts of blocks.
  46. Also acts as the allocator of new blocks. Currently two
  47. implementations: a simpler one for managing blocks on a different
  48. device (eg. thinly-provisioned data blocks); and one for managing
  49. the metadata space. The latter is complicated by the need to store
  50. its own data within the space it's managing.
  51. The data structures
  52. -------------------
  53. dm-btree.[hc]
  54. dm-btree-remove.c
  55. dm-btree-spine.c
  56. dm-btree-internal.h
  57. Currently there is only one data structure, a hierarchical btree.
  58. There are plans to add more. For example, something with an
  59. array-like interface would see a lot of use.
  60. The btree is 'hierarchical' in that you can define it to be composed
  61. of nested btrees, and take multiple keys. For example, the
  62. thin-provisioning target uses a btree with two levels of nesting.
  63. The first maps a device id to a mapping tree, and that in turn maps a
  64. virtual block to a physical block.
  65. Values stored in the btrees can have arbitrary size. Keys are always
  66. 64bits, although nesting allows you to use multiple keys.