dm: zoned block device support
Subsystems (3)
v3 cover dm: zoned block device support
From: Damien Le Moal <[email protected]>
[ Note: I'm resending this patch series on Damien's behalf because Damien's ]
[ e-mails apparently do not reach the dm-devel mailing list - Bart. ]
This series introduces zoned block device support to the device mapper infrastructure. Pathces are as follows:
- Patch 1: Add a new target type feature flag to indicate if a target type supports host-managed zoned block devices. This prevents using these drives with the current target types since none of them have the proper support implemented and will not operate properly with these drives.
- Patch 2: If a target device is a zoned block device, check that the range of LBAs mapped is aligned to the device zone size and that the device start offset also aligns to zone boundaries. This is necessary for zone reset and zone report correct execution.
- Patch 3: Check that the different target devices of a table have compatible zone sizes and models. This is necessary for target types that expose a zone model different from the underlying device.
- Patch 4: Fix handling of REQ_OP_ZONE_RESET bios
- Patch 5: Fix handling of REQ_OP_ZONE_REPORT bios
- Patch 6: Introduce a new helper function to reverse map a device zone report to the target LBA range
- Patch 7: Add support for host-managed zoned block devices to dm-flakey. This is necessary for testing file systems supporting natively these drives (e.g. f2fs).
- Patch 8: Add support for for zoned block devices to dm-linear. This can have useful applications during development and testing (e.g. allow creating smaller zoned devices with different combinations and positions of zones). There are also interesting applications for production, for instance, the ability to aggregate conventional zones of different drives to create a regular disk.
- Patch 9: Add sequential write enforcement to dm_kcopyd_copy so that sequential zones of a host-managed zoned block device can be specified as destinations.
- Patch 10: New dm-zoned target type (this was already sent for review twice). This resend adds modifications suggested by Hannes to implement reclaim using dm-kcopyd. dm-zoned depends on patch 9.
As always, comments and reviews are welcome.
Changes from v2:
- Rebased on 4.12-rc tree
- Added Bart Reviewed-by tag
Changes from v1:
- Use for-loop in patch 3 as suggested by Bart
- Add memory shrinker to dm-zoned to shrink the metadata block cache under memory pressure (suggested by Bart)
- Added Hannes Reviewed-by tag
Damien Le Moal (10):
dm-table: Introduce DM_TARGET_ZONED_HM feature
dm-table: Check device area zone alignment
dm-table: Check block devices zone model compatibility
dm: Fix REQ_OP_ZONE_RESET bio handling
dm: Fix REQ_OP_ZONE_REPORT bio handling
dm: Introduce dm_remap_zone_report()
dm-flakey: Add support for zoned block devices
dm-linear: Add support for zoned block devices
dm-kcopyd: Add sequential write feature
dm-zoned: Drive-managed zoned block device target
Documentation/device-mapper/dm-zoned.txt | 154 +++ drivers/md/Kconfig | 17 + drivers/md/Makefile | 2 + drivers/md/dm-flakey.c | 21 +- drivers/md/dm-kcopyd.c | 68 +- drivers/md/dm-linear.c | 15 +- drivers/md/dm-table.c | 143 ++ drivers/md/dm-zoned-io.c | 999 ++++++++++++++ drivers/md/dm-zoned-metadata.c | 2225 ++++++++++++++++++++++++++++++ drivers/md/dm-zoned-reclaim.c | 535 +++++++ drivers/md/dm-zoned.h | 530 +++++++ drivers/md/dm.c | 93 +- include/linux/device-mapper.h | 16 + include/linux/dm-kcopyd.h | 1 + 14 files changed, 4812 insertions(+), 7 deletions(-) create mode 100644 Documentation/device-mapper/dm-zoned.txt create mode 100644 drivers/md/dm-zoned-io.c create mode 100644 drivers/md/dm-zoned-metadata.c create mode 100644 drivers/md/dm-zoned-reclaim.c create mode 100644 drivers/md/dm-zoned.h
Signature · 1 line
2.9.3
PATCH v3 1/10 dm-table: Introduce DM_TARGET_ZONED_HM feature
From: Damien Le Moal <[email protected]>
The target drivers currently available will not operate correctly if a table target maps onto a host-managed zoned block device.
To avoid problems, this patch introduces the new feature flag DM_TARGET_ZONED_HM for a target driver to explicitly state that it supports host-managed zoned block devices. This feature is checked in dm_get_device() to prevent the addition to a table of a target mapping to a host-managed zoned block device if the target type does not have the feature enabled.
Note that as host-aware zoned block devices are backward compatible with regular block devices, they can be used by any of the current target types. This new feature is thus restricted to host-managed zoned block devices.
--- drivers/md/dm-table.c | 23 +++++++++++++++++++++++ include/linux/device-mapper.h | 6 ++++++ 2 files changed, 29 insertions(+)
drivers/md/dm-table.c +23 -0
@@ -389,6 +389,24 @@ dev_t dm_get_dev_t(const char *path)EXPORT_SYMBOL_GPL (dm_get_dev_t);/* +* Check if the target supports supports host-managed zoned block devices. +*/ +static bool device_supported (struct dm_target *ti,struct dm_dev *dev) +{ +struct block_device *bdev = dev->bdev; +char b[BDEVNAME_SIZE ]; + +if (bdev_zoned_model (bdev) ==BLK_ZONED_HM && + !dm_target_zoned_hm (ti->type)) { +DMWARN ("%s: Unsupported host-managed zoned block device %s" , +dm_device_name (ti->table->md),bdevname (bdev, b)); +return false; + } + +return true; +} + +/* * Add a device to the list, or just increment the usage count if * it's already present. */
@@ -427,6 +445,11 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode, }atomic_inc (&dd->count); +if (!device_supported (ti, dd->dm_dev)) { +dm_put_device (ti, dd->dm_dev); +return -ENOTSUPP ; + } + *result = dd->dm_dev;return 0 ; }
include/linux/device-mapper.h +6 -0
@@ -218,6 +218,12 @@ struct target_type {#define dm_target_is_wildcard (type) ((type)->features & DM_TARGET_WILDCARD)/* +* Indicates that a target supports host-managed zoned block devices. +*/ +#define DM_TARGET_ZONED_HM 0x00000010 +#define dm_target_zoned_hm (type) ((type)->features & DM_TARGET_ZONED_HM) + +/* * Some targets need to be sent the same WRITE bio severals times so * that they can send copies of it to different devices. This function * examines any supplied bio and returns the number of copies of it the
Signature · 1 line
2.9.3
PATCH v3 2/10 dm-table: Check device area zone alignment
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
If a target maps to a zoned block device, check that the device area is aligned on zone boundaries to avoid problems with REQ_OP_ZONE_RESET operations (resetting a partially mapped sequential zone would not be possible). This also greatly facilitate the processing of zone report with REQ_OP_ZONE_REPORT bios.
--- drivers/md/dm-table.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/md/dm-table.c +27 -0
@@ -340,6 +340,33 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,return 1 ; } +/* +* If the target is mapped to a zoned block device, check +* that the device zones are not partially mapped. +*/ +if (bdev_zoned_model (bdev) !=BLK_ZONED_NONE ) { +unsigned int zone_sectors =bdev_zone_sectors (bdev); + +if (start & (zone_sectors -1 )) { +DMWARN ("%s: start=%llu not aligned to h/w " +"zone size %u of %s" , +dm_device_name (ti->table->md), + (unsigned long long )start, + zone_sectors,bdevname (bdev, b)); +return 1 ; + } + +if (start + len < dev_size && + len & (zone_sectors -1 )) { +DMWARN ("%s: len=%llu not aligned to h/w " +"zone size %u of %s" , +dm_device_name (ti->table->md), + (unsigned long long )start, + zone_sectors,bdevname (bdev, b)); +return 1 ; + } + } +return 0 ; }
Signature · 1 line
2.9.3
PATCH v3 3/10 dm-table: Check block devices zone model compatibility
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
When setting the dm device queue limits, several possibilities exists for zoned block devices:
1) The dm target driver may want to expose a different zone model (e.g. host-managed device emulation or regular block device on top of host-managed zoned block devices)
2) Expose the underlying zone model of the devices as is
To allow both cases, the underlying block device zone model must be set in the target limits in dm_set_device_limits() and the compatibility of all devices checked similarly to the logical block size alignment. For this last check, introduce the function validate_hardware_zone_model() to check that all targets of a table have the same zone model and that the zone size of the target devices are equal.
--- drivers/md/dm-table.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+)
drivers/md/dm-table.c +93 -0
@@ -506,6 +506,8 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev, q->limits.alignment_offset, (unsigned long long) start << SECTOR_SHIFT); + limits->zoned =bdev_zoned_model (bdev); +return 0 ; }
@@ -721,6 +723,94 @@ static int validate_hardware_logical_block_alignment(struct dm_table *table,return 0 ; } +/* +* Check a devices's table for compatibility between zoned devices used by +* the table targets. The zone model may come directly from a target block +* device or may have been set by the target using the io_hints method. +* Overall, if any of the table device targets is advertized as a zoned +* block device, then all targets devices should also be advertized as +* using the same model and the devices zone size all equal. +*/ +static int validate_hardware_zone_model (struct dm_table *table, +struct queue_limits *limits) +{ +struct dm_target *ti; +struct queue_limits ti_limits; +unsigned int zone_sectors = limits->chunk_sectors; +unsigned int num_targets =dm_table_get_num_targets (table); +int zone_model =-1 ; +unsigned int i; + +if (!num_targets) +return 0 ; + +/* +* Check each entry in the table in turn. +*/ +for (i =0 ; i < num_targets; i++) { + + ti =dm_table_get_target (table, i); + +/* Get the target device limits */ +blk_set_stacking_limits (&ti_limits); +if (ti->type->iterate_devices) + ti->type->iterate_devices (ti, dm_set_device_limits, + &ti_limits); + +/* +* Let the target driver change the hardware limits, and +* in particular the zone model if needed. +*/ +if (ti->type->io_hints) + ti->type->io_hints (ti, &ti_limits); + +/* Check zone model compatibility */ +if (zone_model ==-1 ) + zone_model = ti_limits.zoned; +if (ti_limits.zoned != zone_model) { + zone_model =-1 ; +break ; + } + +if (zone_model !=BLK_ZONED_NONE ) { +/* Check zone size validity and compatibility */ +if (!zone_sectors || + !is_power_of_2 (zone_sectors)) +break ; +if (ti_limits.chunk_sectors != zone_sectors) { + zone_sectors = ti_limits.chunk_sectors; +break ; + } + } + + } + +if (i < num_targets) { +if (zone_model ==-1 ) +DMWARN ("%s: table line %u (start sect %llu len %llu) " +"has an incompatible zone model" , +dm_device_name (table->md), i, + (unsigned long long ) ti->begin, + (unsigned long long ) ti->len); +else +DMWARN ("%s: table line %u (start sect %llu len %llu) " +"has an incompatible zone size %u" , +dm_device_name (table->md), i, + (unsigned long long ) ti->begin, + (unsigned long long ) ti->len, + zone_sectors); +return -EINVAL ; + } + +if (zone_model ==BLK_ZONED_HA || + zone_model ==BLK_ZONED_HM ) { + limits->zoned = zone_model; + limits->chunk_sectors = zone_sectors; + } + +return 0 ; +} +int dm_table_add_target (struct dm_table *t,const char *type,sector_t start,sector_t len,char *params) {
@@ -1448,6 +1538,9 @@ int dm_calculate_queue_limits(struct dm_table *table, (unsigned long long) ti->len); } +if (validate_hardware_zone_model (table, limits)) +return -EINVAL ; +return validate_hardware_logical_block_alignment (table, limits); }
Signature · 1 line
2.9.3
PATCH v3 4/10 dm: Fix REQ_OP_ZONE_RESET bio handling
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
The REQ_OP_ZONE_RESET bio has no payload and zero sectors. Its position is the only information used to indicate the zone to reset on the device. Due to its zero length, this bio is not cloned and sent to the target through the non-flush case in __split_and_process_bio(). Add an additional case in that function to call __split_and_process_non_flush() without checking the clone info size.
--- drivers/md/dm.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/md/dm.c +4 -0
@@ -1374,6 +1374,10 @@ static void __split_and_process_bio(struct mapped_device *md, ci.sector_count =0 ; error =__send_empty_flush (&ci);/* dec_pending submits any data associated with flush */ + }else if (bio_op (bio) ==REQ_OP_ZONE_RESET ) { + ci.bio = bio; + ci.sector_count =0 ; + error =__split_and_process_non_flush (&ci); }else { ci.bio = bio; ci.sector_count =bio_sectors (bio);
Signature · 1 line
2.9.3
PATCH v3 5/10 dm: Fix REQ_OP_ZONE_REPORT bio handling
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
A REQ_OP_ZONE_REPORT bio is not a medium access command. Its number of sectors indicates the maximum size allowed for the report reply size and not an amount of sectors accessed from the device. REQ_OP_ZONE_REPORT bios should thus not be split depending on the target device maximum I/O length but passed as is. Note that it is the responsability of the target to remap and format the report reply.
--- drivers/md/dm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/md/dm.c +7 -2
@@ -1142,7 +1142,8 @@ static int clone_bio(struct dm_target_io *tio, struct bio *bio,return r; } -bio_advance (clone,to_bytes (sector - clone->bi_iter.bi_sector)); +if (bio_op (bio) !=REQ_OP_ZONE_REPORT ) +bio_advance (clone,to_bytes (sector - clone->bi_iter.bi_sector)); clone->bi_iter.bi_size =to_bytes (len);if (unlikely (bio_integrity (bio) !=NULL ))
@@ -1331,7 +1332,11 @@ static int __split_and_process_non_flush(struct clone_info *ci)if (!dm_target_is_valid (ti))return -EIO ; - len =min_t (sector_t,max_io_len (ci->sector, ti), ci->sector_count); +if (bio_op (bio) ==REQ_OP_ZONE_REPORT ) + len = ci->sector_count; +else + len =min_t (sector_t,max_io_len (ci->sector, ti), + ci->sector_count); r =__clone_and_map_data_bio (ci, ti, ci->sector, &len);if (r <0 )
Signature · 1 line
2.9.3
PATCH v3 6/10 dm: Introduce dm_remap_zone_report()
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
A target driver support zoned block devices and exposing it as such may receive REQ_OP_ZONE_REPORT request for the user to determine the mapped device zone configuration. To process properly such request, the target driver may need to remap the zone descriptors provided in the report reply. The helper function dm_remap_zone_report() does this generically using only the target start offset and length and the start offset within the target device.
dm_remap_zone_report() will remap the start sector of all zones reported. If the report includes sequential zones, the write pointer position of these zones will also be remapped.
--- drivers/md/dm.c | 80 +++++++++++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 10 ++++++ 2 files changed, 90 insertions(+)
drivers/md/dm.c +80 -0
@@ -1009,6 +1009,86 @@ void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors) }EXPORT_SYMBOL_GPL (dm_accept_partial_bio); +#ifdef CONFIG_BLK_DEV_ZONED +/* +* The zone descriptors obtained with a zone report indicate +* zone positions within the target device. The zone descriptors +* must be remapped to match their position within the dm device. +* A target may call dm_remap_zone_report after completion of a +* REQ_OP_ZONE_REPORT bio to remap the zone descriptors obtained +* from the target device mapping to the dm device. +*/ +void dm_remap_zone_report (struct dm_target *ti,struct bio *bio,sector_t start) +{ +struct dm_target_io *tio = + container_of(bio, struct dm_target_io, clone); +struct bio *report_bio = tio->io->bio; +struct blk_zone_report_hdr *hdr =NULL ; +struct blk_zone *zone; +unsigned int nr_rep =0 ; +unsigned int ofst; +struct bio_vec bvec; +struct bvec_iter iter; +void *addr; + +if (bio->bi_error) +return ; + +/* +* Remap the start sector of the reported zones. For sequential zones, +* also remap the write pointer position. +*/ +bio_for_each_segment (bvec, report_bio, iter) { + + addr =kmap_atomic (bvec.bv_page); + +/* Remember the report header in the first page */ +if (!hdr) { + hdr = addr; + ofst =sizeof (struct blk_zone_report_hdr ); + }else { + ofst =0 ; + } + +/* Set zones start sector */ +while (hdr->nr_zones && ofst < bvec.bv_len) { + zone = addr + ofst; +if (zone->start >= start + ti->len) { + hdr->nr_zones =0 ; +break ; + } + zone->start = zone->start + ti->begin - start; +if (zone->type !=BLK_ZONE_TYPE_CONVENTIONAL ) { +if (zone->cond ==BLK_ZONE_COND_FULL ) + zone->wp = zone->start + zone->len; +else if (zone->cond ==BLK_ZONE_COND_EMPTY ) + zone->wp = zone->start; +else + zone->wp = zone->wp + ti->begin - start; + } + ofst +=sizeof (struct blk_zone ); + hdr->nr_zones--; + nr_rep++; + } + +if (addr != hdr) +kunmap_atomic (addr); + +if (!hdr->nr_zones) +break ; + + } + +if (hdr) { + hdr->nr_zones = nr_rep; +kunmap_atomic (hdr); + } + +bio_advance (report_bio, report_bio->bi_iter.bi_size); +} +EXPORT_SYMBOL_GPL (dm_remap_zone_report); +#endif +/* * Flush current->bio_list when the target map method blocks. * This fixes deadlocks in snapshot and possibly in other targets.
include/linux/device-mapper.h +10 -0
@@ -450,6 +450,16 @@ struct gendisk *dm_disk(struct mapped_device *md);int dm_suspended (struct dm_target *ti);int dm_noflush_suspending (struct dm_target *ti);void dm_accept_partial_bio (struct bio *bio,unsigned n_sectors); +#ifdef CONFIG_BLK_DEV_ZONED +void dm_remap_zone_report (struct dm_target *ti,struct bio *bio, +sector_t start); +#else +static inline void dm_remap_zone_report (struct dm_target *ti,struct bio *bio, +sector_t start) +{ + bio->bi_error = -ENOTSUPP ; +} +#endif union map_info *dm_get_rq_mapinfo (struct request *rq);struct queue_limits *dm_get_queue_limits (struct mapped_device *md);
Signature · 1 line
2.9.3
PATCH v3 7/10 dm-flakey: Add support for zoned block devices
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
With the development of file system support for zoned block devices (e.g. f2fs), having dm-flakey support for these devices is interesting to improve testing.
This patch adds support for zoned block devices in dm-flakey, both host-aware and host-managed. The target type feature is set to DM_TARGET_ZONED_HM indicate support for host-managed models. The remaining of the support adds hooks for remapping of REQ_OP_ZONE_RESET and REQ_OP_ZONE_REPORT bios. Additionally, in the bio completion path, (backward) remapping of a zone report reply is also added.
--- drivers/md/dm-flakey.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/md/dm-flakey.c +20 -1
@@ -251,6 +251,8 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)return 0 ; bad: +if (fc->dev) +dm_put_device (ti, fc->dev);kfree (fc);return r; }
@@ -275,7 +277,7 @@ static void flakey_map_bio(struct dm_target *ti, struct bio *bio)struct flakey_c *fc = ti->private; bio->bi_bdev = fc->dev->bdev; -if (bio_sectors (bio)) +if (bio_sectors (bio) ||bio_op (bio) ==REQ_OP_ZONE_RESET ) bio->bi_iter.bi_sector =flakey_map_sector (ti, bio->bi_iter.bi_sector); }
@@ -306,6 +308,14 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)struct per_bio_data *pb =dm_per_bio_data (bio,sizeof (struct per_bio_data )); pb->bio_submitted = false; +/* Do not fail reset zone */ +if (bio_op (bio) ==REQ_OP_ZONE_RESET ) + goto map_bio; + +/* We need to remap reported zones, so remember the BIO iter */ +if (bio_op (bio) ==REQ_OP_ZONE_REPORT ) + goto map_bio; +/* Are we alive ? */ elapsed = (jiffies - fc->start_time) /HZ ;if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) {
@@ -363,6 +373,14 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio, int error)struct flakey_c *fc = ti->private;struct per_bio_data *pb =dm_per_bio_data (bio,sizeof (struct per_bio_data )); +if (bio_op (bio) ==REQ_OP_ZONE_RESET ) +return error; + +if (bio_op (bio) ==REQ_OP_ZONE_REPORT ) { +dm_remap_zone_report (ti, bio, fc->start); +return error; + } +if (!error && pb->bio_submitted && (bio_data_dir (bio) ==READ )) {if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw ==READ ) &&all_corrupt_bio_flags_match (bio, fc)) {
@@ -446,6 +464,7 @@ static int flakey_iterate_devices(struct dm_target *ti, iterate_devices_callout_static struct target_type flakey_target = { .name ="flakey" , .version = {1 ,4 ,0 }, + .features =DM_TARGET_ZONED_HM , .module =THIS_MODULE , .ctr = flakey_ctr, .dtr = flakey_dtr,
Signature · 1 line
2.9.3
PATCH v3 8/10 dm-linear: Add support for zoned block devices
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
Add support for zoned block devices by allowing host-managed zoned block device mapped targets, the remapping of REQ_OP_ZONE_RESET and the post processing (reply remapping) of REQ_OP_ZONE_REPORT.
--- drivers/md/dm-linear.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/md/dm-linear.c +13 -2
@@ -89,7 +89,7 @@ static void linear_map_bio(struct dm_target *ti, struct bio *bio)struct linear_c *lc = ti->private; bio->bi_bdev = lc->dev->bdev; -if (bio_sectors (bio)) +if (bio_sectors (bio) ||bio_op (bio) ==REQ_OP_ZONE_RESET ) bio->bi_iter.bi_sector =linear_map_sector (ti, bio->bi_iter.bi_sector); }
@@ -101,6 +101,16 @@ static int linear_map(struct dm_target *ti, struct bio *bio)return DM_MAPIO_REMAPPED ; } +static int linear_end_io (struct dm_target *ti,struct bio *bio,int error) +{ +struct linear_c *lc = ti->private; + +if (!error &&bio_op (bio) ==REQ_OP_ZONE_REPORT ) +dm_remap_zone_report (ti, bio, lc->start); + +return error; +} +static void linear_status (struct dm_target *ti,status_type_t type,unsigned status_flags,char *result,unsigned maxlen) {
@@ -162,11 +172,12 @@ static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,static struct target_type linear_target = { .name ="linear" , .version = {1 ,3 ,0 }, - .features =DM_TARGET_PASSES_INTEGRITY , + .features =DM_TARGET_PASSES_INTEGRITY |DM_TARGET_ZONED_HM , .module =THIS_MODULE , .ctr = linear_ctr, .dtr = linear_dtr, .map = linear_map, + .end_io = linear_end_io, .status = linear_status, .prepare_ioctl = linear_prepare_ioctl, .iterate_devices = linear_iterate_devices,
Signature · 1 line
2.9.3
PATCH v3 9/10 dm-kcopyd: Add sequential write feature
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
When copyying blocks to host-managed zoned block devices, writes must be sequential. dm_kcopyd_copy() does not howerver guarantee this as writes are issued in the completion order of reads, and reads may complete out of order despite being issued sequentially.
Fix this by introducing the DM_KCOPYD_WRITE_SEQ flag. This can be specified by the user when calling dm_kcopyd_copy() and is set automatically if one of the destinations is a host-managed zoned block device. For a split job, the master job maintains the write position at which writes must be issued. This is checked with the pop() function which is modify to not return any write I/O sub job that is not at the correct write position.
When DM_KCOPYD_WRITE_SEQ is specified for a job, errors cannot be ignored and the flag DM_KCOPYD_IGNORE_ERROR is ignored, even if specified by the user.
--- drivers/md/dm-kcopyd.c | 68 +++++++++++++++++++++++++++++++++++++++++++++-- include/linux/dm-kcopyd.h | 1 + 2 files changed, 67 insertions(+), 2 deletions(-)
drivers/md/dm-kcopyd.c +66 -2
@@ -356,6 +356,7 @@ struct kcopyd_job {struct mutex lock;atomic_t sub_jobs;sector_t progress; +sector_t write_ofst;struct kcopyd_job *master_job; };
@@ -386,6 +387,34 @@ void dm_kcopyd_exit(void)* Functions to push and pop a job onto the head of a given job * list. */ +static struct kcopyd_job *pop_io_job (struct list_head *jobs, +struct dm_kcopyd_client *kc) +{ +struct kcopyd_job *job; + +/* +* For I/O jobs, pop any read, any write without sequential write +* constraint and sequential writes that are at the right position. +*/ +list_for_each_entry (job, jobs, list) { + +if (job->rw ==READ || + !test_bit (DM_KCOPYD_WRITE_SEQ , &job->flags)) { +list_del (&job->list); +return job; + } + +if (job->write_ofst == job->master_job->write_ofst) { + job->master_job->write_ofst += job->source.count; +list_del (&job->list); +return job; + } + + } + +return NULL ; +} +static struct kcopyd_job *pop (struct list_head *jobs,struct dm_kcopyd_client *kc) {
@@ -395,8 +424,12 @@ static struct kcopyd_job *pop(struct list_head *jobs,spin_lock_irqsave (&kc->job_lock, flags);if (!list_empty (jobs)) { - job = list_entry(jobs->next, struct kcopyd_job, list); -list_del (&job->list); +if (jobs == &kc->io_jobs) { + job =pop_io_job (jobs, kc); + }else { + job = list_entry(jobs->next, struct kcopyd_job, list); +list_del (&job->list); + } }spin_unlock_irqrestore (&kc->job_lock, flags);
@@ -506,6 +539,14 @@ static int run_io_job(struct kcopyd_job *job) .client = job->kc->io_client, }; +/* +* If we need to write sequentially and some reads or writes failed, +* no point in continuing. +*/ +if (test_bit (DM_KCOPYD_WRITE_SEQ , &job->flags) && + job->master_job->write_err) +return -EIO ; +io_job_start (job->kc->throttle);if (job->rw ==READ )
@@ -655,6 +696,7 @@ static void segment_complete(int read_err, unsigned long write_err,int i; *sub_job = *job; + sub_job->write_ofst = progress; sub_job->source.sector += progress; sub_job->source.count = count;
@@ -723,6 +765,27 @@ int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from, job->num_dests = num_dests;memcpy (&job->dests, dests,sizeof (*dests) * num_dests); +/* +* If one of the destination is a host-managed zoned block device, +* we need to write sequentially. If one of the destination is a +* host-aware device, then leave it to the caller to choose what to do. +*/ +if (!test_bit (DM_KCOPYD_WRITE_SEQ , &job->flags)) { +for (i =0 ; i < job->num_dests; i++) { +if (bdev_zoned_model (dests[i].bdev) ==BLK_ZONED_HM ) { +set_bit (DM_KCOPYD_WRITE_SEQ , &job->flags); +break ; + } + } + } + +/* +* If we need to write sequentially, errors cannot be ignored. +*/ +if (test_bit (DM_KCOPYD_WRITE_SEQ , &job->flags) && +test_bit (DM_KCOPYD_IGNORE_ERROR , &job->flags)) +clear_bit (DM_KCOPYD_IGNORE_ERROR , &job->flags); +if (from) { job->source = *from; job->pages =NULL ;
@@ -746,6 +809,7 @@ int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from, job->fn = fn; job->context = context; job->master_job = job; + job->write_ofst =0 ;if (job->source.count <=SUB_JOB_SIZE )dispatch_job (job);
include/linux/dm-kcopyd.h +1 -0
@@ -20,6 +20,7 @@#define DM_KCOPYD_MAX_REGIONS 8#define DM_KCOPYD_IGNORE_ERROR 1 +#define DM_KCOPYD_WRITE_SEQ 2struct dm_kcopyd_throttle {unsigned throttle;
Signature · 1 line
2.9.3
PATCH v3 10/10 dm-zoned: Drive-managed zoned block device target
In reply to Bart Van AsscheFrom: Damien Le Moal <[email protected]>
The dm-zoned device mapper target provides transparent write access to zoned block devices (ZBC and ZAC compliant block devices). dm-zoned hides to the device user (a file system or an application doing raw block device accesses) any constraint imposed on write requests by the device, equivalent to a drive-managed zoned block device model.
Write requests are processed using a combination of on-disk buffering using the device conventional zones and direct in-place processing for requests aligned to a zone sequential write pointer position. A background reclaim process implemented using dm_kcopyd_copy ensures that conventional zones are always available for executing unaligned write requests. The reclaim process overhead is minimized by managing buffer zones in a least-recently-written order and first targeting the oldest buffer zones. Doing so, blocks under regular write access (such as metadata blocks of a file system) remain stored in conventional zones, resulting in no apparent overhead.
dm-zoned implementation focus on simplicity and on minimizing overhead (CPU, memory and storage overhead). For a 10TB host-managed disk with 256 MB zones, dm-zoned memory usage per disk instance is at most 4.5 MB and as little as 5 zones will be used internally for storing metadata and performing buffer zone reclaim operations. This is achieved using zone level indirection rather than a full block indirection system for managing block movement between zones.
dm-zoned primary target is host-managed zoned block devices but it can also be used with host-aware device models to mitigate potential device-side performance degradation due to excessive random writing.
dm-zoned target devices can be formatted and checked using the dmzadm utility available at:
https://github.com/hgst/dm-zoned-tools
--- Documentation/device-mapper/dm-zoned.txt | 154 +++ drivers/md/Kconfig | 17 + drivers/md/Makefile | 2 + drivers/md/dm-zoned-io.c | 999 ++++++++++++++ drivers/md/dm-zoned-metadata.c | 2225 ++++++++++++++++++++++++++++++ drivers/md/dm-zoned-reclaim.c | 535 +++++++ drivers/md/dm-zoned.h | 530 +++++++ 7 files changed, 4462 insertions(+) create mode 100644 Documentation/device-mapper/dm-zoned.txt create mode 100644 drivers/md/dm-zoned-io.c create mode 100644 drivers/md/dm-zoned-metadata.c create mode 100644 drivers/md/dm-zoned-reclaim.c create mode 100644 drivers/md/dm-zoned.h
Documentation/device-mapper/dm-zoned.txt new file +154 -0
@@ -0,0 +1,154 @@ +dm-zoned +======== + +The dm-zoned device mapper exposes a zoned block device (ZBC and ZAC compliant +devices) as a regular block device without any write pattern constraint. In +effect, it implements a drive-managed zoned block device which hides to the +user (a file system or an application doing raw block device accesses) the +sequential write constraints of host-managed zoned block devices and can +mitigate the potential device-side performance degradation due to excessive +random writes on host-aware zoned block devices. + +For a more detailed description of the zoned block device models and +their constraints see (for SCSI devices): + +http://www.t10.org/drafts.htm#ZBC_Family + +and (for ATA devices): + +http://www.t13.org/Documents/UploadedDocuments/docs2015/ +di537r05-Zoned_Device_ATA_Command_Set_ZAC.pdf + +dm-zoned implementation is simple and minimizes system overhead (CPU and +memory usage as well as storage capacity loss). For a 10TB host-manmaged disk +with 256 MB zones, dm-zoned memory usage per disk instance is at most 4.5 MB +and as little as 5 zones will be used internally for storing metadata and +performaing reclaim operations. + +dm-zoned targte devices can be formatted and checked using the dmzadm utility +available at: + +https://github.com/hgst/dm-zoned-tools + +Algorithm +========= + +dm-zoned implements an on-disk buffering scheme to handle non-sequential write +accesses to the sequential zones of a zoned block device. Conventional zones +are used for caching as well as for storing internal metadata. + +The zones of the device are separated into 2 types: + +1) Metadata zones: these are conventional zones used to store metadata. +Metadata zones are not reported as useable capacity to the user. + +2) Data zones: all remaining zones, the vast majority of which will be +sequential zones used exclusively to store user data. The conventional zones +of the device may be used also for buffering user random writes. Data in these +zones may be directly mapped to the conventional zone, but later moved to a +sequential zone after so that the conventional zone can be reused for buffering +incoming random writes. + +dm-zoned exposes a logical device with a sector size of 4096 bytes, +irrespectively of the physical sector size of the backend zoned block device +being used. This allows reducing the amount of metadata needed to manage valid +blocks (blocks written). + +The on-disk metadata format is as follows: + +1) The first block of the first convnetional zone found contains the +super block which describes the amount and position on disk of metadata blocks. + +2) Following the super block, a set of blocks is used to describe the mapping +of the logical device blocks. The mapping is done per chunk of blocks, with +the chunk size equal to the zoned block device size. The mapping table is +indexed by chunk number and each mapping entry indicates the zone number of +the device storing the chunk of data. Each mapping entry may also indicate if +the zone number of a conventional zone used to buffer random modification to +the data zone. + +3) A set of blocks used to store bitmaps indicating the validity of blocks in +the data zones follows the mapping table. A valid block is defined as a block +that was writen and not discarded. For a buffered data chunk, a block is +always valid only in the data zone mapping the chunk or in the buffer zone of +the chunk. + +For a logical chunk mapped to a conventional zone, all write operations are +processed by directly writing to the zone. If the mapping zone is a +sequential zone, the write operation is processed directly only and only if +the write offset within the logical chunk is equal to the write pointer offset +within of the sequential data zone (i.e. the write operation is aligned on the +zone write pointer). Otherwise, write operations are processed indirectly +using a buffer zone. In such case, an unused conventional zone is allocated +and assigned to the chunk being accessed. Writing a block to the buffer zone +of a chunk will automatically invalidate the same block in the sequential zone +mapping the chunk. If all blocks of the sequential zone become invalid, the +zone is freed and the chunk buffer zone becomes the primary zone mapping the +chunk, resulting is native random write performance similar to a regular +block device. + +Read operations are processed according to the block validity information +provided by the bitmaps. Valid blocks are read either from the sequential zone +mapping a chunk, or if the chunk is buffered, from the buffer zone assigned. +If the accessed chunk has no mapping, or the accessed blocks are invalid, the +read buffer is zeroed and the read operation terminated. + +After some time, the limited number of convnetional zones available may be +exhausted (all used to map chunks or buffer sequential zones) and unaligned +writes to unbuffered chunks become impossible. To avoid such situation, a +reclaim process regularly scans used conventional zones and try to reclaim +the least recently used ones copying the valid blocks of the buffer zone +to a free sequential zone. Once the copy completes, the chunk mapping is +updated to point to the sequential zone and the buffer zone freed for reuse. + +Metadata Protection +=================== + +To protect metadata against corruption in case of sudden power loss or system +crash, 2 sets of metadata zones are used. One set, the primary set, is used as +the main metadata region, while the secondary set is used as a staging area. +Modified metadata are first written to the secondary set and validated by +updating the super block in the secondary set, indicating using a generation +counter that this set contains the newest metadata. Once this operation +completes, updates in place of metadata blocks can be done in the primary +metadata set, ensuring that one of the set is always consistent (all +modifications committed or none at all). Flush operations are used as a commit +point. Upon reception of a flush request, metadata modification activity is +temporarily blocked (for both incoming BIO processing and reclaim process) and +all dirty metadata blocks staged and updated. Normal operation is then resumed. +Metadata flush thus only temporarily delays write and discard requests. Read +requests can be concurrently processed while metadata flush is being executed. + +Usage +===== + +A zoned block device must first be formatted using the dmzadm tool. This will +analyze the device zone configuration, determine where to place the metadata +sets on the device and initialize the metadata sets. + +Ex: + +dmzadm --format /dev/sdxx + +For a formatted device, the target can be created normally with the dmsetup +utility. The only parameter that dm-zoned requires is the device name. + +Example scripts +=============== + +[[ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo "Usage: $0 <Zoned device path>" + exit 1 +fi + +dev="${1}" +shift + +modprobe dm-zoned + +echo "0 `blockdev --getsize ${dev}` dm-zoned ${dev}" | dmsetup create dmz-`basename ${dev}` +]] +
drivers/md/Kconfig +17 -0
@@ -521,6 +521,23 @@ config DM_INTEGRITY To compile this code as a module, choose M here: the module will be called dm-integrity. +config DM_ZONED + tristate "Drive-managed zoned block device target support" + depends on BLK_DEV_DM + depends on BLK_DEV_ZONED + ---help--- + This device-mapper target takes a host-managed or host-aware zoned + block device and expose most of its capacity as a regular block + device (drive-managed zoned block device) without any write + constraint. This is mainly intended for use with file systems that + do not natively support zoned block devices but still want to + benefit from the increased capacity offered by SMR disks. Other uses + by applications using raw block devices (for example object stores) + is also possible. + + To compile this code as a module, choose M here: the module will + be called dm-zoned. + If unsure, say N. endif # MD
drivers/md/Makefile +2 -0
@@ -20,6 +20,7 @@ dm-era-y += dm-era-target.o dm-verity-y += dm-verity-target.o md-mod-y += md.o bitmap.o raid456-y += raid5.o raid5-cache.o raid5-ppl.o +dm-zoned-y += dm-zoned-io.o dm-zoned-metadata.o dm-zoned-reclaim.o # Note: link order is important. All raid personalities # and must come before md.o, as they each initialise
@@ -60,6 +61,7 @@ obj-$(CONFIG_DM_CACHE_SMQ) += dm-cache-smq.o obj-$(CONFIG_DM_ERA) += dm-era.o obj-$(CONFIG_DM_LOG_WRITES) += dm-log-writes.o obj-$(CONFIG_DM_INTEGRITY) += dm-integrity.o +obj-$(CONFIG_DM_ZONED) += dm-zoned.o ifeq ($(CONFIG_DM_UEVENT),y) dm-mod-objs += dm-uevent.o
drivers/md/dm-zoned-io.c new file +999 -0
999 lines not on this page · raw message
drivers/md/dm-zoned-metadata.c new file +2225 -0
1,810 lines not on this page · raw message
drivers/md/dm-zoned-reclaim.c new file +535 -0
535 lines not on this page · raw message
drivers/md/dm-zoned.h new file +530 -0
530 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.9.3
Part of the diff is not shown here. View the raw message.
Quoted 4 lines · Bart Van Assche
From: Damien Le Moal <[email protected]>
[ Note: I'm resending this patch series on Damien's behalf because Damien's ]
[ e-mails apparently do not reach the dm-devel mailing list - Bart. ]
That isn't true. The v2 patchset is in dm-devel's patchwork. I just couldn't review it in time for 4.12. Anyway, I'll be reviewing this v3 patchset for 4.13 inclusion.
Mike
Quoted 11 lines · Mike Snitzer
Quoted 4 lines · Bart Van Assche
From: Damien Le Moal <[email protected]>
[ Note: I'm resending this patch series on Damien's behalf because Damien's ]
[ e-mails apparently do not reach the dm-devel mailing list - Bart. ]That isn't true. The v2 patchset is in dm-devel's patchwork. I just couldn't review it in time for 4.12. Anyway, I'll be reviewing this v3 patchset for 4.13 inclusion.
Hello Mike,
That's weird ... if you have a look at one of the dm-devel e-mail archives you will see that neither v2 nor v3 of this patch series as posted by Damien is in either archive:
* https://www.redhat.com/archives/dm-devel/
* https://www.spinics.net/lists/dm-devel/
However, the v3 of this patch series I posted is already available from the Red Hat archive server. Do you perhaps know whether anyone can help us to unravel the mysteries of the dm-devel mailing list server and why Damien receives an error e-mail when he uses smtp.office365.com to send mail to the dm-devel mailing list?
Thanks,
Bart.
I see quite a few issues with this patchset (only gotten through patches 1 - 6). I'll work through it in more detail and share my feedback/revisions tomorrow. Mostly just cleanups, renames, etc. But "the fun" is obviously once I get to the last patch.
Mike
Quoted 87 lines · Bart Van Assche
From: Damien Le Moal <[email protected]>
[ Note: I'm resending this patch series on Damien's behalf because Damien's ]
[ e-mails apparently do not reach the dm-devel mailing list - Bart. ]This series introduces zoned block device support to the device mapper infrastructure. Pathces are as follows:
- Patch 1: Add a new target type feature flag to indicate if a target type supports host-managed zoned block devices. This prevents using these drives with the current target types since none of them have the proper support implemented and will not operate properly with these drives.
- Patch 2: If a target device is a zoned block device, check that the range of LBAs mapped is aligned to the device zone size and that the device start offset also aligns to zone boundaries. This is necessary for zone reset and zone report correct execution.
- Patch 3: Check that the different target devices of a table have compatible zone sizes and models. This is necessary for target types that expose a zone model different from the underlying device.
- Patch 4: Fix handling ofREQ_OP_ZONE_RESETbios
- Patch 5: Fix handling ofREQ_OP_ZONE_REPORTbios
- Patch 6: Introduce a new helper function to reverse map a device zone report to the target LBA range
- Patch 7: Add support for host-managed zoned block devices to dm-flakey. This is necessary for testing file systems supporting natively these drives (e.g. f2fs).
- Patch 8: Add support for for zoned block devices to dm-linear. This can have useful applications during development and testing (e.g. allow creating smaller zoned devices with different combinations and positions of zones). There are also interesting applications for production, for instance, the ability to aggregate conventional zones of different drives to create a regular disk.
- Patch 9: Add sequential write enforcement todm_kcopyd_copyso that sequential zones of a host-managed zoned block device can be specified as destinations.
- Patch 10: New dm-zoned target type (this was already sent for review twice). This resend adds modifications suggested by Hannes to implement reclaim using dm-kcopyd. dm-zoned depends on patch 9.As always, comments and reviews are welcome.
Changes from v2:
- Rebased on 4.12-rc tree
- Added Bart Reviewed-by tagChanges from v1:
- Use for-loop in patch 3 as suggested by Bart
- Add memory shrinker to dm-zoned to shrink the metadata block cache under memory pressure (suggested by Bart)
- Added Hannes Reviewed-by tagDamien Le Moal (10):
dm-table: IntroduceDM_TARGET_ZONED_HMfeature
dm-table: Check device area zone alignment
dm-table: Check block devices zone model compatibility
dm: FixREQ_OP_ZONE_RESETbio handling
dm: FixREQ_OP_ZONE_REPORTbio handling
dm: Introducedm_remap_zone_report()
dm-flakey: Add support for zoned block devices
dm-linear: Add support for zoned block devices
dm-kcopyd: Add sequential write feature
dm-zoned: Drive-managed zoned block device targetDocumentation/device-mapper/dm-zoned.txt | 154 +++ drivers/md/Kconfig | 17 + drivers/md/Makefile | 2 + drivers/md/dm-flakey.c | 21 +- drivers/md/dm-kcopyd.c | 68 +- drivers/md/dm-linear.c | 15 +- drivers/md/dm-table.c | 143 ++ drivers/md/dm-zoned-io.c | 999 ++++++++++++++ drivers/md/dm-zoned-metadata.c | 2225 ++++++++++++++++++++++++++++++ drivers/md/dm-zoned-reclaim.c | 535 +++++++ drivers/md/dm-zoned.h | 530 +++++++ drivers/md/dm.c | 93 +- include/linux/device-mapper.h | 16 + include/linux/dm-kcopyd.h | 1 + 14 files changed, 4812 insertions(+), 7 deletions(-) create mode 100644 Documentation/device-mapper/dm-zoned.txt create mode 100644 drivers/md/dm-zoned-io.c create mode 100644 drivers/md/dm-zoned-metadata.c create mode 100644 drivers/md/dm-zoned-reclaim.c create mode 100644 drivers/md/dm-zoned.hSignature · 1 line
2.9.3
Quoted 4 lines · Mike Snitzer
I see quite a few issues with this patchset (only gotten through patches 1 - 6). I'll work through it in more detail and share my feedback/revisions tomorrow. Mostly just cleanups, renames, etc. But "the fun" is obviously once I get to the last patch.
FYI, couldn't get to this like I planned. And I'm taking some time off, won't get back to this until next Tuesday (5/23). To be clear, the things I noticed in the preliminary patches were very benign, but do need cleaning up.
I have every intention of getting this reviewed and staged for 4.13.
But would be useful to understand:
1) who will be regression testing this target once it is merged?
2) what is needed to test it? (I assume SMR drives?)
Mike
Mike,
(resending using outlook as I am still having troubles reaching @redhat.com email domain with any other email client. My apologies if multiple copies of this email show up)
Quoted 8 lines · Mike Snitzer
Quoted 4 lines · Mike Snitzer
I see quite a few issues with this patchset (only gotten through patches 1 - 6). I'll work through it in more detail and share my feedback/revisions tomorrow. Mostly just cleanups, renames, etc. But "the fun" is obviously once I get to the last patch.
Quoted 4 lines
FYI, couldn't get to this like I planned. And I'm taking some time off, won't get back to this until next Tuesday (5/23). To be clear, the things I noticed in the preliminary patches were very benign, but do need cleaning up.
Thank you for the review. Let me know the changes you would like to see and I will send an updated series.
Quoted 1 line
I have every intention of getting this reviewed and staged for 4.13.
That's great. Thanks.
Quoted 2 lines
But would be useful to understand:
1) who will be regression testing this target once it is merged?
Myself, Bart, and all other members of my team will be involved in maintaining and testing this. It is critical for us as an SMR disk vendor that those disks are supported correctly in Linux. So we will maintain and regression test all aspects of the zoned block device support constantly.
Quoted 1 line
2) what is needed to test it? (I assume SMR drives?)
Yes, SMR drives, but not necessarily physical ones. We are working on adding ZBC support to the SCSI target (that is missing). With that, we are planning to create a tcm (or tcmu) driver to emulate a host-aware or host-managed disk for testing, with a regular disk or file as back-end storage. This was also requested by file system maintainers (BtrFS) to allow testing of zoned block device support even without physical SMR disks available.
Since zoned block device support spans the entire block I/O stack (from block layer API down to LLD, with device mapper and SCSI/libata in the middle) we are also starting to design new test cases for the newly released blktests infrastructure. This will allow automated testing, including device mapper targets that supports zoned block devices.
Ideally, we will try to release everything for inclusion in 4.13, together with the device mapper support. But all the test parts may get spread over one or two release cycles. But again, the goal is to have a comprehensive automated test suite for zoned block device, similar to what is available for regular block devices.
Best regards.
Signature · 7 lines
Damien Le Moal, Western Digital Research Western Digital Corporation (and its subsidiaries) E-mail Confidentiality Notice & Disclaimer: This e-mail and any files transmitted with it may contain confidential or legally privileged information of WDC and/or its affiliates, and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. If you have received this e-mail in error, please notify the sender immediately and delete the e-mail in its entirety from your system.
From: Damien Le Moal <[email protected]>
[ Note: I'm resending this e-mail on Damien's behalf because Damien's ]
[ e-mails apparently do not reach the dm-devel mailing list - Bart. ]
Mike,
Quoted 8 lines · Mike Snitzer
Quoted 4 lines · Mike Snitzer
I see quite a few issues with this patchset (only gotten through patches 1 - 6). I'll work through it in more detail and share my feedback/revisions tomorrow. Mostly just cleanups, renames, etc. But "the fun" is obviously once I get to the last patch.
Quoted 4 lines
FYI, couldn't get to this like I planned. And I'm taking some time off, won't get back to this until next Tuesday (5/23). To be clear, the things I noticed in the preliminary patches were very benign, but do need cleaning up.
Thank you for the review. Let me know the changes you would like to see and I will send an updated series.
Quoted 1 line
I have every intention of getting this reviewed and staged for 4.13.
That's great. Thanks.
Quoted 2 lines
But would be useful to understand:
1) who will be regression testing this target once it is merged?
Myself, Bart, and all other members of my team will be involved in maintaining and testing this. It is critical for us as an SMR disk vendor that those disk are supported correctly in Linux. So we will maintain and regression test all aspects of the zoned block device support constantly.
Quoted 1 line
2) what is needed to test it? (I assume SMR drives?)
Yes, SMR drives, but not necessarily physical ones. We are working on adding ZBC support to the SCSI target (that is missing). With that, we are planning to create a tcm (or tcmu) driver to emulate a host-aware or host-managed disk for testing, with a regular disk or file as back-end storage. This was also requested by file system maintainers (BtrFS) to allow testing of zoned block device support even without physical SMR disks available.
Since zoned block device support spans the entire block I/O stack (from block layer API down to LLD, with device mapper and SCSI/libata in the middle) we are also starting to design new test cases for the newly released blktests infrastructure. This will allow automated testing, including device mapper targets that supports zoned block devices.
Ideally, we will try to release everything for inclusion in 4.13, together with the device mapper support. But all the test parts may get spread over one or two release cycles. But again, the goal is to have a comprehensive automated test suite for zoned block device, similar to what is available for regular block devices.
Best regards.
Signature · 2 lines
Damien Le Moal, Western Digital Research
Quoted 52 lines · Damien Le Moal
Mike,
(resending using outlook as I am still having troubles reaching @redhat.com email domain with any other email client. My apologies if multiple copies of this email show up)
Quoted 8 lines · Mike Snitzer
Quoted 4 lines · Mike Snitzer
I see quite a few issues with this patchset (only gotten through patches 1 - 6). I'll work through it in more detail and share my feedback/revisions tomorrow. Mostly just cleanups, renames, etc. But "the fun" is obviously once I get to the last patch.
Quoted 4 lines
FYI, couldn't get to this like I planned. And I'm taking some time off, won't get back to this until next Tuesday (5/23). To be clear, the things I noticed in the preliminary patches were very benign, but do need cleaning up.
Thank you for the review. Let me know the changes you would like to see and I will send an updated series.
Quoted 1 line
I have every intention of getting this reviewed and staged for 4.13.
That's great. Thanks.
Quoted 2 lines
But would be useful to understand:
1) who will be regression testing this target once it is merged?Myself, Bart, and all other members of my team will be involved in maintaining and testing this. It is critical for us as an SMR disk vendor that those disks are supported correctly in Linux. So we will maintain and regression test all aspects of the zoned block device support constantly.
Quoted 1 line
2) what is needed to test it? (I assume SMR drives?)
Yes, SMR drives, but not necessarily physical ones. We are working on adding ZBC support to the SCSI target (that is missing). With that, we are planning to create a tcm (or tcmu) driver to emulate a host-aware or host-managed disk for testing, with a regular disk or file as back-end storage. This was also requested by file system maintainers (BtrFS) to allow testing of zoned block device support even without physical SMR disks available.
Since zoned block device support spans the entire block I/O stack (from block layer API down to LLD, with device mapper and SCSI/libata in the middle) we are also starting to design new test cases for the newly released blktests infrastructure. This will allow automated testing, including device mapper targets that supports zoned block devices.
Quoted 5 lines
Ideally, we will try to release everything for inclusion in 4.13, together with the device mapper support. But all the test parts may get spread over one or two release cycles. But again, the goal is to have a comprehensive automated test suite for zoned block device, similar to what is available for regular block devices.
Thanks for all that context, much appreciated.
I'd like to get your thoughts on replacing the first 3 patches with something like the following patch (_not_ compile tested).
Basically I'm not interested in training DM for hypothetical zoned block device configurations. I only want the bare minimum that is needed to support the dm-zoned target at this point. The fact that dm-zoned is "drive managed" makes for a much more narrow validation (AFAICT anyway). I dropped the zone_sectors validation -- we can backfill it if you feel it important but I wanted to float this simplified patch as is:
drivers/md/dm-table.c +78 -0
@@ -340,6 +340,30 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,return 1 ; } +/* +* If the target is mapped to zoned block device(s), check +* that the zones are not partially mapped. +*/ +if (bdev_zoned_model (bdev) !=BLK_ZONED_NONE ) { +unsigned int zone_sectors =bdev_zone_sectors (bdev); + +if (start & (zone_sectors -1 )) { +DMWARN ("%s: start=%llu not aligned to h/w zone size %u of %s" , +dm_device_name (ti->table->md), + (unsigned long long )start, + zone_sectors,bdevname (bdev, b)); +return 1 ; + } + +if (len & (zone_sectors -1 )) { +DMWARN ("%s: len=%llu not aligned to h/w zone size %u of %s" , +dm_device_name (ti->table->md), + (unsigned long long )len, + zone_sectors,bdevname (bdev, b)); +return 1 ; + } + } +return 0 ; }
@@ -456,6 +480,8 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev, q->limits.alignment_offset, (unsigned long long) start << SECTOR_SHIFT); + limits->zoned =blk_queue_zoned_model (q); +return 0 ; }
@@ -1346,6 +1372,36 @@ bool dm_table_has_no_data_devices(struct dm_table *table)return true; } +static int device_is_zoned_model (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) +{ +struct request_queue *q =bdev_get_queue (dev->bdev); +enum blk_zoned_model zoned_model = *data; + +return q &&blk_queue_zoned_model (q) == zoned_model; +} + +static bool dm_table_supports_zoned_model (struct dm_table *t, +enum blk_zoned_model zoned_model) +{ +struct dm_target *ti; +unsigned i; + +for (i =0 ; i <dm_table_get_num_targets (t); i++) { + ti =dm_table_get_target (t, i); + +if (zoned_model ==BLK_ZONED_HM && + !dm_target_supports_zoned_hm (ti->type)) +return false; + +if (!ti->type->iterate_devices || + !ti->type->iterate_devices (ti, device_is_zoned_model, &zoned_model)) +return false; + } + +return true; +} +/* * Establish the new table's queue_limits and validate them. */
@@ -1355,6 +1411,7 @@ int dm_calculate_queue_limits(struct dm_table *table,struct dm_target *ti;struct queue_limits ti_limits;unsigned i; +enum blk_zoned_model zoned_model =BLK_ZONED_NONE ;blk_set_stacking_limits (limits);
@@ -1372,6 +1429,14 @@ int dm_calculate_queue_limits(struct dm_table *table, ti->type->iterate_devices (ti, dm_set_device_limits, &ti_limits); +if (zoned_model ==BLK_ZONED_NONE && ti_limits.zoned !=BLK_ZONED_NONE ) { +/* +* After stacking all limits, validate all devices +* in table support this zoned model. +*/ + zoned_model = ti_limits.zoned; + } +/* Set I/O hints portion of queue limits */ if (ti->type->io_hints) ti->type->io_hints (ti, &ti_limits);
@@ -1398,6 +1463,19 @@ int dm_calculate_queue_limits(struct dm_table *table, (unsigned long long) ti->len); } +/* +* Verify that the zoned model, as determined before any .io_hints +* override, is the same across all devices in the table. +* - but if limits->zoned is not BLK_ZONED_NONE validate match for it +*/ +if (limits->zoned !=BLK_ZONED_NONE ) + zoned_model = limits->zoned; +if (!dm_table_supports_zoned_model (table, zoned_model)) { +DMERR ("%s: zoned model is inconsistent across all devices" + dm_device_name(table->md)); +return -EINVAL ; + } +return validate_hardware_logical_block_alignment (table, limits); }
include/linux/device-mapper.h +6 -0
@@ -237,6 +237,12 @@ typedef unsigned (*dm_num_write_bios_fn) (struct dm_target *ti, struct bio *bio)#define DM_TARGET_PASSES_INTEGRITY 0x00000020#define dm_target_passes_integrity (type) ((type)->features & DM_TARGET_PASSES_INTEGRITY) +/* +* Indicates that a target supports host-managed zoned block devices. +*/ +#define DM_TARGET_ZONED_HM 0x00000040 +#define dm_target_supports_zoned_hm (type) ((type)->features & DM_TARGET_ZONED_HM) +struct dm_target {struct dm_table *table;struct target_type *type;
Mike,
Quoted 7 lines · Mike Snitzer
I'd like to get your thoughts on replacing the first 3 patches with something like the following patch (_not_ compile tested).
Basically I'm not interested in training DM for hypothetical zoned block device configurations. I only want the bare minimum that is needed to support the dm-zoned target at this point. The fact that dm-zoned is "drive managed" makes for a much more narrow validation (AFAICT anyway).
Indeed, it does. And in fact, no patches to the current dm code is necessary for dm-zoned to compile and run. So the bare minimum for dm-zoned is itself. This comes from the fact that dm-zoned will not accept a target that is not an entire zoned block device, and only a single target is allowed per dm-zoned instance. And since the queue limit defaults currently to the NONE zone model, everything nicely fit with the characteristics of the disk that dm-zoned exposes.
dm-zoned was coded this way for simplicity. Otherwise, the scattering of conventional zones across different targets would have complicated things quite a bit with metadata and would also potentially have generated nasty performance characteristics.
In the series, patches 1-9 are solely for supporting zoned block devices in a clean manner, and in particular dm-flakey, for testing file systems with native zoned block device support, and dm-linear, because it is easy and allows separating conventional and sequential zones into different drives, with the conventional zones block device becoming a normal disk (we have quite a few customers wanting to use SMR drives in this manner).
Quoted 2 lines
I dropped the
zone_sectorsvalidation -- we can backfill it if you feel it important but I wanted to float this simplified patch as is:
I think it is. The constraints imposed on zoned block devices in Linux that are not mandated by the standards are that all zones of the device must be the same size and the size must be a power of 2 number of LBAs. Without validating that all devices of a target have an equal zone size, a device created with dm-linear for instance would end up exposing different zone sizes on the same block device. That would break the block layer handling of zones through chunk_sectors.
That said, the patch below looks very good, much cleaner than what I had done. Let me test it and I will report back.
Quoted 143 lines
drivers/md/dm-table.c +78
-0@@ -340,6 +340,30 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,return 1 ; } +/* +* If the target is mapped to zoned block device(s), check +* that the zones are not partially mapped. +*/ +if (bdev_zoned_model (bdev) !=BLK_ZONED_NONE ) { +unsigned int zone_sectors =bdev_zone_sectors (bdev); + +if (start & (zone_sectors -1 )) { +DMWARN ("%s: start=%llu not aligned to h/w zone size %u of %s" , +dm_device_name (ti->table->md), + (unsigned long long )start, + zone_sectors,bdevname (bdev, b)); +return 1 ; + } + +if (len & (zone_sectors -1 )) { +DMWARN ("%s: len=%llu not aligned to h/w zone size %u of %s" , +dm_device_name (ti->table->md), + (unsigned long long )len, + zone_sectors,bdevname (bdev, b)); +return 1 ; + } + } +return 0 ; }@@ -456,6 +480,8 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev, q->limits.alignment_offset, (unsigned long long) start << SECTOR_SHIFT); + limits->zoned =blk_queue_zoned_model (q); +return 0 ; }@@ -1346,6 +1372,36 @@ bool dm_table_has_no_data_devices(struct dm_table *table)return true; } +static int device_is_zoned_model (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) +{ +struct request_queue *q =bdev_get_queue (dev->bdev); +enum blk_zoned_model zoned_model = *data; + +return q &&blk_queue_zoned_model (q) == zoned_model; +} + +static bool dm_table_supports_zoned_model (struct dm_table *t, +enum blk_zoned_model zoned_model) +{ +struct dm_target *ti; +unsigned i; + +for (i =0 ; i <dm_table_get_num_targets (t); i++) { + ti =dm_table_get_target (t, i); + +if (zoned_model ==BLK_ZONED_HM && + !dm_target_supports_zoned_hm (ti->type)) +return false; + +if (!ti->type->iterate_devices || + !ti->type->iterate_devices (ti, device_is_zoned_model, &zoned_model)) +return false; + } + +return true; +} +/* * Establish the new table's queue_limits and validate them. */ @@ -1355,6 +1411,7 @@ int dm_calculate_queue_limits(struct dm_table *table,struct dm_target *ti;struct queue_limits ti_limits;unsigned i; +enum blk_zoned_model zoned_model =BLK_ZONED_NONE ;blk_set_stacking_limits (limits);@@ -1372,6 +1429,14 @@ int dm_calculate_queue_limits(struct dm_table *table, ti->type->iterate_devices (ti, dm_set_device_limits, &ti_limits); +if (zoned_model ==BLK_ZONED_NONE && ti_limits.zoned !=BLK_ZONED_NONE ) { +/* +* After stacking all limits, validate all devices +* in table support this zoned model. +*/ + zoned_model = ti_limits.zoned; + } +/* Set I/O hints portion of queue limits */ if (ti->type->io_hints) ti->type->io_hints (ti, &ti_limits);@@ -1398,6 +1463,19 @@ int dm_calculate_queue_limits(struct dm_table *table, (unsigned long long) ti->len); } +/* +* Verify that the zoned model, as determined before any .io_hints +* override, is the same across all devices in the table. +* - but if limits->zoned is not BLK_ZONED_NONE validate match for it +*/ +if (limits->zoned !=BLK_ZONED_NONE ) + zoned_model = limits->zoned; +if (!dm_table_supports_zoned_model (table, zoned_model)) { +DMERR ("%s: zoned model is inconsistent across all devices" + dm_device_name(table->md)); +return -EINVAL ; + } +return validate_hardware_logical_block_alignment (table, limits); }include/linux/device-mapper.h +6
-0@@ -237,6 +237,12 @@ typedef unsigned (*dm_num_write_bios_fn) (struct dm_target *ti, struct bio *bio)#define DM_TARGET_PASSES_INTEGRITY 0x00000020#define dm_target_passes_integrity (type) ((type)->features & DM_TARGET_PASSES_INTEGRITY) +/* +* Indicates that a target supports host-managed zoned block devices. +*/ +#define DM_TARGET_ZONED_HM 0x00000040 +#define dm_target_supports_zoned_hm (type) ((type)->features & DM_TARGET_ZONED_HM) +struct dm_target {struct dm_table *table;struct target_type *type;
Signature · 10 lines
Damien Le Moal, Ph.D. Sr Manager, System Software Group, Western Digital Research [email protected] Tel: (+81) 0466-98-3593 (Ext. 51-3593) 1 kirihara-cho, Fujisawa, Kanagawa, 252-0888 Japan www.wdc.com, www.hgst.com Western Digital Corporation (and its subsidiaries) E-mail Confidentiality Notice & Disclaimer: This e-mail and any files transmitted with it may contain confidential or legally privileged information of WDC and/or its affiliates, and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. If you have received this e-mail in error, please notify the sender immediately and delete the e-mail in its entirety from your system.
Quoted 43 lines · Damien Le Moal
Mike,
Quoted 7 lines · Mike Snitzer
I'd like to get your thoughts on replacing the first 3 patches with something like the following patch (_not_ compile tested).
Basically I'm not interested in training DM for hypothetical zoned block device configurations. I only want the bare minimum that is needed to support the dm-zoned target at this point. The fact that dm-zoned is "drive managed" makes for a much more narrow validation (AFAICT anyway).
Indeed, it does. And in fact, no patches to the current dm code is necessary for dm-zoned to compile and run. So the bare minimum for dm-zoned is itself. This comes from the fact that dm-zoned will not accept a target that is not an entire zoned block device, and only a single target is allowed per dm-zoned instance. And since the queue limit defaults currently to the NONE zone model, everything nicely fit with the characteristics of the disk that dm-zoned exposes.
dm-zoned was coded this way for simplicity. Otherwise, the scattering of conventional zones across different targets would have complicated things quite a bit with metadata and would also potentially have generated nasty performance characteristics.
In the series, patches 1-9 are solely for supporting zoned block devices in a clean manner, and in particular dm-flakey, for testing file systems with native zoned block device support, and dm-linear, because it is easy and allows separating conventional and sequential zones into different drives, with the conventional zones block device becoming a normal disk (we have quite a few customers wanting to use SMR drives in this manner).
Quoted 2 lines
I dropped the
zone_sectorsvalidation -- we can backfill it if you feel it important but I wanted to float this simplified patch as is:I think it is. The constraints imposed on zoned block devices in Linux that are not mandated by the standards are that all zones of the device must be the same size and the size must be a power of 2 number of LBAs. Without validating that all devices of a target have an equal zone size, a device created with dm-linear for instance would end up exposing different zone sizes on the same block device. That would break the block layer handling of zones through
chunk_sectors.
Quoted 2 lines
That said, the patch below looks very good, much cleaner than what I had done. Let me test it and I will report back.
OK, please apply this incremental patch that adds in zone_sectors validation, thanks:
drivers/md/dm-table.c +45 -7
@@ -1402,6 +1402,41 @@ static bool dm_table_supports_zoned_model(struct dm_table *t,return true; } +static int device_matches_zone_sectors (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) +{ +struct request_queue *q =bdev_get_queue (dev->bdev); +unsigned int zone_sectors = *data; + +return q &&blk_queue_zone_sectors (q) == zone_sectors; +} + +static int validate_hardware_zoned_model (struct dm_table *table, +enum blk_zoned_model zoned_model, +unsigned int zone_sectors) +{ +if (!dm_table_supports_zoned_model (table, zoned_model)) { +DMERR ("%s: zoned model is inconsistent across all devices" , +dm_device_name (table->md)); +return -EINVAL ; + } + +if (zoned_model !=BLK_ZONED_NONE ) { +/* Check zone size validity and compatibility */ +if (!zone_sectors || !is_power_of_2 (zone_sectors)) +return -EINVAL ; + +if (!ti->type->iterate_devices || + !ti->type->iterate_devices (ti, device_matches_zone_sectors, &zone_sectors)) { +DMERR ("%s: zone sectors is inconsistent across all devices" , +dm_device_name (table->md)); +return -EINVAL ; + } + } + +return 0 ; +} +/* * Establish the new table's queue_limits and validate them. */
@@ -1412,6 +1447,7 @@ int dm_calculate_queue_limits(struct dm_table *table,struct queue_limits ti_limits;unsigned i;enum blk_zoned_model zoned_model =BLK_ZONED_NONE ; +unsigned int zone_sectors;blk_set_stacking_limits (limits);
@@ -1432,9 +1468,10 @@ int dm_calculate_queue_limits(struct dm_table *table,if (zoned_model ==BLK_ZONED_NONE && ti_limits.zoned !=BLK_ZONED_NONE ) {/* * After stacking all limits, validate all devices -* in table support this zoned model. +* in table support this zoned model and zone sectors. */ zoned_model = ti_limits.zoned; + zone_sectors = ti_limits.chunk_sectors; }/* Set I/O hints portion of queue limits */
@@ -1464,17 +1501,18 @@ int dm_calculate_queue_limits(struct dm_table *table, }/* -* Verify that the zoned model, as determined before any .io_hints -* override, is the same across all devices in the table. +* Verify that the zoned model and zone sectors, as determined before +* any .io_hints override, are the same across all devices in the table. * - but if limits->zoned is not BLK_ZONED_NONE validate match for it +* - simillarly, check all devices conform to limits->chunk_sectors if +* .io_hints altered them */ if (limits->zoned !=BLK_ZONED_NONE ) zoned_model = limits->zoned; -if (!dm_table_supports_zoned_model (table, zoned_model)) { -DMERR ("%s: zoned model is inconsistent across all devices" - dm_device_name(table->md)); +if (limits->chunk_sectors != zone_sectors) + zone_sectors = limits->chunk_sectors; +if (validate_hardware_zoned_model (table, zoned_model, zone_sectors))return -EINVAL ; - }return validate_hardware_logical_block_alignment (table, limits); }
Quoted 8 lines · Mike Snitzer
Quoted 2 lines · Damien Le Moal
That said, the patch below looks very good, much cleaner than what I had done. Let me test it and I will report back.
OK, please apply this incremental patch that adds in
zone_sectorsvalidation, thanks:
I fixed that patch up and staged all your preliminary zoned block device work into linux-dm.git's 'for-4.13/dm' (and also staged in linux-next).
Please retest against 'for-4.13/dm' and send any incremental fixes you'd like folded in (implied is 'for-4.13/dm' can be rebased):
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/log/?h=for-4.13/dm
FYI, I'll be focusing on reviewing/staging your dm-zoned patch next week (Tues-Thurs).
Thanks,
Mike