Commit dba14160 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Alasdair G Kergon

dm: store dm_target_io in bio front_pad

Use the recently-added bio front_pad field to allocate struct dm_target_io.

Prior to this patch, dm_target_io was allocated from a mempool. For each
dm_target_io, there is exactly one bio allocated from a bioset.

This patch merges these two allocations into one allocation: we create a
bioset with front_pad equal to the size of dm_target_io so that every
bio allocated from the bioset has sizeof(struct dm_target_io) bytes
before it. We allocate a bio and use the bytes before the bio as
dm_target_io.

_tio_cache is removed and the tio_pool mempool is now only used for
request-based devices.

This idea was introduced by Kent Overstreet.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: tj@kernel.org
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Bill Pemberton <wfp5p@viridian.itc.virginia.edu>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 4f81a417
...@@ -71,6 +71,7 @@ struct dm_target_io { ...@@ -71,6 +71,7 @@ struct dm_target_io {
struct dm_io *io; struct dm_io *io;
struct dm_target *ti; struct dm_target *ti;
union map_info info; union map_info info;
struct bio clone;
}; };
/* /*
...@@ -214,7 +215,6 @@ struct dm_md_mempools { ...@@ -214,7 +215,6 @@ struct dm_md_mempools {
#define MIN_IOS 256 #define MIN_IOS 256
static struct kmem_cache *_io_cache; static struct kmem_cache *_io_cache;
static struct kmem_cache *_tio_cache;
static struct kmem_cache *_rq_tio_cache; static struct kmem_cache *_rq_tio_cache;
/* /*
...@@ -232,14 +232,9 @@ static int __init local_init(void) ...@@ -232,14 +232,9 @@ static int __init local_init(void)
if (!_io_cache) if (!_io_cache)
return r; return r;
/* allocate a slab for the target ios */
_tio_cache = KMEM_CACHE(dm_target_io, 0);
if (!_tio_cache)
goto out_free_io_cache;
_rq_tio_cache = KMEM_CACHE(dm_rq_target_io, 0); _rq_tio_cache = KMEM_CACHE(dm_rq_target_io, 0);
if (!_rq_tio_cache) if (!_rq_tio_cache)
goto out_free_tio_cache; goto out_free_io_cache;
_rq_bio_info_cache = KMEM_CACHE(dm_rq_clone_bio_info, 0); _rq_bio_info_cache = KMEM_CACHE(dm_rq_clone_bio_info, 0);
if (!_rq_bio_info_cache) if (!_rq_bio_info_cache)
...@@ -265,8 +260,6 @@ static int __init local_init(void) ...@@ -265,8 +260,6 @@ static int __init local_init(void)
kmem_cache_destroy(_rq_bio_info_cache); kmem_cache_destroy(_rq_bio_info_cache);
out_free_rq_tio_cache: out_free_rq_tio_cache:
kmem_cache_destroy(_rq_tio_cache); kmem_cache_destroy(_rq_tio_cache);
out_free_tio_cache:
kmem_cache_destroy(_tio_cache);
out_free_io_cache: out_free_io_cache:
kmem_cache_destroy(_io_cache); kmem_cache_destroy(_io_cache);
...@@ -277,7 +270,6 @@ static void local_exit(void) ...@@ -277,7 +270,6 @@ static void local_exit(void)
{ {
kmem_cache_destroy(_rq_bio_info_cache); kmem_cache_destroy(_rq_bio_info_cache);
kmem_cache_destroy(_rq_tio_cache); kmem_cache_destroy(_rq_tio_cache);
kmem_cache_destroy(_tio_cache);
kmem_cache_destroy(_io_cache); kmem_cache_destroy(_io_cache);
unregister_blkdev(_major, _name); unregister_blkdev(_major, _name);
dm_uevent_exit(); dm_uevent_exit();
...@@ -463,7 +455,7 @@ static void free_io(struct mapped_device *md, struct dm_io *io) ...@@ -463,7 +455,7 @@ static void free_io(struct mapped_device *md, struct dm_io *io)
static void free_tio(struct mapped_device *md, struct dm_target_io *tio) static void free_tio(struct mapped_device *md, struct dm_target_io *tio)
{ {
mempool_free(tio, md->tio_pool); bio_put(&tio->clone);
} }
static struct dm_rq_target_io *alloc_rq_tio(struct mapped_device *md, static struct dm_rq_target_io *alloc_rq_tio(struct mapped_device *md,
...@@ -682,7 +674,6 @@ static void clone_endio(struct bio *bio, int error) ...@@ -682,7 +674,6 @@ static void clone_endio(struct bio *bio, int error)
} }
free_tio(md, tio); free_tio(md, tio);
bio_put(bio);
dec_pending(io, error); dec_pending(io, error);
} }
...@@ -1002,12 +993,12 @@ int dm_set_target_max_io_len(struct dm_target *ti, sector_t len) ...@@ -1002,12 +993,12 @@ int dm_set_target_max_io_len(struct dm_target *ti, sector_t len)
} }
EXPORT_SYMBOL_GPL(dm_set_target_max_io_len); EXPORT_SYMBOL_GPL(dm_set_target_max_io_len);
static void __map_bio(struct dm_target *ti, struct bio *clone, static void __map_bio(struct dm_target *ti, struct dm_target_io *tio)
struct dm_target_io *tio)
{ {
int r; int r;
sector_t sector; sector_t sector;
struct mapped_device *md; struct mapped_device *md;
struct bio *clone = &tio->clone;
clone->bi_end_io = clone_endio; clone->bi_end_io = clone_endio;
clone->bi_private = tio; clone->bi_private = tio;
...@@ -1031,7 +1022,6 @@ static void __map_bio(struct dm_target *ti, struct bio *clone, ...@@ -1031,7 +1022,6 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
/* error the io and bail out, or requeue it if needed */ /* error the io and bail out, or requeue it if needed */
md = tio->io->md; md = tio->io->md;
dec_pending(tio->io, r); dec_pending(tio->io, r);
bio_put(clone);
free_tio(md, tio); free_tio(md, tio);
} else if (r) { } else if (r) {
DMWARN("unimplemented target map return value: %d", r); DMWARN("unimplemented target map return value: %d", r);
...@@ -1052,14 +1042,13 @@ struct clone_info { ...@@ -1052,14 +1042,13 @@ struct clone_info {
/* /*
* Creates a little bio that just does part of a bvec. * Creates a little bio that just does part of a bvec.
*/ */
static struct bio *split_bvec(struct bio *bio, sector_t sector, static void split_bvec(struct dm_target_io *tio, struct bio *bio,
unsigned short idx, unsigned int offset, sector_t sector, unsigned short idx, unsigned int offset,
unsigned int len, struct bio_set *bs) unsigned int len, struct bio_set *bs)
{ {
struct bio *clone; struct bio *clone = &tio->clone;
struct bio_vec *bv = bio->bi_io_vec + idx; struct bio_vec *bv = bio->bi_io_vec + idx;
clone = bio_alloc_bioset(GFP_NOIO, 1, bs);
*clone->bi_io_vec = *bv; *clone->bi_io_vec = *bv;
clone->bi_sector = sector; clone->bi_sector = sector;
...@@ -1076,20 +1065,18 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector, ...@@ -1076,20 +1065,18 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
bio_integrity_trim(clone, bio_integrity_trim(clone,
bio_sector_offset(bio, idx, offset), len); bio_sector_offset(bio, idx, offset), len);
} }
return clone;
} }
/* /*
* Creates a bio that consists of range of complete bvecs. * Creates a bio that consists of range of complete bvecs.
*/ */
static struct bio *clone_bio(struct bio *bio, sector_t sector, static void clone_bio(struct dm_target_io *tio, struct bio *bio,
unsigned short idx, unsigned short bv_count, sector_t sector, unsigned short idx,
unsigned int len, struct bio_set *bs) unsigned short bv_count, unsigned int len,
struct bio_set *bs)
{ {
struct bio *clone; struct bio *clone = &tio->clone;
clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs);
__bio_clone(clone, bio); __bio_clone(clone, bio);
clone->bi_sector = sector; clone->bi_sector = sector;
clone->bi_idx = idx; clone->bi_idx = idx;
...@@ -1104,14 +1091,16 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector, ...@@ -1104,14 +1091,16 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector,
bio_integrity_trim(clone, bio_integrity_trim(clone,
bio_sector_offset(bio, idx, 0), len); bio_sector_offset(bio, idx, 0), len);
} }
return clone;
} }
static struct dm_target_io *alloc_tio(struct clone_info *ci, static struct dm_target_io *alloc_tio(struct clone_info *ci,
struct dm_target *ti) struct dm_target *ti, int nr_iovecs)
{ {
struct dm_target_io *tio = mempool_alloc(ci->md->tio_pool, GFP_NOIO); struct dm_target_io *tio;
struct bio *clone;
clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, ci->md->bs);
tio = container_of(clone, struct dm_target_io, clone);
tio->io = ci->io; tio->io = ci->io;
tio->ti = ti; tio->ti = ti;
...@@ -1123,8 +1112,8 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci, ...@@ -1123,8 +1112,8 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci,
static void __issue_target_request(struct clone_info *ci, struct dm_target *ti, static void __issue_target_request(struct clone_info *ci, struct dm_target *ti,
unsigned request_nr, sector_t len) unsigned request_nr, sector_t len)
{ {
struct dm_target_io *tio = alloc_tio(ci, ti); struct dm_target_io *tio = alloc_tio(ci, ti, ci->bio->bi_max_vecs);
struct bio *clone; struct bio *clone = &tio->clone;
tio->info.target_request_nr = request_nr; tio->info.target_request_nr = request_nr;
...@@ -1133,14 +1122,14 @@ static void __issue_target_request(struct clone_info *ci, struct dm_target *ti, ...@@ -1133,14 +1122,14 @@ static void __issue_target_request(struct clone_info *ci, struct dm_target *ti,
* ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush
* and discard, so no need for concern about wasted bvec allocations. * and discard, so no need for concern about wasted bvec allocations.
*/ */
clone = bio_clone_bioset(ci->bio, GFP_NOIO, ci->md->bs);
__bio_clone(clone, ci->bio);
if (len) { if (len) {
clone->bi_sector = ci->sector; clone->bi_sector = ci->sector;
clone->bi_size = to_bytes(len); clone->bi_size = to_bytes(len);
} }
__map_bio(ti, clone, tio); __map_bio(ti, tio);
} }
static void __issue_target_requests(struct clone_info *ci, struct dm_target *ti, static void __issue_target_requests(struct clone_info *ci, struct dm_target *ti,
...@@ -1169,14 +1158,13 @@ static int __clone_and_map_empty_flush(struct clone_info *ci) ...@@ -1169,14 +1158,13 @@ static int __clone_and_map_empty_flush(struct clone_info *ci)
*/ */
static void __clone_and_map_simple(struct clone_info *ci, struct dm_target *ti) static void __clone_and_map_simple(struct clone_info *ci, struct dm_target *ti)
{ {
struct bio *clone, *bio = ci->bio; struct bio *bio = ci->bio;
struct dm_target_io *tio; struct dm_target_io *tio;
tio = alloc_tio(ci, ti); tio = alloc_tio(ci, ti, bio->bi_max_vecs);
clone = clone_bio(bio, ci->sector, ci->idx, clone_bio(tio, bio, ci->sector, ci->idx, bio->bi_vcnt - ci->idx,
bio->bi_vcnt - ci->idx, ci->sector_count, ci->sector_count, ci->md->bs);
ci->md->bs); __map_bio(ti, tio);
__map_bio(ti, clone, tio);
ci->sector_count = 0; ci->sector_count = 0;
} }
...@@ -1214,7 +1202,7 @@ static int __clone_and_map_discard(struct clone_info *ci) ...@@ -1214,7 +1202,7 @@ static int __clone_and_map_discard(struct clone_info *ci)
static int __clone_and_map(struct clone_info *ci) static int __clone_and_map(struct clone_info *ci)
{ {
struct bio *clone, *bio = ci->bio; struct bio *bio = ci->bio;
struct dm_target *ti; struct dm_target *ti;
sector_t len = 0, max; sector_t len = 0, max;
struct dm_target_io *tio; struct dm_target_io *tio;
...@@ -1254,10 +1242,10 @@ static int __clone_and_map(struct clone_info *ci) ...@@ -1254,10 +1242,10 @@ static int __clone_and_map(struct clone_info *ci)
len += bv_len; len += bv_len;
} }
tio = alloc_tio(ci, ti); tio = alloc_tio(ci, ti, bio->bi_max_vecs);
clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len, clone_bio(tio, bio, ci->sector, ci->idx, i - ci->idx, len,
ci->md->bs); ci->md->bs);
__map_bio(ti, clone, tio); __map_bio(ti, tio);
ci->sector += len; ci->sector += len;
ci->sector_count -= len; ci->sector_count -= len;
...@@ -1282,12 +1270,11 @@ static int __clone_and_map(struct clone_info *ci) ...@@ -1282,12 +1270,11 @@ static int __clone_and_map(struct clone_info *ci)
len = min(remaining, max); len = min(remaining, max);
tio = alloc_tio(ci, ti); tio = alloc_tio(ci, ti, 1);
clone = split_bvec(bio, ci->sector, ci->idx, split_bvec(tio, bio, ci->sector, ci->idx,
bv->bv_offset + offset, len, bv->bv_offset + offset, len, ci->md->bs);
ci->md->bs);
__map_bio(ti, clone, tio); __map_bio(ti, tio);
ci->sector += len; ci->sector += len;
ci->sector_count -= len; ci->sector_count -= len;
...@@ -1955,7 +1942,7 @@ static void __bind_mempools(struct mapped_device *md, struct dm_table *t) ...@@ -1955,7 +1942,7 @@ static void __bind_mempools(struct mapped_device *md, struct dm_table *t)
{ {
struct dm_md_mempools *p; struct dm_md_mempools *p;
if (md->io_pool && md->tio_pool && md->bs) if (md->io_pool && (md->tio_pool || dm_table_get_type(t) == DM_TYPE_BIO_BASED) && md->bs)
/* the md already has necessary mempools */ /* the md already has necessary mempools */
goto out; goto out;
...@@ -2732,14 +2719,16 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity) ...@@ -2732,14 +2719,16 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity)
if (!pools->io_pool) if (!pools->io_pool)
goto free_pools_and_out; goto free_pools_and_out;
pools->tio_pool = (type == DM_TYPE_BIO_BASED) ? pools->tio_pool = NULL;
mempool_create_slab_pool(MIN_IOS, _tio_cache) : if (type == DM_TYPE_REQUEST_BASED) {
mempool_create_slab_pool(MIN_IOS, _rq_tio_cache); pools->tio_pool = mempool_create_slab_pool(MIN_IOS, _rq_tio_cache);
if (!pools->tio_pool) if (!pools->tio_pool)
goto free_io_pool_and_out; goto free_io_pool_and_out;
}
pools->bs = (type == DM_TYPE_BIO_BASED) ? pools->bs = (type == DM_TYPE_BIO_BASED) ?
bioset_create(pool_size, 0) : bioset_create(pool_size,
offsetof(struct dm_target_io, clone)) :
bioset_create(pool_size, bioset_create(pool_size,
offsetof(struct dm_rq_clone_bio_info, clone)); offsetof(struct dm_rq_clone_bio_info, clone));
if (!pools->bs) if (!pools->bs)
...@@ -2754,7 +2743,8 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity) ...@@ -2754,7 +2743,8 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity)
bioset_free(pools->bs); bioset_free(pools->bs);
free_tio_pool_and_out: free_tio_pool_and_out:
mempool_destroy(pools->tio_pool); if (pools->tio_pool)
mempool_destroy(pools->tio_pool);
free_io_pool_and_out: free_io_pool_and_out:
mempool_destroy(pools->io_pool); mempool_destroy(pools->io_pool);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment