From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Christoph Hellwig <hch@lst.de>, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/8] btrfs: track the next file offset in struct btrfs_bio_ctrl
Date: Thu, 10 Apr 2025 07:45:31 +0930 [thread overview]
Message-ID: <abfa0402-44e4-43c7-beda-55a7439bc5f7@gmx.com> (raw)
In-Reply-To: <20250409111055.3640328-3-hch@lst.de>
在 2025/4/9 20:40, Christoph Hellwig 写道:
> Stop poking into bio implementation details and recalculating the pos
> from the folio over and over and instead just track then end of the
> current bio in logical file offsets in the btrfs_bio_ctrl.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu> ---
> fs/btrfs/extent_io.c | 33 +++++++++++++--------------------
> 1 file changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 193736b07a0b..36db23f7a6bb 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -96,6 +96,7 @@ void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info)
> */
> struct btrfs_bio_ctrl {
> struct btrfs_bio *bbio;
> + loff_t next_file_offset; /* last byte contained in bbio + 1 */
> enum btrfs_compression_type compress_type;
> u32 len_to_oe_boundary;
> blk_opf_t opf;
> @@ -643,13 +644,10 @@ static int alloc_eb_folio_array(struct extent_buffer *eb, bool nofail)
> }
>
> static bool btrfs_bio_is_contig(struct btrfs_bio_ctrl *bio_ctrl,
> - struct folio *folio, u64 disk_bytenr,
> - unsigned int pg_offset)
> + u64 disk_bytenr, loff_t file_offset)
> {
> struct bio *bio = &bio_ctrl->bbio->bio;
> - struct bio_vec *bvec = bio_last_bvec_all(bio);
> const sector_t sector = disk_bytenr >> SECTOR_SHIFT;
> - struct folio *bv_folio = page_folio(bvec->bv_page);
>
> if (bio_ctrl->compress_type != BTRFS_COMPRESS_NONE) {
> /*
> @@ -660,19 +658,11 @@ static bool btrfs_bio_is_contig(struct btrfs_bio_ctrl *bio_ctrl,
> }
>
> /*
> - * The contig check requires the following conditions to be met:
> - *
> - * 1) The folios are belonging to the same inode
> - * This is implied by the call chain.
> - *
> - * 2) The range has adjacent logical bytenr
> - *
> - * 3) The range has adjacent file offset
> - * This is required for the usage of btrfs_bio->file_offset.
> + * To merge into a bio both the disk sector and the logical offset in
> + * the file need to be contiguous.
> */
> - return bio_end_sector(bio) == sector &&
> - folio_pos(bv_folio) + bvec->bv_offset + bvec->bv_len ==
> - folio_pos(folio) + pg_offset;
> + return bio_ctrl->next_file_offset == file_offset &&
> + bio_end_sector(bio) == sector;
> }
>
> static void alloc_new_bio(struct btrfs_inode *inode,
> @@ -690,6 +680,7 @@ static void alloc_new_bio(struct btrfs_inode *inode,
> bbio->file_offset = file_offset;
> bio_ctrl->bbio = bbio;
> bio_ctrl->len_to_oe_boundary = U32_MAX;
> + bio_ctrl->next_file_offset = file_offset;
>
> /* Limit data write bios to the ordered boundary. */
> if (bio_ctrl->wbc) {
> @@ -731,12 +722,13 @@ static void submit_extent_folio(struct btrfs_bio_ctrl *bio_ctrl,
> size_t size, unsigned long pg_offset)
> {
> struct btrfs_inode *inode = folio_to_inode(folio);
> + loff_t file_offset = folio_pos(folio) + pg_offset;
>
> ASSERT(pg_offset + size <= folio_size(folio));
> ASSERT(bio_ctrl->end_io_func);
>
> if (bio_ctrl->bbio &&
> - !btrfs_bio_is_contig(bio_ctrl, folio, disk_bytenr, pg_offset))
> + !btrfs_bio_is_contig(bio_ctrl, disk_bytenr, file_offset))
> submit_one_bio(bio_ctrl);
>
> do {
> @@ -745,7 +737,7 @@ static void submit_extent_folio(struct btrfs_bio_ctrl *bio_ctrl,
> /* Allocate new bio if needed */
> if (!bio_ctrl->bbio) {
> alloc_new_bio(inode, bio_ctrl, disk_bytenr,
> - folio_pos(folio) + pg_offset);
> + file_offset);
> }
>
> /* Cap to the current ordered extent boundary if there is one. */
> @@ -760,14 +752,15 @@ static void submit_extent_folio(struct btrfs_bio_ctrl *bio_ctrl,
> submit_one_bio(bio_ctrl);
> continue;
> }
> + bio_ctrl->next_file_offset += len;
>
> if (bio_ctrl->wbc)
> - wbc_account_cgroup_owner(bio_ctrl->wbc, folio,
> - len);
> + wbc_account_cgroup_owner(bio_ctrl->wbc, folio, len);
>
> size -= len;
> pg_offset += len;
> disk_bytenr += len;
> + file_offset += len;
>
> /*
> * len_to_oe_boundary defaults to U32_MAX, which isn't folio or
next prev parent reply other threads:[~2025-04-09 22:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 11:10 RFC: (almost) stop poking into bvec internals in btrfs Christoph Hellwig
2025-04-09 11:10 ` [PATCH 1/8] btrfs: remove the alignment checks in end_bbio_data_read Christoph Hellwig
2025-04-09 22:13 ` Qu Wenruo
2025-04-10 5:30 ` Christoph Hellwig
2025-04-10 5:39 ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 2/8] btrfs: track the next file offset in struct btrfs_bio_ctrl Christoph Hellwig
2025-04-09 22:15 ` Qu Wenruo [this message]
2025-04-09 11:10 ` [PATCH 3/8] btrfs: pass a physical address to btrfs_repair_io_failure Christoph Hellwig
2025-04-09 22:19 ` Qu Wenruo
2025-04-10 5:31 ` Christoph Hellwig
2025-04-10 6:06 ` Johannes Thumshirn
2025-04-10 6:17 ` hch
2025-04-09 11:10 ` [PATCH 4/8] btrfs: move kmapping out of btrfs_check_sector_csum Christoph Hellwig
2025-04-10 6:16 ` Johannes Thumshirn
2025-04-16 4:51 ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 5/8] btrfs: simplify bvec iteration in index_one_bio Christoph Hellwig
2025-04-18 2:09 ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 6/8] btrfs: store a kernel virtual address in struct sector_ptr Christoph Hellwig
2025-04-09 22:34 ` Qu Wenruo
2025-04-10 5:34 ` Christoph Hellwig
2025-04-14 3:04 ` Qu Wenruo
2025-04-17 23:41 ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 7/8] btrfs: refactor getting the address of a stripe sector Christoph Hellwig
2025-04-09 22:38 ` Qu Wenruo
2025-04-19 1:01 ` Qu Wenruo
2025-04-09 11:10 ` [PATCH 8/8] btrfs: use bvec_kmap_local in btrfs_decompress_buf2page Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=abfa0402-44e4-43c7-beda-55a7439bc5f7@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=hch@lst.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox