Skip to content

Commit b54ffb7

Browse files
koverstreetaxboe
authored andcommitted
block: remove bio_get_nr_vecs()
We can always fill up the bio now, no need to estimate the possible size based on queue parameters. Acked-by: Steven Whitehouse <swhiteho@redhat.com> Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> [hch: rebased and wrote a changelog] Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ming Lin <ming.l@ssi.samsung.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 6cf66b4 commit b54ffb7

File tree

16 files changed

+18
-74
lines changed

16 files changed

+18
-74
lines changed

block/bio.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -693,29 +693,6 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,
693693
}
694694
EXPORT_SYMBOL(bio_clone_bioset);
695695

696-
/**
697-
* bio_get_nr_vecs - return approx number of vecs
698-
* @bdev: I/O target
699-
*
700-
* Return the approximate number of pages we can send to this target.
701-
* There's no guarantee that you will be able to fit this number of pages
702-
* into a bio, it does not account for dynamic restrictions that vary
703-
* on offset.
704-
*/
705-
int bio_get_nr_vecs(struct block_device *bdev)
706-
{
707-
struct request_queue *q = bdev_get_queue(bdev);
708-
int nr_pages;
709-
710-
nr_pages = min_t(unsigned,
711-
queue_max_segments(q),
712-
queue_max_sectors(q) / (PAGE_SIZE >> 9) + 1);
713-
714-
return min_t(unsigned, nr_pages, BIO_MAX_PAGES);
715-
716-
}
717-
EXPORT_SYMBOL(bio_get_nr_vecs);
718-
719696
/**
720697
* bio_add_pc_page - attempt to add page to bio
721698
* @q: the target queue

drivers/md/dm-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
316316
if ((rw & REQ_DISCARD) || (rw & REQ_WRITE_SAME))
317317
num_bvecs = 1;
318318
else
319-
num_bvecs = min_t(int, bio_get_nr_vecs(where->bdev),
319+
num_bvecs = min_t(int, BIO_MAX_PAGES,
320320
dm_sector_div_up(remaining, (PAGE_SIZE >> SECTOR_SHIFT)));
321321

322322
bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios);

fs/btrfs/compression.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ static inline int compressed_bio_size(struct btrfs_root *root,
9797
static struct bio *compressed_bio_alloc(struct block_device *bdev,
9898
u64 first_byte, gfp_t gfp_flags)
9999
{
100-
int nr_vecs;
101-
102-
nr_vecs = bio_get_nr_vecs(bdev);
103-
return btrfs_bio_alloc(bdev, first_byte >> 9, nr_vecs, gfp_flags);
100+
return btrfs_bio_alloc(bdev, first_byte >> 9, BIO_MAX_PAGES, gfp_flags);
104101
}
105102

106103
static int check_compressed_csum(struct inode *inode,

fs/btrfs/extent_io.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,9 +2795,7 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,
27952795
{
27962796
int ret = 0;
27972797
struct bio *bio;
2798-
int nr;
27992798
int contig = 0;
2800-
int this_compressed = bio_flags & EXTENT_BIO_COMPRESSED;
28012799
int old_compressed = prev_bio_flags & EXTENT_BIO_COMPRESSED;
28022800
size_t page_size = min_t(size_t, size, PAGE_CACHE_SIZE);
28032801

@@ -2822,12 +2820,9 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,
28222820
return 0;
28232821
}
28242822
}
2825-
if (this_compressed)
2826-
nr = BIO_MAX_PAGES;
2827-
else
2828-
nr = bio_get_nr_vecs(bdev);
28292823

2830-
bio = btrfs_bio_alloc(bdev, sector, nr, GFP_NOFS | __GFP_HIGH);
2824+
bio = btrfs_bio_alloc(bdev, sector, BIO_MAX_PAGES,
2825+
GFP_NOFS | __GFP_HIGH);
28312826
if (!bio)
28322827
return -ENOMEM;
28332828

fs/btrfs/inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7959,8 +7959,7 @@ static void btrfs_end_dio_bio(struct bio *bio)
79597959
static struct bio *btrfs_dio_bio_alloc(struct block_device *bdev,
79607960
u64 first_sector, gfp_t gfp_flags)
79617961
{
7962-
int nr_vecs = bio_get_nr_vecs(bdev);
7963-
return btrfs_bio_alloc(bdev, first_sector, nr_vecs, gfp_flags);
7962+
return btrfs_bio_alloc(bdev, first_sector, BIO_MAX_PAGES, gfp_flags);
79647963
}
79657964

79667965
static inline int btrfs_lookup_and_bind_dio_csum(struct btrfs_root *root,

fs/btrfs/scrub.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,27 +454,14 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
454454
struct scrub_ctx *sctx;
455455
int i;
456456
struct btrfs_fs_info *fs_info = dev->dev_root->fs_info;
457-
int pages_per_rd_bio;
458457
int ret;
459458

460-
/*
461-
* the setting of pages_per_rd_bio is correct for scrub but might
462-
* be wrong for the dev_replace code where we might read from
463-
* different devices in the initial huge bios. However, that
464-
* code is able to correctly handle the case when adding a page
465-
* to a bio fails.
466-
*/
467-
if (dev->bdev)
468-
pages_per_rd_bio = min_t(int, SCRUB_PAGES_PER_RD_BIO,
469-
bio_get_nr_vecs(dev->bdev));
470-
else
471-
pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
472459
sctx = kzalloc(sizeof(*sctx), GFP_NOFS);
473460
if (!sctx)
474461
goto nomem;
475462
atomic_set(&sctx->refs, 1);
476463
sctx->is_dev_replace = is_dev_replace;
477-
sctx->pages_per_rd_bio = pages_per_rd_bio;
464+
sctx->pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
478465
sctx->curr = -1;
479466
sctx->dev_root = dev->dev_root;
480467
for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
@@ -3896,8 +3883,7 @@ static int scrub_setup_wr_ctx(struct scrub_ctx *sctx,
38963883
return 0;
38973884

38983885
WARN_ON(!dev->bdev);
3899-
wr_ctx->pages_per_wr_bio = min_t(int, SCRUB_PAGES_PER_WR_BIO,
3900-
bio_get_nr_vecs(dev->bdev));
3886+
wr_ctx->pages_per_wr_bio = SCRUB_PAGES_PER_WR_BIO;
39013887
wr_ctx->tgtdev = dev;
39023888
atomic_set(&wr_ctx->flush_all_writes, 0);
39033889
return 0;

fs/direct-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ static inline int dio_new_bio(struct dio *dio, struct dio_submit *sdio,
655655
if (ret)
656656
goto out;
657657
sector = start_sector << (sdio->blkbits - 9);
658-
nr_pages = min(sdio->pages_in_io, bio_get_nr_vecs(map_bh->b_bdev));
658+
nr_pages = min(sdio->pages_in_io, BIO_MAX_PAGES);
659659
BUG_ON(nr_pages <= 0);
660660
dio_bio_alloc(dio, sdio, map_bh->b_bdev, sector, nr_pages);
661661
sdio->boundary = 0;

fs/ext4/page-io.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,9 @@ void ext4_io_submit_init(struct ext4_io_submit *io,
372372
static int io_submit_init_bio(struct ext4_io_submit *io,
373373
struct buffer_head *bh)
374374
{
375-
int nvecs = bio_get_nr_vecs(bh->b_bdev);
376375
struct bio *bio;
377376

378-
bio = bio_alloc(GFP_NOIO, min(nvecs, BIO_MAX_PAGES));
377+
bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
379378
if (!bio)
380379
return -ENOMEM;
381380
bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);

fs/ext4/readpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
284284
goto set_error_page;
285285
}
286286
bio = bio_alloc(GFP_KERNEL,
287-
min_t(int, nr_pages, bio_get_nr_vecs(bdev)));
287+
min_t(int, nr_pages, BIO_MAX_PAGES));
288288
if (!bio) {
289289
if (ctx)
290290
ext4_release_crypto_ctx(ctx);

fs/f2fs/data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
15521552
}
15531553

15541554
bio = bio_alloc(GFP_KERNEL,
1555-
min_t(int, nr_pages, bio_get_nr_vecs(bdev)));
1555+
min_t(int, nr_pages, BIO_MAX_PAGES));
15561556
if (!bio) {
15571557
if (ctx)
15581558
f2fs_release_crypto_ctx(ctx);

fs/gfs2/lops.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,11 @@ void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int rw)
261261
static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno)
262262
{
263263
struct super_block *sb = sdp->sd_vfs;
264-
unsigned nrvecs = bio_get_nr_vecs(sb->s_bdev);
265264
struct bio *bio;
266265

267266
BUG_ON(sdp->sd_log_bio);
268267

269-
while (1) {
270-
bio = bio_alloc(GFP_NOIO, nrvecs);
271-
if (likely(bio))
272-
break;
273-
nrvecs = max(nrvecs/2, 1U);
274-
}
275-
268+
bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
276269
bio->bi_iter.bi_sector = blkno * (sb->s_blocksize >> 9);
277270
bio->bi_bdev = sb->s_bdev;
278271
bio->bi_end_io = gfs2_end_log_write;

fs/logfs/dev_bdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int __bdev_writeseg(struct super_block *sb, u64 ofs, pgoff_t index,
8181
unsigned int max_pages;
8282
int i;
8383

84-
max_pages = min(nr_pages, (size_t) bio_get_nr_vecs(super->s_bdev));
84+
max_pages = min(nr_pages, BIO_MAX_PAGES);
8585

8686
bio = bio_alloc(GFP_NOFS, max_pages);
8787
BUG_ON(!bio);
@@ -171,7 +171,7 @@ static int do_erase(struct super_block *sb, u64 ofs, pgoff_t index,
171171
unsigned int max_pages;
172172
int i;
173173

174-
max_pages = min(nr_pages, (size_t) bio_get_nr_vecs(super->s_bdev));
174+
max_pages = min(nr_pages, BIO_MAX_PAGES);
175175

176176
bio = bio_alloc(GFP_NOFS, max_pages);
177177
BUG_ON(!bio);

fs/mpage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
277277
goto out;
278278
}
279279
bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
280-
min_t(int, nr_pages, bio_get_nr_vecs(bdev)),
280+
min_t(int, nr_pages, BIO_MAX_PAGES),
281281
GFP_KERNEL);
282282
if (bio == NULL)
283283
goto confused;
@@ -602,7 +602,7 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
602602
}
603603
}
604604
bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
605-
bio_get_nr_vecs(bdev), GFP_NOFS|__GFP_HIGH);
605+
BIO_MAX_PAGES, GFP_NOFS|__GFP_HIGH);
606606
if (bio == NULL)
607607
goto confused;
608608

