dm: discard support for the linear target
PATCH v2 1/2 dm: discard support for the linear target
Allow discards to be passed through to a single device linear mapping. Introduce DM_TARGET_SUPPORTS_DISCARDS target features flag that each target must set once discard support is added.
Verify table's underlying devices support discards prior to setting the associated DM device as capable of discards (via QUEUE_FLAG_DISCARD).
--- drivers/md/dm-linear.c | 1 + drivers/md/dm-table.c | 51 ++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 60 ++++++++++++++++++++++++++++++++-------- drivers/md/dm.h | 1 + include/linux/device-mapper.h | 1 + 5 files changed, 102 insertions(+), 12 deletions(-)
drivers/md/dm-linear.c +1 -0
@@ -152,6 +152,7 @@ static struct target_type linear_target = { .ioctl = linear_ioctl, .merge = linear_merge, .iterate_devices = linear_iterate_devices, + .features = DM_TARGET_SUPPORTS_DISCARDS, };int __init dm_linear_init (void )
drivers/md/dm-table.c +51 -0
87 lines not on this page · raw message
drivers/md/dm.c +48 -12
99 lines not on this page · raw message
drivers/md/dm.h +1 -0
@@ -62,6 +62,7 @@ int dm_table_any_busy_target(struct dm_table *t);int dm_table_set_type (struct dm_table *t);unsigned dm_table_get_type (struct dm_table *t);bool dm_table_request_based (struct dm_table *t); +bool dm_table_supports_discards (struct dm_table *t);int dm_table_alloc_md_mempools (struct dm_table *t);void dm_table_free_md_mempools (struct dm_table *t);struct dm_md_mempools *dm_table_get_md_mempools (struct dm_table *t);
include/linux/device-mapper.h +1 -0
@@ -130,6 +130,7 @@ void dm_put_device(struct dm_target *ti, struct dm_dev *d);/* * Target features */ +#define DM_TARGET_SUPPORTS_DISCARDS 0x00000001struct target_type {uint64_t features;
Signature · 1 line
1.6.5.rc2
RFC PATCH 2/2 dm: add support for splitting discard requests
Enable the striped target to support discard requests by splitting a single discard into N discards on a stripe chunk size boundary.
Follow on core block layer work to merge discards would be helpful.
This work relies on DM's clone_bio() always having BIO_RW_BARRIER set for discard requests. Without BIO_RW_BARRIER the block layer will spew "blk: request botched" warnings for discards that were split by DM.
- this clearly needs further investigation!
--- drivers/md/dm-stripe.c | 1 + drivers/md/dm-table.c | 6 ------ drivers/md/dm.c | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 10 deletions(-)
drivers/md/dm-stripe.c +1 -0
@@ -349,6 +349,7 @@ static struct target_type stripe_target = { .status = stripe_status, .iterate_devices = stripe_iterate_devices, .io_hints = stripe_io_hints, + .features = DM_TARGET_SUPPORTS_DISCARDS, };int __init dm_stripe_init (void )
drivers/md/dm-table.c +0 -6
@@ -911,12 +911,6 @@ int dm_table_complete(struct dm_table *t)int r =0 ;unsigned int leaf_nodes; -/* -* We only support discards if there is exactly one underlying device. -*/ -if (!list_is_singular (&t->devices)) - t->discards_supported =0 ; -/* how many indexes will the btree have ? */ leaf_nodes =dm_div_up (t->num_targets,KEYS_PER_NODE ); t->depth =1 +int_log (leaf_nodes,CHILDREN_PER_NODE );
drivers/md/dm.c +33 -4
@@ -1137,7 +1137,12 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector, clone =bio_alloc_bioset (GFP_NOIO , bio->bi_max_vecs, bs);__bio_clone (clone, bio); - clone->bi_rw &= ~(1 <<BIO_RW_BARRIER ); +if (!bio_rw_flagged (bio,BIO_RW_DISCARD )) + clone->bi_rw &= ~(1 <<BIO_RW_BARRIER ); +else if (!bio_rw_flagged (bio,BIO_RW_BARRIER )) { +/* discard w/o barrier results in "blk: request botched" */ + clone->bi_rw |= (1 <<BIO_RW_BARRIER ); + } clone->bi_destructor = dm_bio_destructor; clone->bi_sector = sector; clone->bi_idx = idx;
@@ -1217,7 +1222,7 @@ static void __clone_and_map_simple(struct clone_info *ci, struct dm_target *ti)static int __clone_and_map_discard (struct clone_info *ci) {struct dm_target *ti; -sector_t max; +sector_t len =0 , max;if (!dm_table_supports_discards (ci->map))return -EOPNOTSUPP ;
@@ -1232,9 +1237,33 @@ static int __clone_and_map_discard(struct clone_info *ci)__clone_and_map_simple (ci, ti); else {/* -* FIXME: Handle a discard that spans two or more targets. +* Handle a discard that spans two or more targets. */ -return -EOPNOTSUPP ; +struct bio *clone; +struct dm_target_io *tio; +sector_t remaining = ci->sector_count; +unsigned int offset =0 ; + +do { +if (offset) { + ti =dm_table_find_target (ci->map, ci->sector); +if (!dm_target_is_valid (ti)) +return -EIO ; + + max =max_io_len (ci->md, ci->sector, ti); + } + + len =min (remaining, max); + + tio =alloc_tio (ci, ti); + clone =clone_bio (ci->bio, ci->sector,0 , +0 , len, ci->md->bs); +__map_bio (ti, clone, tio); + + ci->sector += len; + ci->sector_count -= len; + offset +=to_bytes (len); + }while (remaining -= len); }return 0 ;
Signature · 1 line
1.6.5.rc2
Re: [RFC PATCH 2/2] dm: add support for splitting discard requests
Quoted 9 lines · Mike Snitzer
Enable the striped target to support discard requests by splitting a single discard into N discards on a stripe chunk size boundary.
Follow on core block layer work to merge discards would be helpful.
This work relies on DM's
clone_bio()always havingBIO_RW_BARRIERset for discard requests. WithoutBIO_RW_BARRIERthe block layer will spew "blk: request botched" warnings for discards that were split by DM.
- this clearly needs further investigation!
Btw, you can get discard requests from the upper layer that do not have BIO_RW_BARRIER set, currently from the BLKDISCARD ioctl used by various mkfs tools, and also from the not yet merged xfs discard support.
Can I assume it works fine with those?
drivers/md/dm.c static struct bio *clone_bio(struct bio *bio, sector_t sector, · line 1145
Quoted 7 lines
drivers/md/dm.c +6
-1- clone->bi_rw &= ~(1 <<BIO_RW_BARRIER ); +if (!bio_rw_flagged (bio,BIO_RW_DISCARD )) + clone->bi_rw &= ~(1 <<BIO_RW_BARRIER ); +else if (!bio_rw_flagged (bio,BIO_RW_BARRIER )) { +/* discard w/o barrier results in "blk: request botched" */ + clone->bi_rw |= (1 <<BIO_RW_BARRIER ); + }
So previously we unconditionally cleared the BIO_RW_BARRIER bit in the clone.
Maybe to make it cleared reorder the if a bit and also just set the barrier bit unconditionally for discards, similar to how we unconditionally clear it otherwise:
if (bio_rw_flagged(bio, BIO_RW_DISCARD)) {
/* discard w/o barrier results in "blk: request botched" */
clone->bi_rw |= (1 << BIO_RW_BARRIER);
} else {
clone->bi_rw &= ~(1 << BIO_RW_BARRIER);
}maybe even with a slightly longer comment explaining what's actually going on here, and a FIXME.
Re: [RFC PATCH 2/2] dm: add support for splitting discard requests
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Mike Snitzer
Enable the striped target to support discard requests by splitting a single discard into N discards on a stripe chunk size boundary.
Follow on core block layer work to merge discards would be helpful.
This work relies on DM's
clone_bio()always havingBIO_RW_BARRIERset for discard requests. WithoutBIO_RW_BARRIERthe block layer will spew "blk: request botched" warnings for discards that were split by DM.
- this clearly needs further investigation!
Quoted 4 lines
Btw, you can get discard requests from the upper layer that do not have
BIO_RW_BARRIERset, currently from the BLKDISCARD ioctl used by various mkfs tools, and also from the not yet merged xfs discard support.
Yes, I'm aware of the BLKDISCARD ioctl. I added the 'else if' clause which adds the BIO_RW_BARRIER flag specifically for that case. Testing showed the mkfs.ext4 uses the BLKDISCARD ioctl and it would result in "blk: request botched" when operated against a striped DM target (that was performing the discrad splitting).
Quoted 1 line
Can I assume it works fine with those?
Yes it works, with or without DM adding the BIO_RW_BARRIER flag, but without the flag it'll spew "blk: request botched" and the block layer will fix things up with this at the end of blk_update_request():
/*
* If total number of sectors is less than the first segment
* size, something has gone terribly wrong.
*/
if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) {
printk(KERN_ERR "blk: request botched\n");
req->__data_len = blk_rq_cur_bytes(req);
}Additional tracing showed blk_rq_bytes(req) was always 0 if DM didn't set BIO_RW_BARRIER for split discard requests. It could be that if BIO_RW_BARRIER is set we'll exit early from blk_update_request to avoid its "blk: request botched"? I'll look closer.
Quoted 9 lines
drivers/md/dm.c static struct bio *clone_bio(struct bio *bio, sector_t sector, · line 1145
Quoted 7 lines
drivers/md/dm.c +6
-1- clone->bi_rw &= ~(1 <<BIO_RW_BARRIER ); +if (!bio_rw_flagged (bio,BIO_RW_DISCARD )) + clone->bi_rw &= ~(1 <<BIO_RW_BARRIER ); +else if (!bio_rw_flagged (bio,BIO_RW_BARRIER )) { +/* discard w/o barrier results in "blk: request botched" */ + clone->bi_rw |= (1 <<BIO_RW_BARRIER ); + }So previously we unconditionally cleared the
BIO_RW_BARRIERbit in the clone.
Yes. I'd like to understand why from Mikulas.
Quoted 11 lines
Maybe to make it clear reorder the if a bit and also just set the barrier bit unconditionally for discards, similar to how we unconditionally clear it otherwise:
if (bio_rw_flagged(bio, BIO_RW_DISCARD)) { /* discard w/o barrier results in "blk: request botched" */ clone->bi_rw |= (1 << BIO_RW_BARRIER); } else { clone->bi_rw &= ~(1 << BIO_RW_BARRIER); }
Quoted 2 lines
maybe even with a slightly longer comment explaining what's actually going on here, and a FIXME.
OK, your reorder is clearer. As for a FIXME describing what's going on
here: I'll work to sort that out.. it is still unclear to me why the BIO_RW_BARRIER flag silences the "blk: request botched" spew from blk_update_request().
Thanks,
Mike
Quoted 16 lines · Mike Snitzer
Allow discards to be passed through to a single device linear mapping. Introduce
DM_TARGET_SUPPORTS_DISCARDStarget features flag that each target must set once discard support is added.Verify table's underlying devices support discards prior to setting the associated DM device as capable of discards (via
QUEUE_FLAG_DISCARD).Signed-off-by Mike Snitzer <[email protected]>--- drivers/md/dm-linear.c | 1 + drivers/md/dm-table.c | 51 ++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 60 ++++++++++++++++++++++++++++++++-------- drivers/md/dm.h | 1 + include/linux/device-mapper.h | 1 + 5 files changed, 102 insertions(+), 12 deletions(-)
drivers/md/dm-table.c struct mapped_device *dm_table_get_md(struct dm_table *t) · line 1258
Quoted 9 lines
drivers/md/dm-table.c +9
-0+static int device_discard_incapable (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) +{ +struct block_device *bdev = dev->bdev; +struct request_queue *q =bdev_get_queue (bdev); + +WARN_ON (!q); +return (!q || !blk_queue_discard (q)); +}
How could a NULL queue happen here?
Otherwise it looks okay to me, but my DM knowledge is rather limited.
Quoted 17 lines · Christoph Hellwig
Quoted 15 lines · Mike Snitzer
Allow discards to be passed through to a single device linear mapping. Introduce
DM_TARGET_SUPPORTS_DISCARDStarget features flag that each target must set once discard support is added.Verify table's underlying devices support discards prior to setting the associated DM device as capable of discards (via
QUEUE_FLAG_DISCARD).Signed-off-by Mike Snitzer <[email protected]>--- drivers/md/dm-linear.c | 1 + drivers/md/dm-table.c | 51 ++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 60 ++++++++++++++++++++++++++++++++-------- drivers/md/dm.h | 1 + include/linux/device-mapper.h | 1 + 5 files changed, 102 insertions(+), 12 deletions(-)
Quoted 11 lines
drivers/md/dm-table.c struct mapped_device *dm_table_get_md(struct dm_table *t) · line 1258
Quoted 9 lines
drivers/md/dm-table.c +9
-0+static int device_discard_incapable (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) +{ +struct block_device *bdev = dev->bdev; +struct request_queue *q =bdev_get_queue (bdev); + +WARN_ON (!q); +return (!q || !blk_queue_discard (q)); +}How could a NULL queue happen here?
It really cannot, I was just being defensive.
PATCH v3 1/2 dm: discard support for the linear target
In reply to Mike SnitzerAllow discards to be passed through to a single device linear mapping. Introduce DM_TARGET_SUPPORTS_DISCARDS target features flag that each target must set once discard support is added.
Verify table's underlying devices support discards prior to setting the associated DM device as capable of discards (via QUEUE_FLAG_DISCARD).
--- drivers/md/dm-linear.c | 1 drivers/md/dm-table.c | 50 +++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 60 +++++++++++++++++++++++++++++++++--------- drivers/md/dm.h | 1 include/linux/device-mapper.h | 1 5 files changed, 101 insertions(+), 12 deletions(-)
drivers/md/dm-linear.c +1 -0
@@ -152,6 +152,7 @@ static struct target_type linear_target .ioctl = linear_ioctl, .merge = linear_merge, .iterate_devices = linear_iterate_devices, + .features = DM_TARGET_SUPPORTS_DISCARDS, };int __init dm_linear_init (void )
drivers/md/dm-table.c +50 -0
86 lines not on this page · raw message
drivers/md/dm.c +48 -12
99 lines not on this page · raw message
drivers/md/dm.h +1 -0
@@ -62,6 +62,7 @@ int dm_table_any_busy_target(struct dm_tint dm_table_set_type (struct dm_table *t);unsigned dm_table_get_type (struct dm_table *t);bool dm_table_request_based (struct dm_table *t); +bool dm_table_supports_discards (struct dm_table *t);int dm_table_alloc_md_mempools (struct dm_table *t);void dm_table_free_md_mempools (struct dm_table *t);struct dm_md_mempools *dm_table_get_md_mempools (struct dm_table *t);
include/linux/device-mapper.h +1 -0
@@ -130,6 +130,7 @@ void dm_put_device(struct dm_target *ti,/* * Target features */ +#define DM_TARGET_SUPPORTS_DISCARDS 0x00000001struct target_type {uint64_t features;
Quoted 8 lines · Mike Snitzer
Allow discards to be passed through to a single device linear mapping. Introduce
DM_TARGET_SUPPORTS_DISCARDStarget features flag that each target must set once discard support is added.Verify table's underlying devices support discards prior to setting the associated DM device as capable of discards (via
QUEUE_FLAG_DISCARD).Signed-off-by Mike Snitzer <[email protected]>
I mistakenly dropped Joe's Reviewed-by after making agk's suggested (minor) changes for v3:
- invert if..else logic in __clone_and_map_discard
- remove unnecessary uninitialized_var() in dm_table_supports_discards