Commit 390ed29b authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: refactor submit_extent_page() to make bio and its flag tracing easier

There is a lot of code inside extent_io.c needs both "struct bio
**bio_ret" and "unsigned long prev_bio_flags", along with some
parameters like "unsigned long bio_flags".

Such strange parameters are here for bio assembly.

For example, we have such inode page layout:

  0       4K      8K      12K
  |<-- Extent A-->|<- EB->|

Then what we do is:

- Page [0, 4K)
  *bio_ret = NULL
  So we allocate a new bio to bio_ret,
  Add page [0, 4K) to *bio_ret.

- Page [4K, 8K)
  *bio_ret != NULL
  We found this page is continuous to *bio_ret,
  and if we're not at stripe boundary, we
  add page [4K, 8K) to *bio_ret.

- Page [8K, 12K)
  *bio_ret != NULL
  But we found this page is not continuous, so
  we submit *bio_ret, then allocate a new bio,
  and add page [8K, 12K) to the new bio.

This means we need to record both the bio and its bio_flag, but we
record them manually using those strange parameter list, other than
encapsulating them into their own structure.

So this patch will introduce a new structure, btrfs_bio_ctrl, to record
both the bio, and its bio_flags.

Also, in above case, for all pages added to the bio, we need to check if
the new page crosses stripe boundary.  This check itself can be time
consuming, and we don't really need to do that for each page.

This patch also integrates the stripe boundary check into btrfs_bio_ctrl.
When a new bio is allocated, the stripe and ordered extent boundary is
also calculated, so no matter how large the bio will be, we only
calculate the boundaries once, to save some CPU time.

The following functions/structures are affected:

- struct extent_page_data
  Replace its bio pointer with structure btrfs_bio_ctrl (embedded
  structure, not pointer)

- end_write_bio()
- flush_write_bio()
  Just change how bio is fetched

- btrfs_bio_add_page()
  Use pre-calculated boundaries instead of re-calculating them.
  And use @bio_ctrl to replace @bio and @prev_bio_flags.

- calc_bio_boundaries()
  New function

- submit_extent_page() callers
- btrfs_do_readpage() callers
- contiguous_readpages() callers
  To Use @bio_ctrl to replace @bio and @prev_bio_flags, and how to grab
  bio.

- btrfs_bio_fits_in_ordered_extent()
  Removed, as now the ordered extent size limit is done at bio
  allocation time, no need to check for each page range.
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 1a0b5c4d
...@@ -3157,8 +3157,6 @@ void btrfs_split_delalloc_extent(struct inode *inode, ...@@ -3157,8 +3157,6 @@ void btrfs_split_delalloc_extent(struct inode *inode,
struct extent_state *orig, u64 split); struct extent_state *orig, u64 split);
int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio, int btrfs_bio_fits_in_stripe(struct page *page, size_t size, struct bio *bio,
unsigned long bio_flags); unsigned long bio_flags);
bool btrfs_bio_fits_in_ordered_extent(struct page *page, struct bio *bio,
unsigned int size);
void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end); void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end);
vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf); vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf);
int btrfs_readpage(struct file *file, struct page *page); int btrfs_readpage(struct file *file, struct page *page);
......
This diff is collapsed.
...@@ -101,6 +101,17 @@ struct extent_buffer { ...@@ -101,6 +101,17 @@ struct extent_buffer {
#endif #endif
}; };
/*
* Structure to record info about the bio being assembled, and other info like
* how many bytes are there before stripe/ordered extent boundary.
*/
struct btrfs_bio_ctrl {
struct bio *bio;
unsigned long bio_flags;
u32 len_to_stripe_boundary;
u32 len_to_oe_boundary;
};
/* /*
* Structure to record how many bytes and which ranges are set/cleared * Structure to record how many bytes and which ranges are set/cleared
*/ */
...@@ -169,7 +180,7 @@ int try_release_extent_buffer(struct page *page); ...@@ -169,7 +180,7 @@ int try_release_extent_buffer(struct page *page);
int __must_check submit_one_bio(struct bio *bio, int mirror_num, int __must_check submit_one_bio(struct bio *bio, int mirror_num,
unsigned long bio_flags); unsigned long bio_flags);
int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
struct bio **bio, unsigned long *bio_flags, struct btrfs_bio_ctrl *bio_ctrl,
unsigned int read_flags, u64 *prev_em_start); unsigned int read_flags, u64 *prev_em_start);
int extent_write_full_page(struct page *page, struct writeback_control *wbc); int extent_write_full_page(struct page *page, struct writeback_control *wbc);
int extent_write_locked_range(struct inode *inode, u64 start, u64 end, int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
......
...@@ -2229,33 +2229,6 @@ static blk_status_t btrfs_submit_bio_start(struct inode *inode, struct bio *bio, ...@@ -2229,33 +2229,6 @@ static blk_status_t btrfs_submit_bio_start(struct inode *inode, struct bio *bio,
return btrfs_csum_one_bio(BTRFS_I(inode), bio, 0, 0); return btrfs_csum_one_bio(BTRFS_I(inode), bio, 0, 0);
} }
bool btrfs_bio_fits_in_ordered_extent(struct page *page, struct bio *bio,
unsigned int size)
{
struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
struct btrfs_fs_info *fs_info = inode->root->fs_info;
struct btrfs_ordered_extent *ordered;
u64 len = bio->bi_iter.bi_size + size;
bool ret = true;
ASSERT(btrfs_is_zoned(fs_info));
ASSERT(fs_info->max_zone_append_size > 0);
ASSERT(bio_op(bio) == REQ_OP_ZONE_APPEND);
/* Ordered extent not yet created, so we're good */
ordered = btrfs_lookup_ordered_extent(inode, page_offset(page));
if (!ordered)
return ret;
if ((bio->bi_iter.bi_sector << SECTOR_SHIFT) + len >
ordered->disk_bytenr + ordered->disk_num_bytes)
ret = false;
btrfs_put_ordered_extent(ordered);
return ret;
}
static blk_status_t extract_ordered_extent(struct btrfs_inode *inode, static blk_status_t extract_ordered_extent(struct btrfs_inode *inode,
struct bio *bio, loff_t file_offset) struct bio *bio, loff_t file_offset)
{ {
...@@ -8297,15 +8270,14 @@ int btrfs_readpage(struct file *file, struct page *page) ...@@ -8297,15 +8270,14 @@ int btrfs_readpage(struct file *file, struct page *page)
struct btrfs_inode *inode = BTRFS_I(page->mapping->host); struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
u64 start = page_offset(page); u64 start = page_offset(page);
u64 end = start + PAGE_SIZE - 1; u64 end = start + PAGE_SIZE - 1;
unsigned long bio_flags = 0; struct btrfs_bio_ctrl bio_ctrl = { 0 };
struct bio *bio = NULL;
int ret; int ret;
btrfs_lock_and_flush_ordered_range(inode, start, end, NULL); btrfs_lock_and_flush_ordered_range(inode, start, end, NULL);
ret = btrfs_do_readpage(page, NULL, &bio, &bio_flags, 0, NULL); ret = btrfs_do_readpage(page, NULL, &bio_ctrl, 0, NULL);
if (bio) if (bio_ctrl.bio)
ret = submit_one_bio(bio, 0, bio_flags); ret = submit_one_bio(bio_ctrl.bio, 0, bio_ctrl.bio_flags);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment