From: Mike Snitzer <snitzer@redhat.com>
To: dm-devel@redhat.com
Subject: [PATCH v2 5/9] dm: improve noclone bio support
Date: Wed, 20 Feb 2019 16:44:32 -0500 [thread overview]
Message-ID: <20190220214436.38476-6-snitzer@redhat.com> (raw)
In-Reply-To: <20190220214436.38476-1-snitzer@redhat.com>
Leverage fact that dm_queue_split() enables use of noclone support even
for targets that require additional splitting (via ti->max_io_len).
To achieve this move noclone processing from dm_make_request() to
dm_process_bio() and check if bio->bi_end_io is already set to
noclone_endio. This also fixes dm_wq_work() to be able to support
noclone bios (because it calls dm_process_bio()).
While at it, clean up ->map() return processing to be comparable to
__map_bio() and add some code comments that explain why certain
conditionals exist to prevent the use of noclone.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
---
drivers/md/dm.c | 103 ++++++++++++++++++++++++++++++++++----------------------
1 file changed, 62 insertions(+), 41 deletions(-)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 57919f211acc..d84735be6927 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1764,14 +1764,75 @@ static blk_qc_t dm_process_bio(struct mapped_device *md,
* If in ->make_request_fn we need to use blk_queue_split(), otherwise
* queue_limits for abnormal requests (e.g. discard, writesame, etc)
* won't be imposed.
+ *
+ * For normal READ and WRITE requests we benefit from upfront splitting
+ * via dm_queue_split() because we can then leverage noclone support below.
*/
- if (current->bio_list) {
+ if (current->bio_list && (bio->bi_end_io != noclone_endio)) {
+ /*
+ * It is fine to use {blk,dm}_queue_split() before opting to use noclone
+ * because any ->bi_private and ->bi_end_io will get saved off below.
+ * Once noclone_endio() is called the bio_chain's endio will kick in.
+ * - __split_and_process_bio() can split further, but any targets that
+ * require late _DM_ initiated splitting (e.g. dm_accept_partial_bio()
+ * callers) shouldn't set ti->no_clone.
+ */
if (is_abnormal_io(bio))
blk_queue_split(md->queue, &bio);
else
dm_queue_split(md, ti, &bio);
}
+ if (dm_table_supports_noclone(map) &&
+ (bio_op(bio) == REQ_OP_READ || bio_op(bio) == REQ_OP_WRITE) &&
+ likely(!(bio->bi_opf & REQ_PREFLUSH)) &&
+ likely(!bio_integrity(bio)) && /* integrity requires specialized processing */
+ likely(!dm_stats_used(&md->stats))) { /* noclone doesn't support dm-stats */
+ int r;
+ struct dm_noclone *noclone;
+
+ /* Already been here if bio->bi_end_io is noclone_endio, reentered via dm_wq_work() */
+ if (bio->bi_end_io != noclone_endio) {
+ noclone = kmalloc_node(sizeof(*noclone), GFP_NOWAIT, md->numa_node_id);
+ if (unlikely(!noclone))
+ goto no_fast_path;
+
+ noclone->md = md;
+ noclone->start_time = jiffies;
+ noclone->orig_bi_end_io = bio->bi_end_io;
+ noclone->orig_bi_private = bio->bi_private;
+ bio->bi_end_io = noclone_endio;
+ bio->bi_private = noclone;
+ } else
+ noclone = bio->bi_private;
+
+ start_io_acct(md, bio);
+ r = ti->type->map(ti, bio);
+ switch (r) {
+ case DM_MAPIO_SUBMITTED:
+ break;
+ case DM_MAPIO_REMAPPED:
+ /* the bio has been remapped so dispatch it */
+ if (md->type == DM_TYPE_NVME_BIO_BASED)
+ ret = direct_make_request(bio);
+ else
+ ret = generic_make_request(bio);
+ break;
+ case DM_MAPIO_KILL:
+ bio_io_error(bio);
+ break;
+ case DM_MAPIO_REQUEUE:
+ bio->bi_status = BLK_STS_DM_REQUEUE;
+ noclone_endio(bio);
+ break;
+ default:
+ DMWARN("unimplemented target map return value: %d", r);
+ BUG();
+ }
+
+ return ret;
+ }
+no_fast_path:
if (dm_get_md_type(md) == DM_TYPE_NVME_BIO_BASED)
return __process_bio(md, map, bio, ti);
else
@@ -1798,48 +1859,8 @@ static blk_qc_t dm_make_request(struct request_queue *q, struct bio *bio)
return ret;
}
- if (dm_table_supports_noclone(map) &&
- (bio_op(bio) == REQ_OP_READ || bio_op(bio) == REQ_OP_WRITE) &&
- likely(!(bio->bi_opf & REQ_PREFLUSH)) &&
- !bio_flagged(bio, BIO_CHAIN) &&
- likely(!bio_integrity(bio)) &&
- likely(!dm_stats_used(&md->stats))) {
- int r;
- struct dm_noclone *noclone;
- struct dm_target *ti = dm_table_find_target(map, bio->bi_iter.bi_sector);
- if (unlikely(!dm_target_is_valid(ti)))
- goto no_fast_path;
- if (unlikely(bio_sectors(bio) > max_io_len(bio->bi_iter.bi_sector, ti)))
- goto no_fast_path;
- noclone = kmalloc_node(sizeof(*noclone), GFP_NOWAIT, md->numa_node_id);
- if (unlikely(!noclone))
- goto no_fast_path;
- noclone->md = md;
- noclone->start_time = jiffies;
- noclone->orig_bi_end_io = bio->bi_end_io;
- noclone->orig_bi_private = bio->bi_private;
- bio->bi_end_io = noclone_endio;
- bio->bi_private = noclone;
- start_io_acct(md, bio);
- r = ti->type->map(ti, bio);
- ret = BLK_QC_T_NONE;
- if (likely(r == DM_MAPIO_REMAPPED)) {
- ret = generic_make_request(bio);
- } else if (likely(r == DM_MAPIO_SUBMITTED)) {
- } else if (r == DM_MAPIO_KILL) {
- bio->bi_status = BLK_STS_IOERR;
- noclone_endio(bio);
- } else {
- DMWARN("unimplemented target map return value: %d", r);
- BUG();
- }
- goto put_table_ret;
- }
-
-no_fast_path:
ret = dm_process_bio(md, map, bio);
-put_table_ret:
dm_put_live_table(md, srcu_idx);
return ret;
}
--
2.15.0
next prev parent reply other threads:[~2019-02-20 21:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-20 21:44 [PATCH v2 0/9] dm: changes staged in linux-next for 5.1 so far Mike Snitzer
2019-02-20 21:44 ` [PATCH v2 1/9] dm: update dm_process_bio() to split bio if in ->make_request_fn() Mike Snitzer
2019-02-20 21:44 ` [PATCH v2 2/9] dm: eliminate 'split_discard_bios' flag from DM target interface Mike Snitzer
2019-02-21 4:36 ` Mike Snitzer
2019-02-20 21:44 ` [PATCH v2 3/9] dm: refactor start_io_acct and end_io_acct Mike Snitzer
2019-02-20 21:44 ` [PATCH v2 4/9] dm: implement noclone optimization for bio-based Mike Snitzer
2019-02-20 21:44 ` Mike Snitzer [this message]
2019-02-22 10:59 ` [PATCH v2 5/9] dm: improve noclone bio support Mikulas Patocka
2019-02-22 15:22 ` Mike Snitzer
2019-02-22 16:56 ` Mike Snitzer
2019-02-20 21:44 ` [PATCH v2 6/9] dm: add per-bio-data support to noclone bio Mike Snitzer
2019-02-20 21:44 ` [PATCH v2 7/9] dm: improve noclone_endio() to support multipath target Mike Snitzer
2019-02-20 21:44 ` [PATCH v2 8/9] dm mpath: enable noclone support for bio-based Mike Snitzer
2019-02-20 21:44 ` [PATCH v2 9/9] dm: remove unused _rq_tio_cache and _rq_cache Mike Snitzer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190220214436.38476-6-snitzer@redhat.com \
--to=snitzer@redhat.com \
--cc=dm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox