Skip to content

Commit 011067b

Browse files
NeilBrownaxboe
authored andcommitted
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: Christoph Hellwig <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Ming Lei <[email protected]> Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent af67c31 commit 011067b

File tree

18 files changed

+45
-57
lines changed

18 files changed

+45
-57
lines changed

block/bio.c

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,9 +1921,26 @@ void bioset_free(struct bio_set *bs)
19211921
}
19221922
EXPORT_SYMBOL(bioset_free);
19231923

1924-
static struct bio_set *__bioset_create(unsigned int pool_size,
1925-
unsigned int front_pad,
1926-
bool create_bvec_pool)
1924+
/**
1925+
* bioset_create - Create a bio_set
1926+
* @pool_size: Number of bio and bio_vecs to cache in the mempool
1927+
* @front_pad: Number of bytes to allocate in front of the returned bio
1928+
* @flags: Flags to modify behavior, currently only %BIOSET_NEED_BVECS
1929+
*
1930+
* Description:
1931+
* Set up a bio_set to be used with @bio_alloc_bioset. Allows the caller
1932+
* to ask for a number of bytes to be allocated in front of the bio.
1933+
* Front pad allocation is useful for embedding the bio inside
1934+
* another structure, to avoid allocating extra data to go with the bio.
1935+
* Note that the bio must be embedded at the END of that structure always,
1936+
* or things will break badly.
1937+
* If %BIOSET_NEED_BVECS is set in @flags, a separate pool will be allocated
1938+
* for allocating iovecs. This pool is not needed e.g. for bio_clone_fast().
1939+
*
1940+
*/
1941+
struct bio_set *bioset_create(unsigned int pool_size,
1942+
unsigned int front_pad,
1943+
int flags)
19271944
{
19281945
unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec);
19291946
struct bio_set *bs;
@@ -1948,7 +1965,7 @@ static struct bio_set *__bioset_create(unsigned int pool_size,
19481965
if (!bs->bio_pool)
19491966
goto bad;
19501967

1951-
if (create_bvec_pool) {
1968+
if (flags & BIOSET_NEED_BVECS) {
19521969
bs->bvec_pool = biovec_create_pool(pool_size);
19531970
if (!bs->bvec_pool)
19541971
goto bad;
@@ -1963,41 +1980,8 @@ static struct bio_set *__bioset_create(unsigned int pool_size,
19631980
bioset_free(bs);
19641981
return NULL;
19651982
}
1966-
1967-
/**
1968-
* bioset_create - Create a bio_set
1969-
* @pool_size: Number of bio and bio_vecs to cache in the mempool
1970-
* @front_pad: Number of bytes to allocate in front of the returned bio
1971-
*
1972-
* Description:
1973-
* Set up a bio_set to be used with @bio_alloc_bioset. Allows the caller
1974-
* to ask for a number of bytes to be allocated in front of the bio.
1975-
* Front pad allocation is useful for embedding the bio inside
1976-
* another structure, to avoid allocating extra data to go with the bio.
1977-
* Note that the bio must be embedded at the END of that structure always,
1978-
* or things will break badly.
1979-
*/
1980-
struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad)
1981-
{
1982-
return __bioset_create(pool_size, front_pad, true);
1983-
}
19841983
EXPORT_SYMBOL(bioset_create);
19851984

1986-
/**
1987-
* bioset_create_nobvec - Create a bio_set without bio_vec mempool
1988-
* @pool_size: Number of bio to cache in the mempool
1989-
* @front_pad: Number of bytes to allocate in front of the returned bio
1990-
*
1991-
* Description:
1992-
* Same functionality as bioset_create() except that mempool is not
1993-
* created for bio_vecs. Saving some memory for bio_clone_fast() users.
1994-
*/
1995-
struct bio_set *bioset_create_nobvec(unsigned int pool_size, unsigned int front_pad)
1996-
{
1997-
return __bioset_create(pool_size, front_pad, false);
1998-
}
1999-
EXPORT_SYMBOL(bioset_create_nobvec);
2000-
20011985
#ifdef CONFIG_BLK_CGROUP
20021986

20031987
/**
@@ -2112,7 +2096,7 @@ static int __init init_bio(void)
21122096
bio_integrity_init();
21132097
biovec_init_slabs();
21142098

2115-
fs_bio_set = bioset_create(BIO_POOL_SIZE, 0);
2099+
fs_bio_set = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
21162100
if (!fs_bio_set)
21172101
panic("bio: can't allocate bios\n");
21182102

block/blk-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
790790
if (q->id < 0)
791791
goto fail_q;
792792

793-
q->bio_split = bioset_create(BIO_POOL_SIZE, 0);
793+
q->bio_split = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
794794
if (!q->bio_split)
795795
goto fail_id;
796796

drivers/block/drbd/drbd_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ static int drbd_create_mempools(void)
21652165
goto Enomem;
21662166

21672167
/* mempools */
2168-
drbd_md_io_bio_set = bioset_create(DRBD_MIN_POOL_PAGES, 0);
2168+
drbd_md_io_bio_set = bioset_create(DRBD_MIN_POOL_PAGES, 0, BIOSET_NEED_BVECS);
21692169
if (drbd_md_io_bio_set == NULL)
21702170
goto Enomem;
21712171

drivers/md/bcache/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
782782

783783
minor *= BCACHE_MINORS;
784784

785-
if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) ||
785+
if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio), BIOSET_NEED_BVECS)) ||
786786
!(d->disk = alloc_disk(BCACHE_MINORS))) {
787787
ida_simple_remove(&bcache_minor, minor);
788788
return -ENOMEM;
@@ -1516,7 +1516,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
15161516
sizeof(struct bbio) + sizeof(struct bio_vec) *
15171517
bucket_pages(c))) ||
15181518
!(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) ||
1519-
!(c->bio_split = bioset_create(4, offsetof(struct bbio, bio))) ||
1519+
!(c->bio_split = bioset_create(4, offsetof(struct bbio, bio), BIOSET_NEED_BVECS)) ||
15201520
!(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) ||
15211521
!(c->moving_gc_wq = alloc_workqueue("bcache_gc",
15221522
WQ_MEM_RECLAIM, 0)) ||

