提交 011067b0 编写于 作者: N NeilBrown 提交者: Jens Axboe

blk: replace bioset_create_nobvec() with a flags arg to bioset_create()

"flags" arguments are often seen as good API design as they allow
easy extensibility.
bioset_create_nobvec() is implemented internally as a variation in
flags passed to __bioset_create().

To support future extension, make the internal structure part of the
API.
i.e. add a 'flags' argument to bioset_create() and discard
bioset_create_nobvec().

Note that the bio_split allocations in drivers/md/raid* do not need
the bvec mempool - they should have used bioset_create_nobvec().
Suggested-by: NChristoph Hellwig <hch@infradead.org>
Reviewed-by: NChristoph Hellwig <hch@infradead.org>
Reviewed-by: NMing Lei <ming.lei@redhat.com>
Signed-off-by: NNeilBrown <neilb@suse.com>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
上级 af67c31f
...@@ -1921,9 +1921,26 @@ void bioset_free(struct bio_set *bs) ...@@ -1921,9 +1921,26 @@ void bioset_free(struct bio_set *bs)
} }
EXPORT_SYMBOL(bioset_free); EXPORT_SYMBOL(bioset_free);
static struct bio_set *__bioset_create(unsigned int pool_size, /**
unsigned int front_pad, * bioset_create - Create a bio_set
bool create_bvec_pool) * @pool_size: Number of bio and bio_vecs to cache in the mempool
* @front_pad: Number of bytes to allocate in front of the returned bio
* @flags: Flags to modify behavior, currently only %BIOSET_NEED_BVECS
*
* Description:
* Set up a bio_set to be used with @bio_alloc_bioset. Allows the caller
* to ask for a number of bytes to be allocated in front of the bio.
* Front pad allocation is useful for embedding the bio inside
* another structure, to avoid allocating extra data to go with the bio.
* Note that the bio must be embedded at the END of that structure always,
* or things will break badly.
* If %BIOSET_NEED_BVECS is set in @flags, a separate pool will be allocated
* for allocating iovecs. This pool is not needed e.g. for bio_clone_fast().
*
*/
struct bio_set *bioset_create(unsigned int pool_size,
unsigned int front_pad,
int flags)
{ {
unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec); unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec);
struct bio_set *bs; struct bio_set *bs;
...@@ -1948,7 +1965,7 @@ static struct bio_set *__bioset_create(unsigned int pool_size, ...@@ -1948,7 +1965,7 @@ static struct bio_set *__bioset_create(unsigned int pool_size,
if (!bs->bio_pool) if (!bs->bio_pool)
goto bad; goto bad;
if (create_bvec_pool) { if (flags & BIOSET_NEED_BVECS) {
bs->bvec_pool = biovec_create_pool(pool_size); bs->bvec_pool = biovec_create_pool(pool_size);
if (!bs->bvec_pool) if (!bs->bvec_pool)
goto bad; goto bad;
...@@ -1963,41 +1980,8 @@ static struct bio_set *__bioset_create(unsigned int pool_size, ...@@ -1963,41 +1980,8 @@ static struct bio_set *__bioset_create(unsigned int pool_size,
bioset_free(bs); bioset_free(bs);
return NULL; return NULL;
} }
/**
* bioset_create - Create a bio_set
* @pool_size: Number of bio and bio_vecs to cache in the mempool
* @front_pad: Number of bytes to allocate in front of the returned bio
*
* Description:
* Set up a bio_set to be used with @bio_alloc_bioset. Allows the caller
* to ask for a number of bytes to be allocated in front of the bio.
* Front pad allocation is useful for embedding the bio inside
* another structure, to avoid allocating extra data to go with the bio.
* Note that the bio must be embedded at the END of that structure always,
* or things will break badly.
*/
struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad)
{
return __bioset_create(pool_size, front_pad, true);
}
EXPORT_SYMBOL(bioset_create); EXPORT_SYMBOL(bioset_create);
/**
* bioset_create_nobvec - Create a bio_set without bio_vec mempool
* @pool_size: Number of bio to cache in the mempool
* @front_pad: Number of bytes to allocate in front of the returned bio
*
* Description:
* Same functionality as bioset_create() except that mempool is not
* created for bio_vecs. Saving some memory for bio_clone_fast() users.
*/
struct bio_set *bioset_create_nobvec(unsigned int pool_size, unsigned int front_pad)
{
return __bioset_create(pool_size, front_pad, false);
}
EXPORT_SYMBOL(bioset_create_nobvec);
#ifdef CONFIG_BLK_CGROUP #ifdef CONFIG_BLK_CGROUP
/** /**
...@@ -2112,7 +2096,7 @@ static int __init init_bio(void) ...@@ -2112,7 +2096,7 @@ static int __init init_bio(void)
bio_integrity_init(); bio_integrity_init();
biovec_init_slabs(); biovec_init_slabs();
fs_bio_set = bioset_create(BIO_POOL_SIZE, 0); fs_bio_set = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (!fs_bio_set) if (!fs_bio_set)
panic("bio: can't allocate bios\n"); panic("bio: can't allocate bios\n");
......
...@@ -790,7 +790,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id) ...@@ -790,7 +790,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
if (q->id < 0) if (q->id < 0)
goto fail_q; goto fail_q;
q->bio_split = bioset_create(BIO_POOL_SIZE, 0); q->bio_split = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (!q->bio_split) if (!q->bio_split)
goto fail_id; goto fail_id;
......
...@@ -2165,7 +2165,7 @@ static int drbd_create_mempools(void) ...@@ -2165,7 +2165,7 @@ static int drbd_create_mempools(void)
goto Enomem; goto Enomem;
/* mempools */ /* mempools */
drbd_md_io_bio_set = bioset_create(DRBD_MIN_POOL_PAGES, 0); drbd_md_io_bio_set = bioset_create(DRBD_MIN_POOL_PAGES, 0, BIOSET_NEED_BVECS);
if (drbd_md_io_bio_set == NULL) if (drbd_md_io_bio_set == NULL)
goto Enomem; goto Enomem;
......
...@@ -782,7 +782,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, ...@@ -782,7 +782,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
minor *= BCACHE_MINORS; minor *= BCACHE_MINORS;
if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio), BIOSET_NEED_BVECS)) ||
!(d->disk = alloc_disk(BCACHE_MINORS))) { !(d->disk = alloc_disk(BCACHE_MINORS))) {
ida_simple_remove(&bcache_minor, minor); ida_simple_remove(&bcache_minor, minor);
return -ENOMEM; return -ENOMEM;
...@@ -1516,7 +1516,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) ...@@ -1516,7 +1516,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
sizeof(struct bbio) + sizeof(struct bio_vec) * sizeof(struct bbio) + sizeof(struct bio_vec) *
bucket_pages(c))) || bucket_pages(c))) ||
!(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) || !(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) ||
!(c->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || !(c->bio_split = bioset_create(4, offsetof(struct bbio, bio), BIOSET_NEED_BVECS)) ||
!(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) || !(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) ||
!(c->moving_gc_wq = alloc_workqueue("bcache_gc", !(c->moving_gc_wq = alloc_workqueue("bcache_gc",
WQ_MEM_RECLAIM, 0)) || WQ_MEM_RECLAIM, 0)) ||
......
...@@ -2677,7 +2677,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -2677,7 +2677,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto bad; goto bad;
} }
cc->bs = bioset_create(MIN_IOS, 0); cc->bs = bioset_create(MIN_IOS, 0, BIOSET_NEED_BVECS);
if (!cc->bs) { if (!cc->bs) {
ti->error = "Cannot allocate crypt bioset"; ti->error = "Cannot allocate crypt bioset";
goto bad; goto bad;
......
...@@ -58,7 +58,7 @@ struct dm_io_client *dm_io_client_create(void) ...@@ -58,7 +58,7 @@ struct dm_io_client *dm_io_client_create(void)
if (!client->pool) if (!client->pool)
goto bad; goto bad;
client->bios = bioset_create(min_ios, 0); client->bios = bioset_create(min_ios, 0, BIOSET_NEED_BVECS);
if (!client->bios) if (!client->bios)
goto bad; goto bad;
......
...@@ -2660,7 +2660,7 @@ struct dm_md_mempools *dm_alloc_md_mempools(struct mapped_device *md, enum dm_qu ...@@ -2660,7 +2660,7 @@ struct dm_md_mempools *dm_alloc_md_mempools(struct mapped_device *md, enum dm_qu
BUG(); BUG();
} }
pools->bs = bioset_create_nobvec(pool_size, front_pad); pools->bs = bioset_create(pool_size, front_pad, 0);
if (!pools->bs) if (!pools->bs)
goto out; goto out;
......
...@@ -5428,7 +5428,7 @@ int md_run(struct mddev *mddev) ...@@ -5428,7 +5428,7 @@ int md_run(struct mddev *mddev)
} }
if (mddev->bio_set == NULL) { if (mddev->bio_set == NULL) {
mddev->bio_set = bioset_create(BIO_POOL_SIZE, 0); mddev->bio_set = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (!mddev->bio_set) if (!mddev->bio_set)
return -ENOMEM; return -ENOMEM;
} }
......
...@@ -2955,7 +2955,7 @@ static struct r1conf *setup_conf(struct mddev *mddev) ...@@ -2955,7 +2955,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
if (!conf->r1bio_pool) if (!conf->r1bio_pool)
goto abort; goto abort;
conf->bio_split = bioset_create(BIO_POOL_SIZE, 0); conf->bio_split = bioset_create(BIO_POOL_SIZE, 0, 0);
if (!conf->bio_split) if (!conf->bio_split)
goto abort; goto abort;
......
...@@ -3552,7 +3552,7 @@ static struct r10conf *setup_conf(struct mddev *mddev) ...@@ -3552,7 +3552,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
if (!conf->r10bio_pool) if (!conf->r10bio_pool)
goto out; goto out;
conf->bio_split = bioset_create(BIO_POOL_SIZE, 0); conf->bio_split = bioset_create(BIO_POOL_SIZE, 0, 0);
if (!conf->bio_split) if (!conf->bio_split)
goto out; goto out;
......
...@@ -3063,7 +3063,7 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev) ...@@ -3063,7 +3063,7 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
if (!log->io_pool) if (!log->io_pool)
goto io_pool; goto io_pool;
log->bs = bioset_create(R5L_POOL_SIZE, 0); log->bs = bioset_create(R5L_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (!log->bs) if (!log->bs)
goto io_bs; goto io_bs;
......
...@@ -1150,7 +1150,7 @@ int ppl_init_log(struct r5conf *conf) ...@@ -1150,7 +1150,7 @@ int ppl_init_log(struct r5conf *conf)
goto err; goto err;
} }
ppl_conf->bs = bioset_create(conf->raid_disks, 0); ppl_conf->bs = bioset_create(conf->raid_disks, 0, 0);
if (!ppl_conf->bs) { if (!ppl_conf->bs) {
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
......
...@@ -6943,7 +6943,7 @@ static struct r5conf *setup_conf(struct mddev *mddev) ...@@ -6943,7 +6943,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
goto abort; goto abort;
} }
conf->bio_split = bioset_create(BIO_POOL_SIZE, 0); conf->bio_split = bioset_create(BIO_POOL_SIZE, 0, 0);
if (!conf->bio_split) if (!conf->bio_split)
goto abort; goto abort;
conf->mddev = mddev; conf->mddev = mddev;
......
...@@ -93,7 +93,7 @@ static int iblock_configure_device(struct se_device *dev) ...@@ -93,7 +93,7 @@ static int iblock_configure_device(struct se_device *dev)
return -EINVAL; return -EINVAL;
} }
ib_dev->ibd_bio_set = bioset_create(IBLOCK_BIO_POOL_SIZE, 0); ib_dev->ibd_bio_set = bioset_create(IBLOCK_BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (!ib_dev->ibd_bio_set) { if (!ib_dev->ibd_bio_set) {
pr_err("IBLOCK: Unable to create bioset\n"); pr_err("IBLOCK: Unable to create bioset\n");
goto out; goto out;
......
...@@ -439,7 +439,7 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ...@@ -439,7 +439,7 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
static __init int blkdev_init(void) static __init int blkdev_init(void)
{ {
blkdev_dio_pool = bioset_create(4, offsetof(struct blkdev_dio, bio)); blkdev_dio_pool = bioset_create(4, offsetof(struct blkdev_dio, bio), BIOSET_NEED_BVECS);
if (!blkdev_dio_pool) if (!blkdev_dio_pool)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
......
...@@ -174,7 +174,8 @@ int __init extent_io_init(void) ...@@ -174,7 +174,8 @@ int __init extent_io_init(void)
goto free_state_cache; goto free_state_cache;
btrfs_bioset = bioset_create(BIO_POOL_SIZE, btrfs_bioset = bioset_create(BIO_POOL_SIZE,
offsetof(struct btrfs_io_bio, bio)); offsetof(struct btrfs_io_bio, bio),
BIOSET_NEED_BVECS);
if (!btrfs_bioset) if (!btrfs_bioset)
goto free_buffer_cache; goto free_buffer_cache;
......
...@@ -1766,7 +1766,8 @@ STATIC int __init ...@@ -1766,7 +1766,8 @@ STATIC int __init
xfs_init_zones(void) xfs_init_zones(void)
{ {
xfs_ioend_bioset = bioset_create(4 * MAX_BUF_PER_PAGE, xfs_ioend_bioset = bioset_create(4 * MAX_BUF_PER_PAGE,
offsetof(struct xfs_ioend, io_inline_bio)); offsetof(struct xfs_ioend, io_inline_bio),
BIOSET_NEED_BVECS);
if (!xfs_ioend_bioset) if (!xfs_ioend_bioset)
goto out; goto out;
......
...@@ -373,8 +373,10 @@ static inline struct bio *bio_next_split(struct bio *bio, int sectors, ...@@ -373,8 +373,10 @@ static inline struct bio *bio_next_split(struct bio *bio, int sectors,
return bio_split(bio, sectors, gfp, bs); return bio_split(bio, sectors, gfp, bs);
} }
extern struct bio_set *bioset_create(unsigned int, unsigned int); extern struct bio_set *bioset_create(unsigned int, unsigned int, int flags);
extern struct bio_set *bioset_create_nobvec(unsigned int, unsigned int); enum {
BIOSET_NEED_BVECS = BIT(0),
};
extern void bioset_free(struct bio_set *); extern void bioset_free(struct bio_set *);
extern mempool_t *biovec_create_pool(int pool_entries); extern mempool_t *biovec_create_pool(int pool_entries);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册