diff mbox series

[1/7] btrfs: use file_offset to limit bios size in calc_bio_boundaries

Message ID 20221212073724.12637-2-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/7] btrfs: use file_offset to limit bios size in calc_bio_boundaries | expand

Commit Message

Christoph Hellwig Dec. 12, 2022, 7:37 a.m. UTC
btrfs_ordered_extent->disk_bytenr can be rewritten by the zoned I/O
completion handler, and thus in general is not a good idea to limit I/O
size.  But the maximum bio size calculation can easily be done using the
file_offset fields in the btrfs_ordered_extent and btrfs_bio structures,
so switch to that instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/extent_io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Josef Bacik Dec. 12, 2022, 6:54 p.m. UTC | #1
On Mon, Dec 12, 2022 at 08:37:18AM +0100, Christoph Hellwig wrote:
> btrfs_ordered_extent->disk_bytenr can be rewritten by the zoned I/O
> completion handler, and thus in general is not a good idea to limit I/O
> size.  But the maximum bio size calculation can easily be done using the
> file_offset fields in the btrfs_ordered_extent and btrfs_bio structures,
> so switch to that instead.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Can you add a comment to the code as well?  I'm going to see this in a year or two
and spend a little bit scratching my head as to why we're using the file_offset
here.  With that done you can add

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
Christoph Hellwig Dec. 13, 2022, 2:08 p.m. UTC | #2
On Mon, Dec 12, 2022 at 01:54:14PM -0500, Josef Bacik wrote:
> Can you add a comment to the code as well?

Sure.

> I'm going to see this in a year or two
> and spend a little bit scratching my head as to why we're using the file_offset
> here.  With that done you can add

Heh.  I hope the code in this form is actually gone in a year, as the
concept of first creating the ordered extents and inserting them into a
tree, and then doing a lookup a few lines down in writepages is not
exactly very efficient and we should be able to just pass a pointer
down.  But that is several series down in my queue.
diff mbox series

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index a65a1629d3356d..1fcb55e549717f 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -944,8 +944,8 @@  static void calc_bio_boundaries(struct btrfs_bio_ctrl *bio_ctrl,
 		ordered = btrfs_lookup_ordered_extent(inode, file_offset);
 		if (ordered) {
 			bio_ctrl->len_to_oe_boundary = min_t(u32, U32_MAX,
-					ordered->disk_bytenr +
-					ordered->disk_num_bytes - logical);
+					ordered->file_offset +
+					ordered->disk_num_bytes - file_offset);
 			btrfs_put_ordered_extent(ordered);
 			return;
 		}