aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2015-05-19 08:31:01 -0400
committerJens Axboe <axboe@fb.com>2015-08-13 14:32:04 -0400
commitb54ffb73cadcdcff9cc1ae0e11f502407e3e2e4c (patch)
tree8a6d90b3e092e598fefd34718afd2198d8bff2a7
parent6cf66b4caf9c71f64a5486cadbd71ab58d0d4307 (diff)
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>
-rw-r--r--block/bio.c23
-rw-r--r--drivers/md/dm-io.c2
-rw-r--r--fs/btrfs/compression.c5
-rw-r--r--fs/btrfs/extent_io.c9
-rw-r--r--fs/btrfs/inode.c3
-rw-r--r--fs/btrfs/scrub.c18
-rw-r--r--fs/direct-io.c2
-rw-r--r--fs/ext4/page-io.c3
-rw-r--r--fs/ext4/readpage.c2
-rw-r--r--fs/f2fs/data.c2
-rw-r--r--fs/gfs2/lops.c9
-rw-r--r--fs/logfs/dev_bdev.c4
-rw-r--r--fs/mpage.c4
-rw-r--r--fs/nilfs2/segbuf.c2
-rw-r--r--fs/xfs/xfs_aops.c3
-rw-r--r--include/linux/bio.h1
16 files changed, 18 insertions, 74 deletions
diff --git a/block/bio.c b/block/bio.c
index ba9c4b0c0ff2..425d6d4a2f7a 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -694,29 +694,6 @@ integrity_clone:
694EXPORT_SYMBOL(bio_clone_bioset); 694EXPORT_SYMBOL(bio_clone_bioset);
695 695
696/** 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 */
705int 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}
717EXPORT_SYMBOL(bio_get_nr_vecs);
718
719/**
720 * bio_add_pc_page - attempt to add page to bio 697 * bio_add_pc_page - attempt to add page to bio
721 * @q: the target queue 698 * @q: the target queue
722 * @bio: destination bio 699 * @bio: destination bio
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index c84714f70378..6f8e83b2a6f8 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -316,7 +316,7 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
316 if ((rw & REQ_DISCARD) || (rw & REQ_WRITE_SAME)) 316 if ((rw & REQ_DISCARD) || (rw & REQ_WRITE_SAME))
317 num_bvecs = 1; 317 num_bvecs = 1;
318 else 318 else
319 num_bvecs = min_t(int, bio_get_nr_vecs(where->bdev), 319 num_bvecs = min_t(int, BIO_MAX_PAGES,
320 dm_sector_div_up(remaining, (PAGE_SIZE >> SECTOR_SHIFT))); 320 dm_sector_div_up(remaining, (PAGE_SIZE >> SECTOR_SHIFT)));
321 321
322 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios); 322 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios);
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 302266ec2cdb..57ee8ca29b06 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -97,10 +97,7 @@ static inline int compressed_bio_size(struct btrfs_root *root,
97static struct bio *compressed_bio_alloc(struct block_device *bdev, 97static struct bio *compressed_bio_alloc(struct block_device *bdev,
98 u64 first_byte, gfp_t gfp_flags) 98 u64 first_byte, gfp_t gfp_flags)
99{ 99{
100 int nr_vecs; 100 return btrfs_bio_alloc(bdev, first_byte >> 9, BIO_MAX_PAGES, gfp_flags);
101
102 nr_vecs = bio_get_nr_vecs(bdev);
103 return btrfs_bio_alloc(bdev, first_byte >> 9, nr_vecs, gfp_flags);
104} 101}
105 102
106static int check_compressed_csum(struct inode *inode, 103static int check_compressed_csum(struct inode *inode,
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index c22f175ed024..68b12bbc709f 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2795,9 +2795,7 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,
2795{ 2795{
2796 int ret = 0; 2796 int ret = 0;
2797 struct bio *bio; 2797 struct bio *bio;
2798 int nr;
2799 int contig = 0; 2798 int contig = 0;
2800 int this_compressed = bio_flags & EXTENT_BIO_COMPRESSED;
2801 int old_compressed = prev_bio_flags & EXTENT_BIO_COMPRESSED; 2799 int old_compressed = prev_bio_flags & EXTENT_BIO_COMPRESSED;
2802 size_t page_size = min_t(size_t, size, PAGE_CACHE_SIZE); 2800 size_t page_size = min_t(size_t, size, PAGE_CACHE_SIZE);
2803 2801
@@ -2822,12 +2820,9 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,
2822 return 0; 2820 return 0;
2823 } 2821 }
2824 } 2822 }
2825 if (this_compressed)
2826 nr = BIO_MAX_PAGES;
2827 else
2828 nr = bio_get_nr_vecs(bdev);
2829 2823
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);
2831 if (!bio) 2826 if (!bio)
2832 return -ENOMEM; 2827 return -ENOMEM;
2833 2828
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 6b8becfe2057..8635ef01a04a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7959,8 +7959,7 @@ out:
7959static struct bio *btrfs_dio_bio_alloc(struct block_device *bdev, 7959static struct bio *btrfs_dio_bio_alloc(struct block_device *bdev,
7960 u64 first_sector, gfp_t gfp_flags) 7960 u64 first_sector, gfp_t gfp_flags)
7961{ 7961{
7962 int nr_vecs = bio_get_nr_vecs(bdev); 7962 return btrfs_bio_alloc(bdev, first_sector, BIO_MAX_PAGES, gfp_flags);
7963 return btrfs_bio_alloc(bdev, first_sector, nr_vecs, gfp_flags);
7964} 7963}
7965 7964
7966static inline int btrfs_lookup_and_bind_dio_csum(struct btrfs_root *root, 7965static inline int btrfs_lookup_and_bind_dio_csum(struct btrfs_root *root,
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index ebb8260186fe..9c146d8307b5 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -454,27 +454,14 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
454 struct scrub_ctx *sctx; 454 struct scrub_ctx *sctx;
455 int i; 455 int i;
456 struct btrfs_fs_info *fs_info = dev->dev_root->fs_info; 456 struct btrfs_fs_info *fs_info = dev->dev_root->fs_info;
457 int pages_per_rd_bio;
458 int ret; 457 int ret;
459 458
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;
472 sctx = kzalloc(sizeof(*sctx), GFP_NOFS); 459 sctx = kzalloc(sizeof(*sctx), GFP_NOFS);
473 if (!sctx) 460 if (!sctx)
474 goto nomem; 461 goto nomem;
475 atomic_set(&sctx->refs, 1); 462 atomic_set(&sctx->refs, 1);
476 sctx->is_dev_replace = is_dev_replace; 463 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;
478 sctx->curr = -1; 465 sctx->curr = -1;
479 sctx->dev_root = dev->dev_root; 466 sctx->dev_root = dev->dev_root;
480 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) { 467 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
@@ -3896,8 +3883,7 @@ static int scrub_setup_wr_ctx(struct scrub_ctx *sctx,
3896 return 0; 3883 return 0;
3897 3884
3898 WARN_ON(!dev->bdev); 3885 WARN_ON(!dev->bdev);
3899 wr_ctx->pages_per_wr_bio = min_t(int, SCRUB_PAGES_PER_WR_BIO, 3886 wr_ctx->pages_per_wr_bio = SCRUB_PAGES_PER_WR_BIO;
3900 bio_get_nr_vecs(dev->bdev));
3901 wr_ctx->tgtdev = dev; 3887 wr_ctx->tgtdev = dev;
3902 atomic_set(&wr_ctx->flush_all_writes, 0); 3888 atomic_set(&wr_ctx->flush_all_writes, 0);
3903 return 0; 3889 return 0;
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 818c647f36d3..11256291642e 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -655,7 +655,7 @@ static inline int dio_new_bio(struct dio *dio, struct dio_submit *sdio,
655 if (ret) 655 if (ret)
656 goto out; 656 goto out;
657 sector = start_sector << (sdio->blkbits - 9); 657 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);
659 BUG_ON(nr_pages <= 0); 659 BUG_ON(nr_pages <= 0);
660 dio_bio_alloc(dio, sdio, map_bh->b_bdev, sector, nr_pages); 660 dio_bio_alloc(dio, sdio, map_bh->b_bdev, sector, nr_pages);
661 sdio->boundary = 0; 661 sdio->boundary = 0;
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index aa95566f14be..8a9d63a0c071 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -372,10 +372,9 @@ void ext4_io_submit_init(struct ext4_io_submit *io,
372static int io_submit_init_bio(struct ext4_io_submit *io, 372static int io_submit_init_bio(struct ext4_io_submit *io,
373 struct buffer_head *bh) 373 struct buffer_head *bh)
374{ 374{
375 int nvecs = bio_get_nr_vecs(bh->b_bdev);
376 struct bio *bio; 375 struct bio *bio;
377 376
378 bio = bio_alloc(GFP_NOIO, min(nvecs, BIO_MAX_PAGES)); 377 bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
379 if (!bio) 378 if (!bio)
380 return -ENOMEM; 379 return -ENOMEM;
381 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); 380 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
index 5de5b871c178..e26803fb210d 100644
--- a/fs/ext4/readpage.c
+++ b/fs/ext4/readpage.c
@@ -284,7 +284,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
284 goto set_error_page; 284 goto set_error_page;
285 } 285 }
286 bio = bio_alloc(GFP_KERNEL, 286 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));
288 if (!bio) { 288 if (!bio) {
289 if (ctx) 289 if (ctx)
290 ext4_release_crypto_ctx(ctx); 290 ext4_release_crypto_ctx(ctx);
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 8f0baa7ffb50..b478accb24d9 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1552,7 +1552,7 @@ submit_and_realloc:
1552 } 1552 }
1553 1553
1554 bio = bio_alloc(GFP_KERNEL, 1554 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));
1556 if (!bio) { 1556 if (!bio) {
1557 if (ctx) 1557 if (ctx)
1558 f2fs_release_crypto_ctx(ctx); 1558 f2fs_release_crypto_ctx(ctx);
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index c0a1b967deba..92324ac58290 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -261,18 +261,11 @@ void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int rw)
261static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno) 261static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno)
262{ 262{
263 struct super_block *sb = sdp->sd_vfs; 263 struct super_block *sb = sdp->sd_vfs;
264 unsigned nrvecs = bio_get_nr_vecs(sb->s_bdev);
265 struct bio *bio; 264 struct bio *bio;
266 265
267 BUG_ON(sdp->sd_log_bio); 266 BUG_ON(sdp->sd_log_bio);
268 267
269 while (1) { 268 bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
270 bio = bio_alloc(GFP_NOIO, nrvecs);
271 if (likely(bio))
272 break;
273 nrvecs = max(nrvecs/2, 1U);
274 }
275
276 bio->bi_iter.bi_sector = blkno * (sb->s_blocksize >> 9); 269 bio->bi_iter.bi_sector = blkno * (sb->s_blocksize >> 9);
277 bio->bi_bdev = sb->s_bdev; 270 bio->bi_bdev = sb->s_bdev;
278 bio->bi_end_io = gfs2_end_log_write; 271 bio->bi_end_io = gfs2_end_log_write;
diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index cea0cc9878b7..a7fdbd868474 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -81,7 +81,7 @@ static int __bdev_writeseg(struct super_block *sb, u64 ofs, pgoff_t index,
81 unsigned int max_pages; 81 unsigned int max_pages;
82 int i; 82 int i;
83 83
84 max_pages = min(nr_pages, (size_t) bio_get_nr_vecs(super->s_bdev)); 84 max_pages = min(nr_pages, BIO_MAX_PAGES);
85 85
86 bio = bio_alloc(GFP_NOFS, max_pages); 86 bio = bio_alloc(GFP_NOFS, max_pages);
87 BUG_ON(!bio); 87 BUG_ON(!bio);
@@ -171,7 +171,7 @@ static int do_erase(struct super_block *sb, u64 ofs, pgoff_t index,
171 unsigned int max_pages; 171 unsigned int max_pages;
172 int i; 172 int i;
173 173
174 max_pages = min(nr_pages, (size_t) bio_get_nr_vecs(super->s_bdev)); 174 max_pages = min(nr_pages, BIO_MAX_PAGES);
175 175
176 bio = bio_alloc(GFP_NOFS, max_pages); 176 bio = bio_alloc(GFP_NOFS, max_pages);
177 BUG_ON(!bio); 177 BUG_ON(!bio);
diff --git a/fs/mpage.c b/fs/mpage.c
index abac9361b3f1..778a4ddef77a 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -277,7 +277,7 @@ alloc_new:
277 goto out; 277 goto out;
278 } 278 }
279 bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9), 279 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),
281 GFP_KERNEL); 281 GFP_KERNEL);
282 if (bio == NULL) 282 if (bio == NULL)
283 goto confused; 283 goto confused;
@@ -602,7 +602,7 @@ alloc_new:
602 } 602 }
603 } 603 }
604 bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9), 604 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);
606 if (bio == NULL) 606 if (bio == NULL)
607 goto confused; 607 goto confused;
608 608
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index 550b10efb14e..f63620ce3892 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -414,7 +414,7 @@ static void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf,
414{ 414{
415 wi->bio = NULL; 415 wi->bio = NULL;
416 wi->rest_blocks = segbuf->sb_sum.nblocks; 416 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;
418 wi->nr_vecs = min(wi->max_pages, wi->rest_blocks); 418 wi->nr_vecs = min(wi->max_pages, wi->rest_blocks);
419 wi->start = wi->end = 0; 419 wi->start = wi->end = 0;
420 wi->blocknr = segbuf->sb_pseg_start; 420 wi->blocknr = segbuf->sb_pseg_start;
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 3714844a81d8..c77499bcbd7a 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -381,8 +381,7 @@ STATIC struct bio *
381xfs_alloc_ioend_bio( 381xfs_alloc_ioend_bio(
382 struct buffer_head *bh) 382 struct buffer_head *bh)
383{ 383{
384 int nvecs = bio_get_nr_vecs(bh->b_bdev); 384 struct bio *bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
385 struct bio *bio = bio_alloc(GFP_NOIO, nvecs);
386 385
387 ASSERT(bio->bi_private == NULL); 386 ASSERT(bio->bi_private == NULL);
388 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); 387 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index b7892a1906bd..ad7217458812 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -460,7 +460,6 @@ void bio_chain(struct bio *, struct bio *);
460extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int); 460extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
461extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *, 461extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
462 unsigned int, unsigned int); 462 unsigned int, unsigned int);
463extern int bio_get_nr_vecs(struct block_device *);
464struct rq_map_data; 463struct rq_map_data;
465extern struct bio *bio_map_user_iov(struct request_queue *, 464extern struct bio *bio_map_user_iov(struct request_queue *,
466 const struct iov_iter *, gfp_t); 465 const struct iov_iter *, gfp_t);