drivers/md/dm-crypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
26772677
goto bad;
26782678
}
26792679

2680-
cc->bs = bioset_create(MIN_IOS, 0);
2680+
cc->bs = bioset_create(MIN_IOS, 0, BIOSET_NEED_BVECS);
26812681
if (!cc->bs) {
26822682
ti->error = "Cannot allocate crypt bioset";
26832683
goto bad;

drivers/md/dm-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct dm_io_client *dm_io_client_create(void)
5858
if (!client->pool)
5959
goto bad;
6060

61-
client->bios = bioset_create(min_ios, 0);
61+
client->bios = bioset_create(min_ios, 0, BIOSET_NEED_BVECS);
6262
if (!client->bios)
6363
goto bad;
6464

drivers/md/dm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ struct dm_md_mempools *dm_alloc_md_mempools(struct mapped_device *md, enum dm_qu
26602660
BUG();
26612661
}
26622662

2663-
pools->bs = bioset_create_nobvec(pool_size, front_pad);
2663+
pools->bs = bioset_create(pool_size, front_pad, 0);
26642664
if (!pools->bs)
26652665
goto out;
26662666

drivers/md/md.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5428,7 +5428,7 @@ int md_run(struct mddev *mddev)
54285428
}
54295429

54305430
if (mddev->bio_set == NULL) {
5431-
mddev->bio_set = bioset_create(BIO_POOL_SIZE, 0);
5431+
mddev->bio_set = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
54325432
if (!mddev->bio_set)
54335433
return -ENOMEM;
54345434
}

drivers/md/raid1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2955,7 +2955,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
29552955
if (!conf->r1bio_pool)
29562956
goto abort;
29572957

2958-
conf->bio_split = bioset_create(BIO_POOL_SIZE, 0);
2958+
conf->bio_split = bioset_create(BIO_POOL_SIZE, 0, 0);
29592959
if (!conf->bio_split)
29602960
goto abort;
29612961

drivers/md/raid10.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3552,7 +3552,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
35523552
if (!conf->r10bio_pool)
35533553
goto out;
35543554

3555-
conf->bio_split = bioset_create(BIO_POOL_SIZE, 0);
3555+
conf->bio_split = bioset_create(BIO_POOL_SIZE, 0, 0);
35563556
if (!conf->bio_split)
35573557
goto out;
35583558

0 commit comments

Comments
 (0)