Message ID | 59940825e958cf3e4cf99813febae57beb86ddaf.1610693037.git.naohiro.aota@wdc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: zoned block device support | expand |
On 1/15/21 1:53 AM, Naohiro Aota wrote: > This commit extract page adding to bio part from submit_extent_page(). The > page is added only when bio_flags are the same, contiguous and the added > page fits in the same stripe as pages in the bio. > > Condition checkings are reordered to allow early return to avoid possibly > heavy btrfs_bio_fits_in_stripe() calling. > > Reviewed-by: Josef Bacik <josef@toxicpanda.com> > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> > --- > fs/btrfs/extent_io.c | 57 ++++++++++++++++++++++++++++++++------------ > 1 file changed, 42 insertions(+), 15 deletions(-) > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > index 129d571a5c1a..96f43b9121d6 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -3061,6 +3061,45 @@ struct bio *btrfs_bio_clone_partial(struct bio *orig, int offset, int size) > return bio; > } > > +/** > + * btrfs_bio_add_page - attempt to add a page to bio > + * @bio: destination bio > + * @page: page to add to the bio > + * @logical: offset of the new bio or to check whether we are adding > + * a contiguous page to the previous one > + * @pg_offset: starting offset in the page > + * @size: portion of page that we want to write > + * @prev_bio_flags: flags of previous bio to see if we can merge the current one > + * @bio_flags: flags of the current bio to see if we can merge them > + * @return: true if page was added, false otherwise > + * > + * Attempt to add a page to bio considering stripe alignment etc. Return > + * true if successfully page added. Otherwise, return false. > + */ > +static bool btrfs_bio_add_page(struct bio *bio, struct page *page, u64 logical, > + unsigned int size, unsigned int pg_offset, > + unsigned long prev_bio_flags, > + unsigned long bio_flags) > +{ > + sector_t sector = logical >> SECTOR_SHIFT; > + bool contig; > + > + if (prev_bio_flags != bio_flags) > + return false; > + > + if (prev_bio_flags & EXTENT_BIO_COMPRESSED) > + contig = bio->bi_iter.bi_sector == sector; > + else > + contig = bio_end_sector(bio) == sector; > + if (!contig) > + return false; > + > + if (btrfs_bio_fits_in_stripe(page, size, bio, bio_flags)) > + return false; > + > + return bio_add_page(bio, page, size, pg_offset) == size; > +} > + > /* > * @opf: bio REQ_OP_* and REQ_* flags as one value > * @wbc: optional writeback control for io accounting > @@ -3089,27 +3128,15 @@ static int submit_extent_page(unsigned int opf, > int ret = 0; > struct bio *bio; > size_t io_size = min_t(size_t, size, PAGE_SIZE); > - sector_t sector = offset >> 9; offset has been renamed to disk_bytenr in misc-next, you'll need to refresh these patches against misc-next as this doesn't apply cleanly. Thanks, Josef
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 129d571a5c1a..96f43b9121d6 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3061,6 +3061,45 @@ struct bio *btrfs_bio_clone_partial(struct bio *orig, int offset, int size) return bio; } +/** + * btrfs_bio_add_page - attempt to add a page to bio + * @bio: destination bio + * @page: page to add to the bio + * @logical: offset of the new bio or to check whether we are adding + * a contiguous page to the previous one + * @pg_offset: starting offset in the page + * @size: portion of page that we want to write + * @prev_bio_flags: flags of previous bio to see if we can merge the current one + * @bio_flags: flags of the current bio to see if we can merge them + * @return: true if page was added, false otherwise + * + * Attempt to add a page to bio considering stripe alignment etc. Return + * true if successfully page added. Otherwise, return false. + */ +static bool btrfs_bio_add_page(struct bio *bio, struct page *page, u64 logical, + unsigned int size, unsigned int pg_offset, + unsigned long prev_bio_flags, + unsigned long bio_flags) +{ + sector_t sector = logical >> SECTOR_SHIFT; + bool contig; + + if (prev_bio_flags != bio_flags) + return false; + + if (prev_bio_flags & EXTENT_BIO_COMPRESSED) + contig = bio->bi_iter.bi_sector == sector; + else + contig = bio_end_sector(bio) == sector; + if (!contig) + return false; + + if (btrfs_bio_fits_in_stripe(page, size, bio, bio_flags)) + return false; + + return bio_add_page(bio, page, size, pg_offset) == size; +} + /* * @opf: bio REQ_OP_* and REQ_* flags as one value * @wbc: optional writeback control for io accounting @@ -3089,27 +3128,15 @@ static int submit_extent_page(unsigned int opf, int ret = 0; struct bio *bio; size_t io_size = min_t(size_t, size, PAGE_SIZE); - sector_t sector = offset >> 9; struct extent_io_tree *tree = &BTRFS_I(page->mapping->host)->io_tree; ASSERT(bio_ret); if (*bio_ret) { - bool contig; - bool can_merge = true; - bio = *bio_ret; - if (prev_bio_flags & EXTENT_BIO_COMPRESSED) - contig = bio->bi_iter.bi_sector == sector; - else - contig = bio_end_sector(bio) == sector; - - if (btrfs_bio_fits_in_stripe(page, io_size, bio, bio_flags)) - can_merge = false; - - if (prev_bio_flags != bio_flags || !contig || !can_merge || - force_bio_submit || - bio_add_page(bio, page, io_size, pg_offset) < io_size) { + if (force_bio_submit || + !btrfs_bio_add_page(bio, page, offset, io_size, pg_offset, + prev_bio_flags, bio_flags)) { ret = submit_one_bio(bio, mirror_num, prev_bio_flags); if (ret < 0) { *bio_ret = NULL;