fs/nilfs2/segbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ static void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf,
414414
{
415415
wi->bio = NULL;
416416
wi->rest_blocks = segbuf->sb_sum.nblocks;
417-
wi->max_pages = bio_get_nr_vecs(wi->nilfs->ns_bdev);
417+
wi->max_pages = BIO_MAX_PAGES;
418418
wi->nr_vecs = min(wi->max_pages, wi->rest_blocks);
419419
wi->start = wi->end = 0;
420420
wi->blocknr = segbuf->sb_pseg_start;

fs/xfs/xfs_aops.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ STATIC struct bio *
381381
xfs_alloc_ioend_bio(
382382
struct buffer_head *bh)
383383
{
384-
int nvecs = bio_get_nr_vecs(bh->b_bdev);
385-
struct bio *bio = bio_alloc(GFP_NOIO, nvecs);
384+
struct bio *bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
386385

387386
ASSERT(bio->bi_private == NULL);
388387
bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);

include/linux/bio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ void bio_chain(struct bio *, struct bio *);
460460
extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
461461
extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
462462
unsigned int, unsigned int);
463-
extern int bio_get_nr_vecs(struct block_device *);
464463
struct rq_map_data;
465464
extern struct bio *bio_map_user_iov(struct request_queue *,
466465
const struct iov_iter *, gfp_t);

0 commit comments

Comments
 (0)