brintos

brintos / linux-shallow public Read only

0
0
Text · 8.3 KiB · 932383f Raw
195 lines · plain
1========2dm-zoned3========4 5The dm-zoned device mapper target exposes a zoned block device (ZBC and6ZAC compliant devices) as a regular block device without any write7pattern constraints. In effect, it implements a drive-managed zoned8block device which hides from the user (a file system or an application9doing raw block device accesses) the sequential write constraints of10host-managed zoned block devices and can mitigate the potential11device-side performance degradation due to excessive random writes on12host-aware zoned block devices.13 14For a more detailed description of the zoned block device models and15their constraints see (for SCSI devices):16 17https://www.t10.org/drafts.htm#ZBC_Family18 19and (for ATA devices):20 21http://www.t13.org/Documents/UploadedDocuments/docs2015/di537r05-Zoned_Device_ATA_Command_Set_ZAC.pdf22 23The dm-zoned implementation is simple and minimizes system overhead (CPU24and memory usage as well as storage capacity loss). For a 10TB25host-managed disk with 256 MB zones, dm-zoned memory usage per disk26instance is at most 4.5 MB and as little as 5 zones will be used27internally for storing metadata and performing reclaim operations.28 29dm-zoned target devices are formatted and checked using the dmzadm30utility available at:31 32https://github.com/hgst/dm-zoned-tools33 34Algorithm35=========36 37dm-zoned implements an on-disk buffering scheme to handle non-sequential38write accesses to the sequential zones of a zoned block device.39Conventional zones are used for caching as well as for storing internal40metadata. It can also use a regular block device together with the zoned41block device; in that case the regular block device will be split logically42in zones with the same size as the zoned block device. These zones will be43placed in front of the zones from the zoned block device and will be handled44just like conventional zones.45 46The zones of the device(s) are separated into 2 types:47 481) Metadata zones: these are conventional zones used to store metadata.49Metadata zones are not reported as usable capacity to the user.50 512) Data zones: all remaining zones, the vast majority of which will be52sequential zones used exclusively to store user data. The conventional53zones of the device may be used also for buffering user random writes.54Data in these zones may be directly mapped to the conventional zone, but55later moved to a sequential zone so that the conventional zone can be56reused for buffering incoming random writes.57 58dm-zoned exposes a logical device with a sector size of 4096 bytes,59irrespective of the physical sector size of the backend zoned block60device being used. This allows reducing the amount of metadata needed to61manage valid blocks (blocks written).62 63The on-disk metadata format is as follows:64 651) The first block of the first conventional zone found contains the66super block which describes the on disk amount and position of metadata67blocks.68 692) Following the super block, a set of blocks is used to describe the70mapping of the logical device blocks. The mapping is done per chunk of71blocks, with the chunk size equal to the zoned block device size. The72mapping table is indexed by chunk number and each mapping entry73indicates the zone number of the device storing the chunk of data. Each74mapping entry may also indicate if the zone number of a conventional75zone used to buffer random modification to the data zone.76 773) A set of blocks used to store bitmaps indicating the validity of78blocks in the data zones follows the mapping table. A valid block is79defined as a block that was written and not discarded. For a buffered80data chunk, a block is always valid only in the data zone mapping the81chunk or in the buffer zone of the chunk.82 83For a logical chunk mapped to a conventional zone, all write operations84are processed by directly writing to the zone. If the mapping zone is a85sequential zone, the write operation is processed directly only if the86write offset within the logical chunk is equal to the write pointer87offset within of the sequential data zone (i.e. the write operation is88aligned on the zone write pointer). Otherwise, write operations are89processed indirectly using a buffer zone. In that case, an unused90conventional zone is allocated and assigned to the chunk being91accessed. Writing a block to the buffer zone of a chunk will92automatically invalidate the same block in the sequential zone mapping93the chunk. If all blocks of the sequential zone become invalid, the zone94is freed and the chunk buffer zone becomes the primary zone mapping the95chunk, resulting in native random write performance similar to a regular96block device.97 98Read operations are processed according to the block validity99information provided by the bitmaps. Valid blocks are read either from100the sequential zone mapping a chunk, or if the chunk is buffered, from101the buffer zone assigned. If the accessed chunk has no mapping, or the102accessed blocks are invalid, the read buffer is zeroed and the read103operation terminated.104 105After some time, the limited number of conventional zones available may106be exhausted (all used to map chunks or buffer sequential zones) and107unaligned writes to unbuffered chunks become impossible. To avoid this108situation, a reclaim process regularly scans used conventional zones and109tries to reclaim the least recently used zones by copying the valid110blocks of the buffer zone to a free sequential zone. Once the copy111completes, the chunk mapping is updated to point to the sequential zone112and the buffer zone freed for reuse.113 114Metadata Protection115===================116 117To protect metadata against corruption in case of sudden power loss or118system crash, 2 sets of metadata zones are used. One set, the primary119set, is used as the main metadata region, while the secondary set is120used as a staging area. Modified metadata is first written to the121secondary set and validated by updating the super block in the secondary122set, a generation counter is used to indicate that this set contains the123newest metadata. Once this operation completes, in place of metadata124block updates can be done in the primary metadata set. This ensures that125one of the set is always consistent (all modifications committed or none126at all). Flush operations are used as a commit point. Upon reception of127a flush request, metadata modification activity is temporarily blocked128(for both incoming BIO processing and reclaim process) and all dirty129metadata blocks are staged and updated. Normal operation is then130resumed. Flushing metadata thus only temporarily delays write and131discard requests. Read requests can be processed concurrently while132metadata flush is being executed.133 134If a regular device is used in conjunction with the zoned block device,135a third set of metadata (without the zone bitmaps) is written to the136start of the zoned block device. This metadata has a generation counter of137'0' and will never be updated during normal operation; it just serves for138identification purposes. The first and second copy of the metadata139are located at the start of the regular block device.140 141Usage142=====143 144A zoned block device must first be formatted using the dmzadm tool. This145will analyze the device zone configuration, determine where to place the146metadata sets on the device and initialize the metadata sets.147 148Ex::149 150	dmzadm --format /dev/sdxx151 152 153If two drives are to be used, both devices must be specified, with the154regular block device as the first device.155 156Ex::157 158	dmzadm --format /dev/sdxx /dev/sdyy159 160 161Formatted device(s) can be started with the dmzadm utility, too.:162 163Ex::164 165	dmzadm --start /dev/sdxx /dev/sdyy166 167 168Information about the internal layout and current usage of the zones can169be obtained with the 'status' callback from dmsetup:170 171Ex::172 173	dmsetup status /dev/dm-X174 175will return a line176 177	0 <size> zoned <nr_zones> zones <nr_unmap_rnd>/<nr_rnd> random <nr_unmap_seq>/<nr_seq> sequential178 179where <nr_zones> is the total number of zones, <nr_unmap_rnd> is the number180of unmapped (ie free) random zones, <nr_rnd> the total number of zones,181<nr_unmap_seq> the number of unmapped sequential zones, and <nr_seq> the182total number of sequential zones.183 184Normally the reclaim process will be started once there are less than 50185percent free random zones. In order to start the reclaim process manually186even before reaching this threshold the 'dmsetup message' function can be187used:188 189Ex::190 191	dmsetup message /dev/dm-X 0 reclaim192 193will start the reclaim process and random zones will be moved to sequential194zones.195