diff mbox series

[v7,19/39] btrfs: limit bio size under max_zone_append_size

Message ID 20200911123259.3782926-20-naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: zoned block device support | expand

Commit Message

Naohiro Aota Sept. 11, 2020, 12:32 p.m. UTC
Zone append write command cannot exceed the max zone append size. This
commit limits the page merging into a bio.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/extent_io.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Christoph Hellwig Sept. 11, 2020, 2:17 p.m. UTC | #1
On Fri, Sep 11, 2020 at 09:32:39PM +0900, Naohiro Aota wrote:
> +		if (fs_info->max_zone_append_size &&
> +		    bio_op(bio) == REQ_OP_WRITE &&
> +		    bio->bi_iter.bi_size + size > fs_info->max_zone_append_size)
> +			can_merge = false;
> +
>  		if (prev_bio_flags != bio_flags || !contig || !can_merge ||
>  		    force_bio_submit ||
>  		    bio_add_page(bio, page, page_size, pg_offset) < page_size) {

For zoned devices you need to use bio_add_hw_page instead of so that all
the hardware restrictions are applied.  bio_add_hw_page asso gets the
lenght limited passed as the last parameter so we won't need a separate
check.
Naohiro Aota Sept. 12, 2020, 4:14 a.m. UTC | #2
On Fri, Sep 11, 2020 at 03:17:19PM +0100, Christoph Hellwig wrote:
>On Fri, Sep 11, 2020 at 09:32:39PM +0900, Naohiro Aota wrote:
>> +		if (fs_info->max_zone_append_size &&
>> +		    bio_op(bio) == REQ_OP_WRITE &&
>> +		    bio->bi_iter.bi_size + size > fs_info->max_zone_append_size)
>> +			can_merge = false;
>> +
>>  		if (prev_bio_flags != bio_flags || !contig || !can_merge ||
>>  		    force_bio_submit ||
>>  		    bio_add_page(bio, page, page_size, pg_offset) < page_size) {
>
>For zoned devices you need to use bio_add_hw_page instead of so that all
>the hardware restrictions are applied.  bio_add_hw_page asso gets the
>lenght limited passed as the last parameter so we won't need a separate
>check.

I think we can't use it here. This bio is built for btrfs's logical space,
so the corresponding request queue is not available here.

Technically, we can use fs_devices->lateste_bdev. But considering this bio
can map to multiple bios to multiple devices, limiting the size of this bio
under the minimum queue_max_zone_appends_sectors() among devices is
feasible.
Christoph Hellwig Sept. 12, 2020, 5:30 a.m. UTC | #3
On Sat, Sep 12, 2020 at 01:14:24PM +0900, Naohiro Aota wrote:
> > For zoned devices you need to use bio_add_hw_page instead of so that all
> > the hardware restrictions are applied.  bio_add_hw_page asso gets the
> > lenght limited passed as the last parameter so we won't need a separate
> > check.
> 
> I think we can't use it here. This bio is built for btrfs's logical space,
> so the corresponding request queue is not available here.
> 
> Technically, we can use fs_devices->lateste_bdev. But considering this bio
> can map to multiple bios to multiple devices, limiting the size of this bio
> under the minimum queue_max_zone_appends_sectors() among devices is
> feasible.

Well, how do you then ensure the bio actually fits all the other
device limits as well?  e.g. max segment size, no SG gaps policy,
etc?
Naohiro Aota Sept. 17, 2020, 5:32 a.m. UTC | #4
On Sat, Sep 12, 2020 at 06:30:56AM +0100, Christoph Hellwig wrote:
>On Sat, Sep 12, 2020 at 01:14:24PM +0900, Naohiro Aota wrote:
>> > For zoned devices you need to use bio_add_hw_page instead of so that all
>> > the hardware restrictions are applied.  bio_add_hw_page asso gets the
>> > lenght limited passed as the last parameter so we won't need a separate
>> > check.
>>
>> I think we can't use it here. This bio is built for btrfs's logical space,
>> so the corresponding request queue is not available here.
>>
>> Technically, we can use fs_devices->lateste_bdev. But considering this bio
>> can map to multiple bios to multiple devices, limiting the size of this bio
>> under the minimum queue_max_zone_appends_sectors() among devices is
>> feasible.
>
>Well, how do you then ensure the bio actually fits all the other
>device limits as well?  e.g. max segment size, no SG gaps policy,
>etc?

Yeah, that's problematic, and I realized we could not deal with all the
restrictions in this manner. I'm reimplementing this patch basing on
bio_add_hw_page().

Regards,
diff mbox series

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 53bac37bc4ac..63cdf67e6885 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3041,6 +3041,7 @@  static int submit_extent_page(unsigned int opf,
 	size_t page_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;
+	struct btrfs_fs_info *fs_info = tree->fs_info;
 
 	ASSERT(bio_ret);
 
@@ -3058,6 +3059,11 @@  static int submit_extent_page(unsigned int opf,
 		if (btrfs_bio_fits_in_stripe(page, page_size, bio, bio_flags))
 			can_merge = false;
 
+		if (fs_info->max_zone_append_size &&
+		    bio_op(bio) == REQ_OP_WRITE &&
+		    bio->bi_iter.bi_size + size > fs_info->max_zone_append_size)
+			can_merge = false;
+
 		if (prev_bio_flags != bio_flags || !contig || !can_merge ||
 		    force_bio_submit ||
 		    bio_add_page(bio, page, page_size, pg_offset) < page_size) {