zoned_loop.rst 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =======================
  3. Zoned Loop Block Device
  4. =======================
  5. .. Contents:
  6. 1) Overview
  7. 2) Creating a Zoned Device
  8. 3) Deleting a Zoned Device
  9. 4) Example
  10. 1) Overview
  11. -----------
  12. The zoned loop block device driver (zloop) allows a user to create a zoned block
  13. device using one regular file per zone as backing storage. This driver does not
  14. directly control any hardware and uses read, write and truncate operations to
  15. regular files of a file system to emulate a zoned block device.
  16. Using zloop, zoned block devices with a configurable capacity, zone size and
  17. number of conventional zones can be created. The storage for each zone of the
  18. device is implemented using a regular file with a maximum size equal to the zone
  19. size. The size of a file backing a conventional zone is always equal to the zone
  20. size. The size of a file backing a sequential zone indicates the amount of data
  21. sequentially written to the file, that is, the size of the file directly
  22. indicates the position of the write pointer of the zone.
  23. When resetting a sequential zone, its backing file size is truncated to zero.
  24. Conversely, for a zone finish operation, the backing file is truncated to the
  25. zone size. With this, the maximum capacity of a zloop zoned block device created
  26. can be larger configured to be larger than the storage space available on the
  27. backing file system. Of course, for such configuration, writing more data than
  28. the storage space available on the backing file system will result in write
  29. errors.
  30. The zoned loop block device driver implements a complete zone transition state
  31. machine. That is, zones can be empty, implicitly opened, explicitly opened,
  32. closed or full. The current implementation does not support any limits on the
  33. maximum number of open and active zones.
  34. No user tools are necessary to create and delete zloop devices.
  35. 2) Creating a Zoned Device
  36. --------------------------
  37. Once the zloop module is loaded (or if zloop is compiled in the kernel), the
  38. character device file /dev/zloop-control can be used to add a zloop device.
  39. This is done by writing an "add" command directly to the /dev/zloop-control
  40. device::
  41. $ modprobe zloop
  42. $ ls -l /dev/zloop*
  43. crw-------. 1 root root 10, 123 Jan 6 19:18 /dev/zloop-control
  44. $ mkdir -p <base directory/<device ID>
  45. $ echo "add [options]" > /dev/zloop-control
  46. The options available for the add command can be listed by reading the
  47. /dev/zloop-control device::
  48. $ cat /dev/zloop-control
  49. add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io
  50. remove id=%d
  51. In more details, the options that can be used with the "add" command are as
  52. follows.
  53. =================== =========================================================
  54. id Device number (the X in /dev/zloopX).
  55. Default: automatically assigned.
  56. capacity_mb Device total capacity in MiB. This is always rounded up
  57. to the nearest higher multiple of the zone size.
  58. Default: 16384 MiB (16 GiB).
  59. zone_size_mb Device zone size in MiB. Default: 256 MiB.
  60. zone_capacity_mb Device zone capacity (must always be equal to or lower
  61. than the zone size. Default: zone size.
  62. conv_zones Total number of conventioanl zones starting from
  63. sector 0
  64. Default: 8
  65. base_dir Path to the base directory where to create the directory
  66. containing the zone files of the device.
  67. Default=/var/local/zloop.
  68. The device directory containing the zone files is always
  69. named with the device ID. E.g. the default zone file
  70. directory for /dev/zloop0 is /var/local/zloop/0.
  71. nr_queues Number of I/O queues of the zoned block device. This
  72. value is always capped by the number of online CPUs
  73. Default: 1
  74. queue_depth Maximum I/O queue depth per I/O queue.
  75. Default: 64
  76. buffered_io Do buffered IOs instead of direct IOs (default: false)
  77. zone_append Enable or disable a zloop device native zone append
  78. support.
  79. Default: 1 (enabled).
  80. If native zone append support is disabled, the block layer
  81. will emulate this operation using regular write
  82. operations.
  83. ordered_zone_append Enable zloop mitigation of zone append reordering.
  84. Default: disabled.
  85. This is useful for testing file systems file data mapping
  86. (extents), as when enabled, this can significantly reduce
  87. the number of data extents needed to for a file data
  88. mapping.
  89. =================== =========================================================
  90. 3) Deleting a Zoned Device
  91. --------------------------
  92. Deleting an unused zoned loop block device is done by issuing the "remove"
  93. command to /dev/zloop-control, specifying the ID of the device to remove::
  94. $ echo "remove id=X" > /dev/zloop-control
  95. The remove command does not have any option.
  96. A zoned device that was removed can be re-added again without any change to the
  97. state of the device zones: the device zones are restored to their last state
  98. before the device was removed. Adding again a zoned device after it was removed
  99. must always be done using the same configuration as when the device was first
  100. added. If a zone configuration change is detected, an error will be returned and
  101. the zoned device will not be created.
  102. To fully delete a zoned device, after executing the remove operation, the device
  103. base directory containing the backing files of the device zones must be deleted.
  104. 4) Example
  105. ----------
  106. The following sequence of commands creates a 2GB zoned device with zones of 64
  107. MB and a zone capacity of 63 MB::
  108. $ modprobe zloop
  109. $ mkdir -p /var/local/zloop/0
  110. $ echo "add capacity_mb=2048,zone_size_mb=64,zone_capacity_mb=63" > /dev/zloop-control
  111. For the device created (/dev/zloop0), the zone backing files are all created
  112. under the default base directory (/var/local/zloop)::
  113. $ ls -l /var/local/zloop/0
  114. total 0
  115. -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000000
  116. -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000001
  117. -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000002
  118. -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000003
  119. -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000004
  120. -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000005
  121. -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000006
  122. -rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000007
  123. -rw-------. 1 root root 0 Jan 6 22:23 seq-000008
  124. -rw-------. 1 root root 0 Jan 6 22:23 seq-000009
  125. ...
  126. The zoned device created (/dev/zloop0) can then be used normally::
  127. $ lsblk -z
  128. NAME ZONED ZONE-SZ ZONE-NR ZONE-AMAX ZONE-OMAX ZONE-APP ZONE-WGRAN
  129. zloop0 host-managed 64M 32 0 0 1M 4K
  130. $ blkzone report /dev/zloop0
  131. start: 0x000000000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
  132. start: 0x000020000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
  133. start: 0x000040000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
  134. start: 0x000060000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
  135. start: 0x000080000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
  136. start: 0x0000a0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
  137. start: 0x0000c0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
  138. start: 0x0000e0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
  139. start: 0x000100000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
  140. start: 0x000120000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
  141. ...
  142. Deleting this device is done using the command::
  143. $ echo "remove id=0" > /dev/zloop-control
  144. The removed device can be re-added again using the same "add" command as when
  145. the device was first created. To fully delete a zoned device, its backing files
  146. should also be deleted after executing the remove command::
  147. $ rm -r /var/local/zloop/0