From: NeilBrown <neilb@suse.de>
To: linux-kernel@vger.kernel.org
Subject: [PATCH 035 of 35] Simplify bio splitting in dm.
Date: Tue, 31 Jul 2007 12:18:52 +1000 [thread overview]
Message-ID: <1070731021852.25640@suse.de> (raw)
In-Reply-To: 20070731112539.22428.patches@notabene
Use the new bio_multi_split to simplify dm bio splitting.
Signed-off-by: Neil Brown <neilb@suse.de>
### Diffstat output
./drivers/md/dm.c | 166 ++++++------------------------------------------------
1 file changed, 20 insertions(+), 146 deletions(-)
diff .prev/drivers/md/dm.c ./drivers/md/dm.c
--- .prev/drivers/md/dm.c 2007-07-31 11:21:22.000000000 +1000
+++ ./drivers/md/dm.c 2007-07-31 11:21:30.000000000 +1000
@@ -526,11 +526,6 @@ static void clone_endio(struct bio *bio,
dec_pending(tio->io, error);
- /*
- * Store md for cleanup instead of tio which is about to get freed.
- */
- bio->bi_private = md->bs;
-
bio_put(bio);
free_tio(md, tio);
}
@@ -590,10 +585,6 @@ static void __map_bio(struct dm_target *
/* error the io and bail out, or requeue it if needed */
md = tio->io->md;
dec_pending(tio->io, r);
- /*
- * Store bio_set for cleanup.
- */
- clone->bi_private = md->bs;
bio_put(clone);
free_tio(md, tio);
} else if (r) {
@@ -607,149 +598,35 @@ struct clone_info {
struct dm_table *map;
struct bio *bio;
struct dm_io *io;
- sector_t sector;
- sector_t sector_count;
- unsigned short idx;
};
-static void dm_bio_destructor(struct bio *bio)
-{
- struct bio_set *bs = bio->bi_private;
-
- bio_free(bio, bs);
-}
-
-/*
- * Creates a little bio that is just does part of a bvec.
- */
-static struct bio *split_bvec(struct bio *bio, sector_t sector,
- unsigned short idx, unsigned int offset,
- unsigned int len, struct bio_set *bs)
-{
- struct bio *clone;
- struct bio_vec *bv = bio->bi_io_vec + idx;
-
- clone = bio_alloc_bioset(GFP_NOIO, 1, bs);
- clone->bi_destructor = dm_bio_destructor;
- *clone->bi_io_vec = *bv;
-
- clone->bi_sector = sector;
- clone->bi_bdev = bio->bi_bdev;
- clone->bi_rw = bio->bi_rw;
- clone->bi_vcnt = 1;
- clone->bi_size = to_bytes(len);
- clone->bi_io_vec->bv_offset = offset;
- clone->bi_io_vec->bv_len = clone->bi_size;
-
- return clone;
-}
-
-/*
- * Creates a bio that consists of range of complete bvecs.
- */
-static struct bio *clone_bio(struct bio *bio, sector_t sector,
- unsigned short idx, unsigned short bv_count,
- unsigned int len, struct bio_set *bs)
-{
- struct bio *clone;
-
- clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs);
- __bio_clone(clone, bio);
- clone->bi_destructor = dm_bio_destructor;
- clone->bi_sector = sector;
- clone->bi_io_vec += idx;
- clone->bi_vcnt = bv_count;
- clone->bi_size = to_bytes(len);
-
- return clone;
-}
-
static void __clone_and_map(struct clone_info *ci)
{
- struct bio *clone, *bio = ci->bio;
- struct dm_target *ti = dm_table_find_target(ci->map, ci->sector);
- sector_t len = 0, max = max_io_len(ci->md, ci->sector, ti);
- struct dm_target_io *tio;
+ struct bio *bio = ci->bio;
+ struct bio *remainder = bio;
- /*
- * Allocate a target io object.
- */
- tio = alloc_tio(ci->md);
- tio->io = ci->io;
- tio->ti = ti;
- memset(&tio->info, 0, sizeof(tio->info));
+ while (remainder) {
+ struct bio *clone;
+ struct dm_target *ti =
+ dm_table_find_target(ci->map,
+ remainder->bi_sector);
+ sector_t len = 0;
+ sector_t max = max_io_len(ci->md, remainder->bi_sector, ti);
+ struct dm_target_io *tio;
- if (ci->sector_count <= max) {
/*
- * Optimise for the simple case where we can do all of
- * the remaining io with a single clone.
+ * Allocate a target io object.
*/
- clone = clone_bio(bio, ci->sector, ci->idx,
- bio->bi_vcnt - ci->idx, ci->sector_count,
- ci->md->bs);
- __map_bio(ti, clone, tio);
- ci->sector_count = 0;
-
- } else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
- /*
- * There are some bvecs that don't span targets.
- * Do as many of these as possible.
- */
- int i;
- sector_t remaining = max;
- sector_t bv_len;
-
- for (i = ci->idx; remaining && (i < bio->bi_vcnt); i++) {
- bv_len = to_sector(bio->bi_io_vec[i].bv_len);
+ tio = alloc_tio(ci->md);
+ tio->io = ci->io;
+ tio->ti = ti;
+ memset(&tio->info, 0, sizeof(tio->info));
- if (bv_len > remaining)
- break;
+ len = min_t(unsigned int, remainder->bi_size>>9, max);
- remaining -= bv_len;
- len += bv_len;
- }
-
- clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len,
- ci->md->bs);
+ clone = bio_multi_split(bio, len, &remainder);
__map_bio(ti, clone, tio);
-
- ci->sector += len;
- ci->sector_count -= len;
- ci->idx = i;
-
- } else {
- /*
- * Handle a bvec that must be split between two or more targets.
- */
- struct bio_vec *bv = bio->bi_io_vec + ci->idx;
- sector_t remaining = to_sector(bv->bv_len);
- unsigned int offset = 0;
-
- do {
- if (offset) {
- ti = dm_table_find_target(ci->map, ci->sector);
- max = max_io_len(ci->md, ci->sector, ti);
-
- tio = alloc_tio(ci->md);
- tio->io = ci->io;
- tio->ti = ti;
- memset(&tio->info, 0, sizeof(tio->info));
- }
-
- len = min(remaining, max);
-
- clone = split_bvec(bio, ci->sector, ci->idx,
- bv->bv_offset + offset, len,
- ci->md->bs);
-
- __map_bio(ti, clone, tio);
-
- ci->sector += len;
- ci->sector_count -= len;
- offset += to_bytes(len);
- } while (remaining -= len);
-
- ci->idx++;
+ atomic_dec(&bio->bi_iocnt);
}
}
@@ -773,13 +650,10 @@ static void __split_bio(struct mapped_de
atomic_set(&ci.io->io_count, 1);
ci.io->bio = bio;
ci.io->md = md;
- ci.sector = bio->bi_sector;
- ci.sector_count = bio_sectors(bio);
- ci.idx = 0;
start_io_acct(ci.io);
- while (ci.sector_count)
- __clone_and_map(&ci);
+
+ __clone_and_map(&ci);
/* drop the extra reference count */
dec_pending(ci.io, 0);
next prev parent reply other threads:[~2007-07-31 2:31 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-31 2:15 [PATCH 000 of 35] Refactor block layer to improve support for stacked devices NeilBrown
2007-07-31 2:15 ` [PATCH 001 of 35] Replace bio_data with blk_rq_data NeilBrown
2007-07-31 2:15 ` [PATCH 002 of 35] Replace bio_cur_sectors with blk_rq_cur_sectors NeilBrown
2007-07-31 2:16 ` [PATCH 003 of 35] Introduce rq_for_each_segment replacing rq_for_each_bio NeilBrown
2007-07-31 2:16 ` [PATCH 004 of 35] Merge blk_recount_segments into blk_recalc_rq_segments NeilBrown
2007-07-31 2:16 ` [PATCH 005 of 35] Stop updating bi_idx, bv_len, bv_offset when a request completes NeilBrown
2007-08-01 14:54 ` Tejun Heo
2007-07-31 2:16 ` [PATCH 006 of 35] Only call bi_end_io once for any bio NeilBrown
2007-07-31 2:16 ` [PATCH 007 of 35] Drop 'size' argument from bio_endio and bi_end_io NeilBrown
2007-08-01 15:17 ` Tejun Heo
2007-07-31 2:16 ` [PATCH 008 of 35] Introduce bi_iocnt to count requests sharing the one bio NeilBrown
2007-08-01 15:49 ` Tejun Heo
2007-07-31 2:16 ` [PATCH 009 of 35] Remove overloading of bi_hw_segments in raid5 NeilBrown
2007-07-31 2:16 ` [PATCH 010 of 35] New function blk_req_append_bio NeilBrown
2007-08-01 15:54 ` Christoph Hellwig
2007-07-31 2:16 ` [PATCH 011 of 35] Stop exporting blk_rq_bio_prep NeilBrown
2007-07-31 2:16 ` [PATCH 012 of 35] Share code between init_request_from_bio and blk_rq_bio_prep NeilBrown
2007-07-31 2:16 ` [PATCH 013 of 35] Don't update bi_hw_*_size if we aren't going to merge NeilBrown
2007-08-01 15:57 ` Tejun Heo
2007-08-02 3:37 ` Neil Brown
2007-07-31 2:17 ` [PATCH 014 of 35] Change blk_phys/hw_contig_segment to take requests, not bios NeilBrown
2007-07-31 2:17 ` [PATCH 015 of 35] Move hw_front_size and hw_back_size from bio to request NeilBrown
2007-07-31 2:17 ` [PATCH 016 of 35] Centralise setting for REQ_NOMERGE NeilBrown
2007-07-31 2:17 ` [PATCH 017 of 35] Fix various abuse of bio fields in umem.c NeilBrown
2007-07-31 2:17 ` [PATCH 018 of 35] Remove bi_idx NeilBrown
2007-07-31 2:17 ` [PATCH 019 of 35] Convert bio_for_each_segment to fill in a fresh bio_vec NeilBrown
2007-08-01 16:21 ` Tejun Heo
2007-07-31 2:17 ` [PATCH 020 of 35] Add bi_offset and allow a bio to reference only part of a bi_io_vec NeilBrown
2007-07-31 2:17 ` [PATCH 021 of 35] Teach umem.c about bi_offset and to limit to bi_size NeilBrown
2007-07-31 2:17 ` [PATCH 022 of 35] Teach dm-crypt to honour bi_offset and bi_size NeilBrown
2007-07-31 2:17 ` [PATCH 023 of 35] Teach pktcdvd.c " NeilBrown
2007-07-31 2:17 ` [PATCH 024 of 35] Allow request bio list not to end with NULL NeilBrown
2007-07-31 2:17 ` [PATCH 025 of 35] Treat rq->hard_nr_sectors as setting an overriding limit in the size of the request NeilBrown
2007-08-01 17:44 ` Tejun Heo
2007-08-02 3:31 ` Neil Brown
2007-08-02 5:03 ` Tejun Heo
2007-07-31 2:18 ` [PATCH 026 of 35] Split any large bios that arrive at __make_request NeilBrown
2007-08-01 17:56 ` Tejun Heo
2007-08-02 0:49 ` Neil Brown
2007-08-02 2:59 ` Tejun Heo
2007-08-02 3:16 ` Neil Brown
2007-07-31 2:18 ` [PATCH 028 of 35] Split arbitrarily large requests to md/raid0 and md/linear NeilBrown
2007-07-31 2:18 ` [PATCH 029 of 35] Teach md/raid10 to split arbitrarily large bios NeilBrown
2007-07-31 2:18 ` [PATCH 030 of 35] Teach raid5 to split incoming bios NeilBrown
2007-07-31 2:18 ` [PATCH 031 of 35] Use bio_multi_split to fully split bios for pktcdvd NeilBrown
2007-07-31 2:18 ` [PATCH 032 of 35] Remove blk_queue_merge_bvec and bio_split and related code NeilBrown
2007-07-31 2:18 ` [PATCH 033 of 35] Simplify stacking of IO restrictions NeilBrown
2007-07-31 2:18 ` [PATCH 034 of 35] Simplify bio_add_page and raid1/raid10 resync which use it NeilBrown
2007-07-31 2:18 ` NeilBrown [this message]
2007-07-31 15:28 ` [PATCH 000 of 35] Refactor block layer to improve support for stacked devices Avi Kivity
2007-08-01 14:37 ` Tejun Heo
2007-08-01 15:52 ` John Stoffel
2007-08-01 15:59 ` Tejun Heo
2007-08-02 3:43 ` Neil Brown
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=1070731021852.25640@suse.de \
--to=neilb@suse.de \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.